Class: RSLT::ElementWrapper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stylesheet, element, builder) ⇒ ElementWrapper

Returns a new instance of ElementWrapper.



6
7
8
9
10
# File 'lib/rslt/element_wrapper.rb', line 6

def initialize(stylesheet, element, builder)
  @stylesheet = stylesheet
  @element = element
  @builder = builder
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rslt/element_wrapper.rb', line 19

def method_missing(sym, *args)
  begin
    @element.send(sym, *args)
  rescue Exception => e
    raise e.exception("Error delegating method '#{sym}' to #{@element.class.name}: #{e.message}\n\n#{e.backtrace.join("\n")}")
  end
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



4
5
6
# File 'lib/rslt/element_wrapper.rb', line 4

def builder
  @builder
end

#elementObject (readonly)

Returns the value of attribute element.



4
5
6
# File 'lib/rslt/element_wrapper.rb', line 4

def element
  @element
end

#stylesheetObject (readonly)

Returns the value of attribute stylesheet.



4
5
6
# File 'lib/rslt/element_wrapper.rb', line 4

def stylesheet
  @stylesheet
end

Instance Method Details

#add(*content) ⇒ Object



27
28
29
# File 'lib/rslt/element_wrapper.rb', line 27

def add(*content)
  @builder << content.join('')
end

#child_content(selector = nil) ⇒ Object



12
13
14
15
16
17
# File 'lib/rslt/element_wrapper.rb', line 12

def child_content(selector=nil)
  elements = selector ? @element.css(selector) : @element.children
  elements.each do |child|
    stylesheet.generate_element(child)
  end
end

#error(string) ⇒ Object



31
32
33
# File 'lib/rslt/element_wrapper.rb', line 31

def error(string)
  stylesheet.errors << string
end