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
Creates CSS content.
-
#render(renderer, depth) ⇒ void
rubocop:disable Metrics/MethodLength Renders CSS content.
Constructor Details
#initialize(content) ⇒ void
Creates CSS content.
198 199 200 201 202 203 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 198 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) ⇒ void
This method returns an undefined value.
rubocop:disable Metrics/MethodLength Renders CSS content.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 210 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 |