Class: Tilt::Jbuilder
- Inherits:
-
Jbuilder
- Object
- Jbuilder
- Tilt::Jbuilder
- Defined in:
- lib/tilt/jbuilder.rb
Instance Method Summary collapse
- #array!(collection = [], *attributes, &block) ⇒ Object
-
#cache!(key = nil, options = {}, &block) ⇒ Object
for now caching is not supported, but at least we can transparently ignore it.
-
#initialize(scope, *args, &block) ⇒ Jbuilder
constructor
A new instance of Jbuilder.
- #partial!(name_or_options, locals = {}) ⇒ Object
Constructor Details
#initialize(scope, *args, &block) ⇒ Jbuilder
Returns a new instance of Jbuilder.
6 7 8 9 |
# File 'lib/tilt/jbuilder.rb', line 6 def initialize(scope, *args, &block) @scope = scope super(*args, &block) end |
Instance Method Details
#array!(collection = [], *attributes, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/tilt/jbuilder.rb', line 29 def array!(collection = [], *attributes, &block) = attributes. if .key?(:partial) partial! [:partial], .merge(collection: collection) else super end end |
#cache!(key = nil, options = {}, &block) ⇒ Object
for now caching is not supported, but at least we can transparently ignore it
40 41 42 |
# File 'lib/tilt/jbuilder.rb', line 40 def cache!(key=nil, ={}, &block) yield end |
#partial!(name_or_options, locals = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tilt/jbuilder.rb', line 11 def partial!(, locals = {}) case when ::Hash # partial! partial: 'name', locals: { foo: 'bar' } = else # partial! 'name', foo: 'bar' = { partial: , locals: locals } as = locals.delete(:as) [:as] = as if as.present? [:collection] = locals[:collection] if locals.key?(:collection) end view_path = @scope.instance_variable_get('@_jbuilder_view_path') template = ::Tilt::JbuilderTemplate.new(fetch_partial_path([:partial].to_s, view_path), nil, view_path: view_path) template, end |