Class: Uniword::Styles::StyleLibrary
- Inherits:
-
Object
- Object
- Uniword::Styles::StyleLibrary
- Defined in:
- lib/uniword/wordprocessingml/styles/style_library.rb
Overview
Style Library - loads external style definitions
Responsibility: Load and manage style definitions from external YAML files Single Responsibility: Style configuration management only
External config: config/styles/*.yml
Follows “External Configuration” principle - all styles defined in YAML files, not hardcoded. Supports style inheritance and multiple style types (paragraph, character, list, table, semantic).
Constant Summary collapse
- STYLES_DIR =
Default styles directory
File.("../../../../config/styles", __dir__)
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.load(library_name) ⇒ StyleLibrary
Load style library from config/styles directory.
-
.load_from_file(file_path) ⇒ StyleLibrary
Load style library from specific file path.
Instance Method Summary collapse
-
#character_style(style_name) ⇒ CharacterStyleDefinition
Get character style definition.
-
#character_style_names ⇒ Array<Symbol>
Get all character style names.
-
#initialize(config) ⇒ StyleLibrary
constructor
Initialize style library from configuration.
-
#list_style(style_name) ⇒ ListStyleDefinition
Get list style definition.
-
#list_style_names ⇒ Array<Symbol>
Get all list style names.
-
#paragraph_style(style_name) ⇒ ParagraphStyleDefinition
Get paragraph style definition.
-
#paragraph_style_names ⇒ Array<Symbol>
Get all paragraph style names.
-
#semantic_style(style_name) ⇒ SemanticStyle
Get semantic style definition.
-
#semantic_style_names ⇒ Array<Symbol>
Get all semantic style names.
-
#table_style(style_name) ⇒ TableStyleDefinition
Get table style definition.
-
#table_style_names ⇒ Array<Symbol>
Get all table style names.
Constructor Details
#initialize(config) ⇒ StyleLibrary
Initialize style library from configuration
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 57 def initialize(config) @name = config[:name] @version = config[:version] @description = config[:description] @paragraph_styles = load_paragraph_styles(config[:paragraph_styles] || {}) @character_styles = load_character_styles(config[:character_styles] || {}) @list_styles = load_list_styles(config[:list_styles] || {}) @table_styles = load_table_styles(config[:table_styles] || {}) @semantic_styles = load_semantic_styles(config[:semantic_styles] || {}) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
23 24 25 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 23 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 23 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
23 24 25 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 23 def version @version end |
Class Method Details
.load(library_name) ⇒ StyleLibrary
Load style library from config/styles directory
36 37 38 39 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 36 def self.load(library_name) file_path = File.join(STYLES_DIR, "#{library_name}.yml") load_from_file(file_path) end |
.load_from_file(file_path) ⇒ StyleLibrary
Load style library from specific file path
49 50 51 52 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 49 def self.load_from_file(file_path) config = Configuration::ConfigurationLoader.load_file(file_path) new(config[:style_library]) end |
Instance Method Details
#character_style(style_name) ⇒ CharacterStyleDefinition
Get character style definition
84 85 86 87 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 84 def character_style(style_name) @character_styles[style_name.to_sym] || raise(ArgumentError, "Character style not found: #{style_name}") end |
#character_style_names ⇒ Array<Symbol>
Get all character style names
129 130 131 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 129 def character_style_names @character_styles.keys end |
#list_style(style_name) ⇒ ListStyleDefinition
Get list style definition
94 95 96 97 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 94 def list_style(style_name) @list_styles[style_name.to_sym] || raise(ArgumentError, "List style not found: #{style_name}") end |
#list_style_names ⇒ Array<Symbol>
Get all list style names
136 137 138 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 136 def list_style_names @list_styles.keys end |
#paragraph_style(style_name) ⇒ ParagraphStyleDefinition
Get paragraph style definition
74 75 76 77 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 74 def paragraph_style(style_name) @paragraph_styles[style_name.to_sym] || raise(ArgumentError, "Paragraph style not found: #{style_name}") end |
#paragraph_style_names ⇒ Array<Symbol>
Get all paragraph style names
122 123 124 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 122 def paragraph_style_names @paragraph_styles.keys end |
#semantic_style(style_name) ⇒ SemanticStyle
Get semantic style definition
114 115 116 117 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 114 def semantic_style(style_name) @semantic_styles[style_name.to_sym] || raise(ArgumentError, "Semantic style not found: #{style_name}") end |
#semantic_style_names ⇒ Array<Symbol>
Get all semantic style names
150 151 152 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 150 def semantic_style_names @semantic_styles.keys end |
#table_style(style_name) ⇒ TableStyleDefinition
Get table style definition
104 105 106 107 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 104 def table_style(style_name) @table_styles[style_name.to_sym] || raise(ArgumentError, "Table style not found: #{style_name}") end |
#table_style_names ⇒ Array<Symbol>
Get all table style names
143 144 145 |
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 143 def table_style_names @table_styles.keys end |