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)


20
21
22
# File 'lib/element.rb', line 20

def empty?
    @node.empty?
end

#langObject



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

def lang
    lang_attribute = @node.attribute(ATTRIBUTES[:lang]).first
    return LANG_DEFALTS[@type] unless lang_attribute
    lang_attribute.value
end

#renderObject



28
29
30
31
32
# File 'lib/element.rb', line 28

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

#textObject



24
25
26
# File 'lib/element.rb', line 24

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