Module: Hypertemplate::Hook::Rails::Helpers
- Defined in:
- lib/hypertemplate/hook/rails.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#partial(partial_path, caller_binding = nil) ⇒ Object
Load a partial template to execute in describe.
Class Method Details
.extend_object(base) ⇒ Object
61 62 63 64 |
# File 'lib/hypertemplate/hook/rails.rb', line 61 def self.extend_object(base) super base.extend(Rails3Adapter) unless base.respond_to?(:_pick_partial_template) end |
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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hypertemplate/hook/rails.rb', line 88 def partial(partial_path, caller_binding = nil) template = _pick_partial_template(partial_path) # 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 |