Files
Notare/examples/full_demo.rb
mathias234 243b06d8f8
All checks were successful
CI Pipeline / build (push) Successful in 11s
Not a script
2025-12-02 13:46:05 +01:00

182 lines
5.6 KiB
Ruby

# frozen_string_literal: true
# Full demo of all Notare features
# Run with: bundle exec ruby examples/full_demo.rb
require_relative "../lib/notare"
OUTPUT_FILE = File.expand_path("../example.docx", __dir__)
FIXTURES_DIR = File.expand_path("../test/fixtures", __dir__)
Notare::Document.create(OUTPUT_FILE) do |doc|
# ============================================================================
# Custom Styles
# ============================================================================
doc.define_style :highlight, bold: true, color: "FF6600"
doc.define_style :success, color: "228B22", italic: true
doc.define_style :centered_large, align: :center, size: 16, bold: true
# ============================================================================
# Title and Introduction
# ============================================================================
doc.h1 "Notare Feature Demo"
doc.p "A comprehensive example of all supported features", style: :subtitle
# ============================================================================
# 1. Text Formatting
# ============================================================================
doc.h2 "1. Text Formatting"
doc.p do
doc.text "This paragraph demonstrates "
doc.b { doc.text "bold" }
doc.text ", "
doc.i { doc.text "italic" }
doc.text ", "
doc.u { doc.text "underlined" }
doc.text ", and "
doc.b do
doc.i do
doc.u { doc.text "combined" }
end
end
doc.text " formatting."
end
# ============================================================================
# 2. Headings
# ============================================================================
doc.h2 "2. Headings"
doc.h3 "This is Heading 3"
doc.h4 "This is Heading 4"
doc.h5 "This is Heading 5"
doc.h6 "This is Heading 6"
# ============================================================================
# 3. Built-in Styles
# ============================================================================
doc.h2 "3. Built-in Styles"
doc.p "This is styled as a title", style: :title
doc.p "This is styled as a subtitle", style: :subtitle
doc.p "This is styled as a quote - perfect for citations and quotations.", style: :quote
doc.p "def hello; puts \"world\"; end", style: :code
# ============================================================================
# 4. Custom Styles
# ============================================================================
doc.h2 "4. Custom Styles"
doc.p "This text uses our custom highlight style!", style: :highlight
doc.p do
doc.text "Mixed styles: "
doc.text "success message", style: :success
doc.text " and "
doc.text "highlighted text", style: :highlight
doc.text " in one paragraph."
end
doc.p "Centered and large text", style: :centered_large
# ============================================================================
# 5. Lists
# ============================================================================
doc.h2 "5. Lists"
doc.h3 "Bullet List"
doc.ul do
doc.li "First item"
doc.li "Second item"
doc.li do
doc.text "Item with "
doc.b { doc.text "bold" }
doc.text " text"
end
end
doc.h3 "Numbered List"
doc.ol do
doc.li "Step one"
doc.li "Step two"
doc.li "Step three"
end
# ============================================================================
# 6. Tables
# ============================================================================
doc.h2 "6. Tables"
doc.table do
doc.tr do
doc.td { doc.b { doc.text "Feature" } }
doc.td { doc.b { doc.text "Status" } }
doc.td { doc.b { doc.text "Notes" } }
end
doc.tr do
doc.td "Paragraphs"
doc.td { doc.text "Complete", style: :success }
doc.td "Basic text support"
end
doc.tr do
doc.td "Formatting"
doc.td { doc.text "Complete", style: :success }
doc.td "Bold, italic, underline"
end
doc.tr do
doc.td "Headings"
doc.td { doc.text "Complete", style: :success }
doc.td "h1 through h6"
end
doc.tr do
doc.td "Styles"
doc.td { doc.text "Complete", style: :success }
doc.td "Built-in and custom"
end
doc.tr do
doc.td "Images"
doc.td { doc.text "Complete", style: :success }
doc.td "PNG and JPEG"
end
end
# ============================================================================
# 7. Images
# ============================================================================
doc.h2 "7. Images"
doc.p "Image with explicit dimensions:"
doc.p do
doc.image File.join(FIXTURES_DIR, "test.png"), width: "2in", height: "2in"
end
doc.p "Inline image with text:"
doc.p do
doc.text "Before "
doc.image File.join(FIXTURES_DIR, "test.jpg"), width: "0.75in", height: "0.75in"
doc.text " After"
end
doc.p "Image in a table:"
doc.table do
doc.tr do
doc.td "Description"
doc.td do
doc.image File.join(FIXTURES_DIR, "test.png"), width: "1in", height: "1in"
end
end
end
# ============================================================================
# 8. Combined Features
# ============================================================================
doc.h2 "8. Combined Features"
doc.p do
doc.text "This final paragraph combines "
doc.b { doc.text "multiple" }
doc.text " "
doc.i { doc.text "formatting" }
doc.text " options with "
doc.text "custom styles", style: :highlight
doc.text " to demonstrate the full power of Notare."
end
doc.p "End of demo document.", style: :centered_large
end
puts "Created #{OUTPUT_FILE}"