Class: Uniword::StyleSetCLI
- Inherits:
-
Thor
- Object
- Thor
- Uniword::StyleSetCLI
- Includes:
- CLIHelpers
- Defined in:
- lib/uniword/cli/styleset_cli.rb
Overview
StyleSet subcommands for Uniword CLI.
Manages bundled and imported StyleSets – collections of paragraph, character, and table styles that provide consistent formatting.
Instance Method Summary collapse
- #apply(input_path, output_path) ⇒ Object
- #extract(docx_path) ⇒ Object
- #import ⇒ Object
- #list ⇒ Object
Methods included from CLIHelpers
Instance Method Details
#apply(input_path, output_path) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/uniword/cli/styleset_cli.rb', line 111 def apply(input_path, output_path) unless [:name] || [:file] say "Error: Must specify either --name for bundled StyleSet or --file for .dotx file", :red exit 1 end if [:name] && [:file] say "Error: Cannot specify both --name and --file", :red exit 1 end say "Loading document #{input_path}...", :green if [:verbose] doc = load_document(input_path) if [:verbose] say " Loaded document:", :cyan say " Paragraphs: #{doc.paragraphs.count}" say " Current styles: #{doc.styles.count}" end apply_styleset_to(doc) if [:verbose] say " Applied StyleSet:", :cyan say " Total styles: #{doc.styles.count}" say " Strategy: #{[:strategy]}" end doc.save(output_path) say "StyleSet applied successfully to #{output_path}", :green rescue Uniword::Error => e handle_error(e) rescue StandardError => e handle_error(e, verbose: [:verbose]) end |
#extract(docx_path) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/uniword/cli/styleset_cli.rb', line 152 def extract(docx_path) output = [:output] || "data/stylesets/#{[:name]}.yml" Generation::StyleExtractor.extract_to_yaml(docx_path, output) say("StyleSet extracted: #{output}", :green) rescue Uniword::Error => e handle_error(e) rescue StandardError => e handle_error(e) end |
#import ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/uniword/cli/styleset_cli.rb', line 67 def import if [:verbose] say "Importing StyleSet from #{[:source]}...", :green end importer = Stylesets::StyleSetImporter.new count = importer.import_all([:source], [:output]) say "Successfully imported #{count} StyleSets to #{[:output]}/", :green if [:verbose] stylesets = Dir.glob(File.join([:output], "*.yml")).map do |f| File.basename(f, ".yml") end.sort say "\nAvailable StyleSets:", :cyan stylesets.each { |name| say " - #{name}" } end rescue StandardError => e say "Error importing StyleSet: #{e.}", :red exit 1 end |
#list ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/uniword/cli/styleset_cli.rb', line 24 def list stylesets = StyleSet.available_stylesets if stylesets.empty? say "No bundled StyleSets found.", :yellow say "Run 'uniword styleset import' to import .dotx StyleSets.", :yellow return end say "Available StyleSets (#{stylesets.count}):", :green stylesets.each do |styleset_name| if [:verbose] begin styleset = StyleSet.load(styleset_name) say " #{styleset_name}:", :cyan say " Name: #{styleset.name}" say " Styles: #{styleset.styles.count}" say " Paragraph styles: #{styleset.paragraph_styles.count}" say " Character styles: #{styleset.character_styles.count}" say " Table styles: #{styleset.table_styles.count}" rescue StandardError => e say " #{styleset_name}: Error loading - #{e.}", :red end else say " - #{styleset_name}" end end end |