Class: VueCK::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/element.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc, type) ⇒ Element

Returns a new instance of Element.



3
4
5
6
7
# File 'lib/element.rb', line 3

def initialize(doc, type)
    @node = doc.css(ELEMENTS[type])
    @type = type
    verify
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/element.rb', line 18

def empty?
    @node.empty?
end

#langObject



14
15
16
# File 'lib/element.rb', line 14

def lang
    @node.attribute(ATTRIBUTES[:lang]).first.value || LANG_DEFALTS[type]
end

#renderObject



26
27
28
29
30
# File 'lib/element.rb', line 26

def render
    return text if lang == LANG_DEFALTS[:script]
    raise InvalidTemplateEngine unless Tilt[lang]
    Tilt[lang].new { text }.render
end

#textObject



22
23
24
# File 'lib/element.rb', line 22

def text
    @node.first.children.text
end

#verifyObject



9
10
11
12
# File 'lib/element.rb', line 9

def verify
    return unless REQUIRED[@type]
    raise ComonentRenderError if @node.empty?
end