Module: UzuUzu::Helper::Renderer

Defined in:
lib/uzuuzu-core/helper/renderer.rb

Instance Method Summary collapse

Instance Method Details

#render(view = nil, options = {}, locals = {}, &block) ⇒ Object



28
29
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
# File 'lib/uzuuzu-core/helper/renderer.rb', line 28

def render(view=nil, options={}, locals={}, &block)
  view = helper.action if view.blank?
  view_path = nil
  catch(:view_finded) do
    route = helper.route
    if /index$/ =~ route 
      route = route.split('/')[0...-1].join('/')
    end
    if view[0] == '/'
      _view_path = "#{application.view_root}#{view}"
    else
      _view_path = "#{application.view_root}#{route}/#{view}"
    end
    ::Tilt.mappings.each_key do |key|
      _path = "#{_view_path}.#{key}"
      if ::File.file?(_path)
        view_path = _path
        throw :view_finded
      end
    end
    return nil
  end
  if view_path.blank?
    return nil
  end
  render_file(view_path, options={}, locals={}, &block)
end

#render_engine(view_string, engine = ::UzuUzu.engine, options = {}, locals = {}, &block) ⇒ Object



71
72
73
74
75
# File 'lib/uzuuzu-core/helper/renderer.rb', line 71

def render_engine(view_string, engine=::UzuUzu.engine, options={}, locals={}, &block)
  locals ||= {}
  locals = locals.merge(instance_variable_map(controller))
  UzuUzu.render_engine(helper, view_string, engine, options, locals, &block)
end

#render_file(view_path, options = {}, locals = {}, &block) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/uzuuzu-core/helper/renderer.rb', line 59

def render_file(view_path, options={}, locals={}, &block)
  if ::File.file?(view_path)
    view_string = ::File.respond_to?(:binread) ? ::File.binread(view_path) : ::File.read(view_path)
    render_engine(view_string, ::File.extname(view_path), options, locals, &block)
  else
    raise ::ArgmentError.new("file not found : #{view_path}")
  end
end

#render_full(controller_clazz, action, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/uzuuzu-core/helper/renderer.rb', line 10

def render_full(controller_clazz, action, options={})
    _request = request
    _response = response
    _controller = controller
    _helper = helper
    _action = action
    _query = query
    _route = route
    browser = ::Rack::MockRequest.new(::UzuUzu.current)
    _render_response = browser.get(helper.rf(controller_clazz, action, options))
    _render =  _render_response.body.to_s
    ::UzuUzu.current.di_thread(_request, _response, _controller, _helper, _action, _query, _route)
    _render
end