Class: Uniword::ThemeCLI
- Inherits:
-
Thor
- Object
- Thor
- Uniword::ThemeCLI
- Includes:
- CLIHelpers
- Defined in:
- lib/uniword/cli/theme_cli.rb
Overview
Theme subcommands for Uniword CLI.
Manages bundled and imported themes – colors, fonts, and visual styling that control document appearance.
Instance Method Summary collapse
- #apply(input_path, output_path) ⇒ Object
- #auto(input_path, output_path) ⇒ Object
- #import ⇒ Object
- #list ⇒ Object
Methods included from CLIHelpers
Instance Method Details
#apply(input_path, output_path) ⇒ Object
110 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 148 149 |
# File 'lib/uniword/cli/theme_cli.rb', line 110 def apply(input_path, output_path) unless [:name] || [:file] say "Error: Must specify either --name for bundled theme or --file for .thmx 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 theme: #{doc.theme&.name || 'None'}" end apply_theme_to(doc) if [:verbose] say " Applied theme:", :cyan say " Theme name: #{doc.theme.name}" say " Colors: #{doc.theme.color_scheme.colors.keys.join(', ')}" say " Major font: #{doc.theme.major_font}" say " Minor font: #{doc.theme.minor_font}" say " Available variants: #{doc.theme.variants.keys.join(', ')}" if doc.theme.variants.any? end doc.save(output_path) say "Theme applied successfully to #{output_path}", :green rescue Uniword::Error => e handle_error(e) rescue StandardError => e handle_error(e, verbose: [:verbose]) end |
#auto(input_path, output_path) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/uniword/cli/theme_cli.rb', line 162 def auto(input_path, output_path) say "Loading document #{input_path}...", :green if [:verbose] doc = load_document(input_path) if [:verbose] say " Loaded document:", :cyan say " Current theme: #{doc.theme&.name || 'None'}" end result = doc.auto_transition_theme if result say "Transitioned MS '#{result.ms_name}' to Uniword '#{result.uniword_slug}'", :green if [:verbose] friendly = Themes::Theme.load(result.uniword_slug) say " Uniword theme:", :cyan say " Name: #{friendly.name}" say " Major font: #{friendly.font_scheme.major_font}" say " Minor font: #{friendly.font_scheme.minor_font}" end else say "No matching Uniword theme found for this document's theme", :yellow end doc.save(output_path) say "Saved to #{output_path}", :green rescue Uniword::Error => e handle_error(e) rescue StandardError => e handle_error(e, verbose: [:verbose]) end |
#import ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/uniword/cli/theme_cli.rb', line 65 def import if [:verbose] say "Importing themes from #{[:source]}...", :green end importer = Themes::ThemeImporter.new count = importer.import_all([:source], [:output]) say "Successfully imported #{count} themes to #{[:output]}/", :green if [:verbose] themes = Dir.glob(File.join([:output], "*.yml")).map do |f| File.basename(f, ".yml") end.sort say "\nAvailable themes:", :cyan themes.each { |name| say " - #{name}" } end rescue StandardError => e say "Error importing themes: #{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 |
# File 'lib/uniword/cli/theme_cli.rb', line 24 def list themes = Themes::Theme.available_themes if themes.empty? say "No bundled themes found.", :yellow say "Run 'uniword theme import' to import Office themes.", :yellow return end say "Available themes (#{themes.count}):", :green themes.each do |theme_name| if [:verbose] begin friendly = Themes::Theme.load(theme_name) say " #{theme_name}:", :cyan say " Name: #{friendly.name}" say " Colors: #{friendly.color_scheme&.colors&.count || 0}" say " Variants: #{friendly.variants&.count || 0}" rescue StandardError => e say " #{theme_name}: Error loading - #{e.}", :red end else say " - #{theme_name}" end end end |