Class: Uniword::GenerateCLI

Inherits:
Thor
  • Object
show all
Includes:
CLIHelpers
Defined in:
lib/uniword/cli/generate_cli.rb

Overview

Generate subcommand for Uniword CLI.

Generates DOCX documents from structured text files (YAML or Markdown), using styles extracted from a source DOCX template.

Instance Method Summary collapse

Methods included from CLIHelpers

included

Instance Method Details

#generate(input_path, output_path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/uniword/cli/generate_cli.rb', line 35

def generate(input_path, output_path)
  validate_style_source
  validate_input(input_path)

  say("Parsing #{input_path}...", :green) if options[:verbose]

  content = Generation::StructuredTextParser.parse(input_path)

  say("  Parsed #{content.count} elements", :cyan) if options[:verbose]

  generator = Generation::DocumentGenerator.new(
    style_source: options["style-source"],
    style_mapping: options["style-mapping"],
  )

  generator.generate(content, output_path)

  say("Generated: #{output_path}", :green)
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e, verbose: options[:verbose])
end