Module: Tokamak::Hook::Rails::Helpers
- Defined in:
- lib/tokamak/hook/rails.rb
Instance Method Summary collapse
-
#partial(partial_path, caller_binding = nil) ⇒ Object
Load a partial template to execute in describe.
Instance Method Details
#partial(partial_path, caller_binding = nil) ⇒ Object
Load a partial template to execute in describe
For example:
Passing the current context to partial in template:
member(@album) do |member, album|
partial('member', binding)
end
in partial:
member.links << link(:rel => :artists, :href => album_artists_url(album))
Or passing local variables assing
collection(@albums) do |collection|
collection.members do |member, album|
partial("member", :locals => {:member => member, :album => album})
end
end
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tokamak/hook/rails.rb', line 56 def partial(partial_path, caller_binding = nil) begin template = _pick_partial_template(partial_path) rescue NoMethodError self.extend(Rails3Adapter) template = _pick_partial_template(partial_path) end # Create a context to assing variables if caller_binding.kind_of?(Hash) Proc.new do extend @content_type_helpers context = eval("(class << self; self; end)", binding) caller_binding.fetch(:locals, {}).each do |k, v| context.send(:define_method, k.to_sym) { v } end partial(partial_path, binding) end.call else eval(template.source, caller_binding, template.path) end end |