Class: Phlex::SVG
- Includes:
- StandardElements
- Defined in:
- lib/phlex/svg.rb
Defined Under Namespace
Modules: StandardElements
Constant Summary
Constants included from Phlex::SGML::Elements
Phlex::SGML::Elements::COMMA_SEPARATED_TOKENS
Constants inherited from SGML
Phlex::SGML::ERBCompiler, Phlex::SGML::REF_ATTRIBUTES, Phlex::SGML::UNSAFE_ATTRIBUTES
Instance Method Summary collapse
- #cdata(content = nil, &block) ⇒ Object
-
#content_type ⇒ Object
Returns the string “image/svg+xml”.
-
#filename ⇒ Object
Override to provide a filename for the SVG file.
- #tag(name, **attributes) ⇒ Object
Methods included from Phlex::SGML::Elements
#__register_void_element__, #__registered_elements__, #register_element
Methods inherited from SGML
#cache, #call, call, #capture, #comment, #context, erb, #flush, #fragment, #internal_call, #json_escape, #low_level_cache, new, #plain, #raw, #render, #rendering?, #safe, #to_proc, #view_template, #whitespace
Instance Method Details
#cdata(content = nil, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/phlex/svg.rb', line 16 def cdata(content = nil, &block) state = @_state return unless state.should_render? if !block && String === content state.buffer << "<![CDATA[" << content.gsub("]]>", "]]>]]<![CDATA[") << "]]>" elsif block && nil == content state.buffer << "<![CDATA[" << capture(&block).gsub("]]>", "]]>]]<![CDATA[") << "]]>" else raise Phlex::ArgumentError.new("Expected a String or block.") end end |
#content_type ⇒ Object
Returns the string “image/svg+xml”
7 8 9 |
# File 'lib/phlex/svg.rb', line 7 def content_type "image/svg+xml" end |
#filename ⇒ Object
Override to provide a filename for the SVG file
12 13 14 |
# File 'lib/phlex/svg.rb', line 12 def filename nil end |
#tag(name, **attributes) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/phlex/svg.rb', line 30 def tag(name, **attributes, &) state = @_state block_given = block_given? buffer = state.buffer unless state.should_render? yield(self) if block_given return nil end unless Symbol === name raise Phlex::ArgumentError.new("Expected the tag name to be a Symbol.") end if (tag = StandardElements.__registered_elements__[name]) || (tag = name.name.tr("_", "-")).include?("-") if attributes.length > 0 # with attributes if block_given # with content block buffer << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes)) << ">" __yield_content__(&) buffer << "</#{tag}>" else # without content buffer << "<#{tag}" << (::Phlex::ATTRIBUTE_CACHE[attributes] ||= __attributes__(attributes)) << "></#{tag}>" end else # without attributes if block_given # with content block buffer << ("<#{tag}>") __yield_content__(&) buffer << "</#{tag}>" else # without content buffer << "<#{tag}></#{tag}>" end end else raise Phlex::ArgumentError.new("Invalid SVG tag: #{name}") end end |