Class: Stasis::Render
Instance Method Summary collapse
-
#initialize(stasis) ⇒ Render
constructor
A new instance of Render.
-
#render(path_or_options = {}, options = {}, &block) ⇒ Object
This method is bound to all actions.
Methods inherited from Plugin
#_match_key?, _priority, #_within?, inherited, plugins, priority
Constructor Details
#initialize(stasis) ⇒ Render
Returns a new instance of Render.
8 9 10 |
# File 'lib/stasis/plugins/render.rb', line 8 def initialize(stasis) @stasis = stasis end |
Instance Method Details
#render(path_or_options = {}, options = {}, &block) ⇒ Object
This method is bound to all actions.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/stasis/plugins/render.rb', line 13 def render(={}, ={}, &block) if .is_a?(::String) [:path] = else .merge!() end callback = [:callback] locals = [:locals] path = [:path] ext = File.extname(path.to_s)[1..-1] scope = [:scope] text = [:text] = Options.get_template_option(ext).merge( [:template] || {} ) if @stasis.controller path = @stasis.controller._resolve(path) end output = if text text elsif path && File.file?(path) unless callback == false # Trigger all plugin `before_render` events. temporary_path(path) do @stasis.trigger(:before_render) end end output = if Tilt.mappings.keys.include?(ext) scope = [:scope] ||= @stasis.action tilt = Tilt.new(path, nil, ) if block_given? tilt.render(scope, locals, &block) else tilt.render(scope, locals) { nil } end else File.read(path) end unless callback == false # Trigger all plugin `after_render` events. temporary_path(path) do @stasis.trigger(:after_render) end end output end output end |