Class: Sevgi::Graphics::Content::CSS

Inherits:
Sevgi::Graphics::Content show all
Defined in:
lib/sevgi/graphics/auxilary/content.rb

Instance Attribute Summary

Attributes inherited from Sevgi::Graphics::Content

#content

Instance Method Summary collapse

Methods inherited from Sevgi::Graphics::Content

cdata, css, encoded, text, #to_s, verbatim

Constructor Details

#initialize(content) ⇒ CSS

Returns a new instance of CSS.



37
38
39
40
41
# File 'lib/sevgi/graphics/auxilary/content.rb', line 37

def initialize(content)
  ArgumentError.("CSS content must be a hash: #{content}") unless content.is_a?(::Hash)

  super
end

Instance Method Details

#render(renderer, depth) ⇒ Object

rubocop:disable Metrics/MethodLength



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sevgi/graphics/auxilary/content.rb', line 43

def render(renderer, depth) # rubocop:disable Metrics/MethodLength
  depth += 1

  renderer.append(depth, "<![CDATA[")

  depth += 1
  content.each do |rule, styles|
    case styles
    when ::Hash
      renderer.append(depth, "#{rule} {")
      renderer.append(depth + 1, *styles.map { |key, value| "#{key}: #{value};" })
      renderer.append(depth, "}")
    when ::String, ::Symbol, ::Numeric
      renderer.append(depth, "#{rule}: #{styles};")
    else
      ArgumentError.("Malformed style: #{styles}")
    end
  end
  depth -= 1

  renderer.append(depth, "]]>")
end