Class: Sablon::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sablon/configuration/configuration.rb,
lib/sablon/configuration/html_tag.rb

Overview

Handles storing configuration data for the sablon module

Defined Under Namespace

Classes: HTMLTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
# File 'lib/sablon/configuration/configuration.rb', line 11

def initialize
  initialize_html_tags
  initialize_css_style_conversion
end

Instance Attribute Details

#defined_style_conversionsObject

Returns the value of attribute defined_style_conversions.



9
10
11
# File 'lib/sablon/configuration/configuration.rb', line 9

def defined_style_conversions
  @defined_style_conversions
end

#permitted_html_tagsObject

Returns the value of attribute permitted_html_tags.



9
10
11
# File 'lib/sablon/configuration/configuration.rb', line 9

def permitted_html_tags
  @permitted_html_tags
end

Instance Method Details

#register_html_tag(tag_name, type = :inline, **options) ⇒ Object

Adds a new tag to the permitted tags hash or replaces an existing one



17
18
19
20
# File 'lib/sablon/configuration/configuration.rb', line 17

def register_html_tag(tag_name, type = :inline, **options)
  tag = HTMLTag.new(tag_name, type, **options)
  @permitted_html_tags[tag.name] = tag
end

#register_style_converter(ast_node, prop_name, converter) ⇒ Object

Adds a new style property converter for the specified ast class and CSS property name. The ast_class variable should be the class name in lowercased snakecase as a symbol, i.e. MyClass -> :my_class. The converter passed in must be a proc that accepts a single argument (the value) and returns two values: the WordML property name and its value. The converted property value can be a string, hash or array.



34
35
36
37
38
39
40
41
# File 'lib/sablon/configuration/configuration.rb', line 34

def register_style_converter(ast_node, prop_name, converter)
  # create a new ast node hash if needed
  unless @defined_style_conversions[ast_node]
    @defined_style_conversions[ast_node] = {}
  end
  # add the style converter to the node's hash
  @defined_style_conversions[ast_node][prop_name] = converter
end

#remove_html_tag(tag_name) ⇒ Object

Removes a tag from the permitted tgs hash, returning it



23
24
25
# File 'lib/sablon/configuration/configuration.rb', line 23

def remove_html_tag(tag_name)
  @permitted_html_tags.delete(tag_name)
end

#remove_style_converter(ast_node, prop_name) ⇒ Object

Deletes a CSS converter from the hash by specifying the AST class in lowercased snake case and the property name.



45
46
47
# File 'lib/sablon/configuration/configuration.rb', line 45

def remove_style_converter(ast_node, prop_name)
  @defined_style_conversions[ast_node].delete(prop_name)
end