Class: Sevgi::Graphics::Content::CSS
- Inherits:
-
Content
- Object
- Content
- Sevgi::Graphics::Content::CSS
- Defined in:
- lib/sevgi/graphics/auxiliary/content.rb
Overview
CSS content rendered inside a CDATA section.
Instance Method Summary collapse
-
#initialize(content) ⇒ void
constructor
Creates CSS content.
-
#render(renderer, depth) ⇒ void
rubocop:disable Metrics/MethodLength Renders CSS content.
Constructor Details
#initialize(content) ⇒ void
Creates CSS content.
84 85 86 87 88 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 84 def initialize(content) ArgumentError.("CSS content must be a hash: #{content}") unless content.is_a?(::Hash) super end |
Instance Method Details
#render(renderer, depth) ⇒ void
This method returns an undefined value.
rubocop:disable Metrics/MethodLength Renders CSS content.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 96 def render(renderer, depth) 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 |