Class: Uniword::Styles::StyleLibrary

Inherits:
Object
  • Object
show all
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).

Examples:

Load ISO standard styles

library = StyleLibrary.load('iso_standard')
title_style = library.paragraph_style(:title)

Load with custom path

library = StyleLibrary.load_from_file('/custom/styles.yml')

Constant Summary collapse

STYLES_DIR =

Default styles directory

File.expand_path("../../../../config/styles", __dir__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StyleLibrary

Initialize style library from configuration

Parameters:

  • config (Hash)

    Style library 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

#descriptionObject (readonly)

Returns the value of attribute description.



23
24
25
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 23

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 23

def name
  @name
end

#versionObject (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

Examples:

Load ISO standard styles

library = StyleLibrary.load('iso_standard')

Parameters:

  • library_name (String, Symbol)

    Name of the style library

Returns:

Raises:



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

Examples:

Load from custom path

library = StyleLibrary.load_from_file('/custom/styles.yml')

Parameters:

  • file_path (String)

    Full path to style library YAML file

Returns:

Raises:



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

Parameters:

  • style_name (String, Symbol)

    Style name

Returns:

Raises:

  • (ArgumentError)

    if style not found



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_namesArray<Symbol>

Get all character style names

Returns:

  • (Array<Symbol>)

    List of 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

Parameters:

  • style_name (String, Symbol)

    Style name

Returns:

Raises:

  • (ArgumentError)

    if style not found



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_namesArray<Symbol>

Get all list style names

Returns:

  • (Array<Symbol>)

    List of 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

Parameters:

  • style_name (String, Symbol)

    Style name

Returns:

Raises:

  • (ArgumentError)

    if style not found



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_namesArray<Symbol>

Get all paragraph style names

Returns:

  • (Array<Symbol>)

    List of 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

Parameters:

  • style_name (String, Symbol)

    Style name

Returns:

Raises:

  • (ArgumentError)

    if style not found



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_namesArray<Symbol>

Get all semantic style names

Returns:

  • (Array<Symbol>)

    List of 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

Parameters:

  • style_name (String, Symbol)

    Style name

Returns:

Raises:

  • (ArgumentError)

    if style not found



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_namesArray<Symbol>

Get all table style names

Returns:

  • (Array<Symbol>)

    List of table style names



143
144
145
# File 'lib/uniword/wordprocessingml/styles/style_library.rb', line 143

def table_style_names
  @table_styles.keys
end