Module: Mullet::Sinatra::Helpers
- Defined in:
- lib/mullet/sinatra.rb
Constant Summary collapse
- @@engine =
Mullet::Sinatra::Engine.new()
Instance Method Summary collapse
-
#mullet(view_name, options = {}, locals = {}) ⇒ String
Renders output for a view.
Instance Method Details
#mullet(view_name, options = {}, locals = {}) ⇒ String
Renders output for a view
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mullet/sinatra.rb', line 54 def mullet(view_name, ={}, locals={}) # The options hash may contain a key :locals with the value being a # hash mapping variable names to values. locals.merge!(.delete(:locals) || {}) # Get application settings. = { root: settings.root, views: settings.views } if settings.respond_to?(:mullet) = settings.mullet.merge() end .merge!() # Copy instance variables set by Sinatra application. application_data = Object.new() instance_variables.each do |name| application_data.instance_variable_set( name, instance_variable_get(name)) end # Render view. template = @@engine.get_template(view_name, ) view_class = @@engine.get_view_class(view_name, ) view = view_class.new() view.set_model(application_data, locals) output = '' template.execute(view, output) # Render layout. layout_name = :layout if [:layout] layout_name = [:layout] end if layout_name != false # If configured layout is true or nil, then use :layout. if layout_name == true || !layout_name layout_name = :layout end layout = @@engine.get_template(layout_name, ) view_class = @@engine.get_view_class(layout_name, ) view = view_class.new() view.set_model(application_data, locals, { content: output }) layout_output = '' layout.execute(view, layout_output) output = layout_output end return output end |