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. Rules are captured recursively during construction; mutable selectors, property names, and values are stringified once, and embedded CDATA terminators are split safely.
Instance Method Summary collapse
-
#initialize(content) ⇒ void
constructor
private
Creates CSS content.
-
#render(renderer, depth) ⇒ Object
Renders CSS content.
Constructor Details
#initialize(content) ⇒ void
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.
Creates CSS content.
220 221 222 223 224 225 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 220 def initialize(content) ArgumentError.("CSS content must be a hash") unless content.is_a?(::Hash) validate_styles(content) super end |
Instance Method Details
#render(renderer, depth) ⇒ Object
Renders CSS content.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 231 def render(renderer, depth) depth += 1 renderer.append(depth, "<![CDATA[") depth += 1 payload.each do |rule, styles| case styles when ::Hash renderer.append(depth, safe("#{rule} {")) renderer.append(depth + 1, *styles.map { |key, value| safe("#{key}: #{value};") }) renderer.append(depth, "}") when ::String, ::Symbol, ::Numeric renderer.append(depth, safe("#{rule}: #{styles};")) else ArgumentError.("Malformed style: #{styles}") end end depth -= 1 renderer.append(depth, "]]>") end |