Class: Sakusei::StylePreview

Inherits:
Object
  • Object
show all
Defined in:
lib/sakusei/style_preview.rb

Overview

Generates a preview PDF showing all style elements

Constant Summary collapse

PREVIEW_CONTENT =
<<~MARKDOWN
  # Style Pack Preview

  This document demonstrates all the styling elements available in your style pack.

  ---

  ## Typography

  ### Headings

  # Heading 1
  ## Heading 2
  ### Heading 3
  #### Heading 4
  ##### Heading 5
  ###### Heading 6

  ### Paragraphs

  This is a paragraph with **bold text**, *italic text*, and `inline code`. Here's a [link to example.com](https://example.com).

  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  ---

  ## Lists

  ### Unordered List

  - First item
  - Second item
    - Nested item A
    - Nested item B
  - Third item

  ### Ordered List

  1. First step
  2. Second step
  3. Third step

  ### Task List

  - [x] Completed task
  - [ ] Incomplete task
  - [ ] Another incomplete task

  ---

  ## Code

  ### Inline Code

  Use `puts "Hello World"` to print to stdout.

  ### Code Block

  ```ruby
  def greet(name)
    puts "Hello, \#{name}!"
  end

  greet("Sakusei")
  ```

  ---

  ## Blockquotes

  > This is a blockquote.
  > It can span multiple lines.
  >
  > — Author Name

  ---

  ## Tables

  | Feature | Status | Priority |
  |---------|--------|----------|
  | Markdown | ✅ Supported | High |
  | ERB | ✅ Supported | High |
  | VueJS | 🚧 Planned | Low |

  ---

  ## Horizontal Rules

  Above is a horizontal rule.

  ---

  ## Special Elements

  This page demonstrates all the styling. Check the next page for more.

  <div class="page-break"></div>

  ## Second Page

  This content appears on a second page to demonstrate page breaks and consistent styling across pages.

  ### Sample Formula

  Inline math: $E = mc^2$

  ---

  *Generated by Sakusei Style Preview*
MARKDOWN

Instance Method Summary collapse

Constructor Details

#initialize(style_pack_name = nil, options = {}) ⇒ StylePreview

Returns a new instance of StylePreview.



118
119
120
121
122
# File 'lib/sakusei/style_preview.rb', line 118

def initialize(style_pack_name = nil, options = {})
  @style_pack_name = style_pack_name
  @options = options
  @output_path = options[:output] || 'style-preview.pdf'
end

Instance Method Details

#generateObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/sakusei/style_preview.rb', line 124

def generate
  # Create temp file with preview content
  temp_file = Tempfile.new(['sakusei_preview', '.md'])
  temp_file.write(PREVIEW_CONTENT)
  temp_file.flush
  temp_path = temp_file.path
  temp_file.close

  # Build using the style pack
  builder = Builder.new(temp_path, @options.merge(style: @style_pack_name))
  result = builder.build

  # Clean up temp file
  FileUtils.rm_f(temp_path)

  # Rename to desired output if different
  if result != File.expand_path(@output_path)
    FileUtils.mv(result, @output_path)
    @output_path
  else
    result
  end
end