bkerley (owner)

Revisions

gist: 61672 Download_button fork
public
Public Clone URL: git://gist.github.com/61672.git
Embed All Files: show embed
compose_tag.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
desc %{
A variable field that composes into a new user-specified tag,
allowing for dynamic resource insertion.
*Insert the flv referred to by the "my flv" key in the current block using a p:flv*
<pre><code><g:compose key="my flv" into="flv" as="title"></code></pre>
}
tag 'compose' do |tag|
  required_fields = %w{key into as}
  raise TagError.new("Compose requires #{required_fields.join(', ')}") unless
    required_fields.all?{|f|tag.attr[f]}
  
  value = tag.globals.variables[tag.attr['key']]
  into = tag.attr['into'].gsub(/^p:/,'')
  as = tag.attr['as']
  
  composition_attrs = tag.attr.dup
  required_fields.each{|f|composition_attrs.delete(f)}
  
  composition_attrs[as] = value
  return tag.render(into, composition_attrs)
end