Class: Uniword::Transformation::YamlCssGenerator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/transformation/yaml_css_generator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Generates Word HTML4 CSS from YAML style configuration hashes.

Converts OOXML style definitions (paragraph/character properties) to CSS rules suitable for MHTML output. Produces @font-face declarations, paragraph/heading/character style rules, @page definitions, and @list definitions.

Examples:

Generate CSS from YAML configs

generator = YamlCssGenerator.new(
  styles: YAML.load_file("styles.yml"),
  doc_defaults: YAML.load_file("doc_defaults.yml"),
  numbering: YAML.load_file("numbering.yml")
)
css = generator.generate

Constant Summary collapse

FONT_FACE_LIBRARY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Static @font-face declarations for common ISO fonts.

{
  "Arial" => <<~CSS,
  "Courier New" => <<~CSS,
  "Cambria Math" => <<~CSS,
  "Calibri" => <<~CSS,
  "Cambria" => <<~CSS,
  "Segoe UI" => <<~CSS,
  "Times New Roman" => <<~CSS,
  "SimSun" => <<~CSS,
  "SimHei" => <<~CSS,
  "MS Mincho" => <<~CSS,
  "Malgun Gothic" => <<~CSS,
  "Cambria serif" => <<~CSS,
}.freeze
DEFAULT_FONT_FAMILY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default font-family declaration based on primary font

'"Cambria", serif'
DEFAULT_FAREAST_FONT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'"SimSun", serif'

Instance Method Summary collapse

Constructor Details

#initialize(styles:, doc_defaults:, numbering: nil) ⇒ YamlCssGenerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of YamlCssGenerator.

Parameters:

  • styles (Hash)

    Parsed styles.yml content

  • doc_defaults (Hash)

    Parsed doc_defaults.yml content

  • numbering (Hash, nil) (defaults to: nil)

    Parsed numbering.yml content



153
154
155
156
157
158
159
160
161
# File 'lib/uniword/transformation/yaml_css_generator.rb', line 153

def initialize(styles:, doc_defaults:, numbering: nil)
  style_lib = styles["style_library"] || styles
  @para_styles = style_lib["paragraph_styles"] || {}
  @char_styles = style_lib["character_styles"] || {}
  @doc_defaults = doc_defaults["run_properties"] || {}
  @numbering = numbering
  @defaults = resolve_defaults
  @normal_spacing_after = (@para_styles.dig("Normal", "paragraph_properties", "spacing", "after") || "6.0")
end

Instance Method Details

#generateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generate complete CSS string for MHTML output.



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/uniword/transformation/yaml_css_generator.rb', line 164

def generate
  parts = []
  parts << "@charset \"UTF-8\";"
  parts << generate_font_faces
  parts << "/* Style Definitions */"
  parts << generate_all_styles
  parts << generate_page_section
  parts << generate_list_section
  parts << generate_mso_normal_table
  parts << generate_list_containers
  parts << generate_ol_ul
  parts.compact.join("\n")
end