Class: Ruhl::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/ruhl/rails.rb,
lib/ruhl/engine.rb,
lib/ruhl/sinatra.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html, options = {}) ⇒ Engine

Returns a new instance of Engine.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ruhl/engine.rb', line 6

def initialize(html, options = {})
  @local_object   = options[:local_object] || options[:object]
  @block_object   = options[:block_object]
  @layout         = options[:layout]
  @layout_source  = options[:layout_source]


  if @layout || @local_object || @block_object
    @document = Nokogiri::HTML.fragment(html)
  else
    @document = Nokogiri::HTML(html)
    @document.encoding = Ruhl.encoding
  end

end

Instance Attribute Details

#block_objectObject (readonly)

Returns the value of attribute block_object.



3
4
5
# File 'lib/ruhl/engine.rb', line 3

def block_object
  @block_object
end

#call_resultObject (readonly)

Returns the value of attribute call_result.



4
5
6
# File 'lib/ruhl/engine.rb', line 4

def call_result
  @call_result
end

#current_tagObject (readonly)

Returns the value of attribute current_tag.



4
5
6
# File 'lib/ruhl/engine.rb', line 4

def current_tag
  @current_tag
end

#documentObject (readonly)

Returns the value of attribute document.



4
5
6
# File 'lib/ruhl/engine.rb', line 4

def document
  @document
end

#layoutObject (readonly)

Returns the value of attribute layout.



3
4
5
# File 'lib/ruhl/engine.rb', line 3

def layout
  @layout
end

#layout_sourceObject (readonly)

Returns the value of attribute layout_source.



3
4
5
# File 'lib/ruhl/engine.rb', line 3

def layout_source
  @layout_source
end

#local_objectObject (readonly)

Returns the value of attribute local_object.



3
4
5
# File 'lib/ruhl/engine.rb', line 3

def local_object
  @local_object
end

#original_tagObject (readonly)

Returns the value of attribute original_tag.



4
5
6
# File 'lib/ruhl/engine.rb', line 4

def original_tag
  @original_tag
end

#ruhl_actionsObject (readonly)

Returns the value of attribute ruhl_actions.



4
5
6
# File 'lib/ruhl/engine.rb', line 4

def ruhl_actions
  @ruhl_actions
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/ruhl/engine.rb', line 4

def scope
  @scope
end

Instance Method Details

#_render_Object

The render method is used within a layout to inject the results of the template render.

Ruhl::Engine.new(html, :layout => path_to_layout).render(self)



38
39
40
# File 'lib/ruhl/engine.rb', line 38

def _render_
  document.to_s
end

#render(current_scope) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruhl/engine.rb', line 22

def render(current_scope)
  set_scope(current_scope)

  parse_doc(document)

  if @layout
    render_with_layout 
  else
    document.to_s.gsub(/\302\240/, ' ')
  end
end