blocks 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@
31
31
  <% end %>
32
32
 
33
33
  <% table.columns.each do |column| %>
34
- <%= table.define "#{column.name.to_s}_header", :column => column do |options| %>
34
+ <%= table.define "#{column.name.to_s}_header", :column => column do |record, options| %>
35
35
  <%= column.options[:label] ? column.options[:label] : column.name.to_s.titleize %>
36
36
  <% end %>
37
37
  <% end %>
@@ -57,14 +57,14 @@
57
57
  <%= table.define :data_columns do |options| %>
58
58
  <% table.columns.each do |column| %>
59
59
  <%= content_tag :td, options.merge(column.options)[:column_html] do %>
60
- <%= table.use column, options.merge(:column => column) %>
60
+ <%= table.use column, options[:record], options.merge(:column => column) %>
61
61
  <% end %>
62
62
  <% end %>
63
63
  <% end %>
64
64
 
65
65
  <% table.columns.each do |column| %>
66
- <%= table.define column.name, :column => column do |options| %>
67
- <%= options[:record].send(options[:column].name) %>
66
+ <%= table.define column.name, :column => column do |record, options| %>
67
+ <%= record.send(options[:column].name) %>
68
68
  <% end %>
69
69
  <% end %>
70
70
 
@@ -30,12 +30,12 @@ module Blocks
30
30
  nil
31
31
  end
32
32
 
33
- def use(*args, &block)
33
+ def use(*args, &block)
34
34
  options = args.extract_options!
35
35
 
36
36
  # If the user doesn't specify a block name, we generate an anonymous block name to assure other
37
37
  # anonymous blocks don't override its definition
38
- name = args.first ? args.first : self.anonymous_block_name
38
+ name = args.first ? args.shift : self.anonymous_block_name
39
39
 
40
40
  block_container = Blocks::Container.new
41
41
  block_container.name = name
@@ -45,7 +45,7 @@ module Blocks
45
45
  blocks[name.to_sym] = block_container if !name.is_a?(Blocks::Container) and blocks[name.to_sym].nil? and block
46
46
 
47
47
  if start_rendering_blocks
48
- render_block name, options
48
+ render_block name, args, options
49
49
  else
50
50
  # Delays rendering this block until the partial has been rendered and all the blocks have had a chance to be defined
51
51
  self.block_positions << block_container
@@ -143,7 +143,7 @@ module Blocks
143
143
  "block_#{anonymous_block_number}"
144
144
  end
145
145
 
146
- def render_block(name_or_container, options={})
146
+ def render_block(name_or_container, args, options={})
147
147
  render_options = options
148
148
 
149
149
  if (name_or_container.is_a?(Blocks::Container))
@@ -157,10 +157,32 @@ module Blocks
157
157
 
158
158
  if blocks[name]
159
159
  block_container = blocks[name]
160
- view.concat(view.capture shared_options.merge(block_container.options).merge(render_options), &block_container.block)
160
+
161
+ args.push(shared_options.merge(block_container.options).merge(render_options))
162
+
163
+ # If the block is taking more than one parameter, we can use *args
164
+ if block_container.block.arity > 1
165
+ view.concat(view.capture *args, &block_container.block)
166
+
167
+ # However, if the block only takes a single parameter, we do not want ruby to try to cram the args list into that parameter
168
+ # as an array
169
+ else
170
+ view.concat(view.capture args.first, &block_container.block)
171
+ end
161
172
  elsif view.blocks.blocks[name]
162
173
  block_container = view.blocks.blocks[name]
163
- view.concat(view.capture shared_options.merge(block_container.options).merge(render_options), &block_container.block)
174
+
175
+ args.push(shared_options.merge(block_container.options).merge(render_options))
176
+
177
+ # If the block is taking more than one parameter, we can use *args
178
+ if block_container.block.arity > 1
179
+ view.concat(view.capture *args, &block_container.block)
180
+
181
+ # However, if the block only takes a single parameter, we do not want ruby to try to cram the args list into that parameter
182
+ # as an array
183
+ else
184
+ view.concat(view.capture args.first, &block_container.block)
185
+ end
164
186
  else
165
187
  begin
166
188
  begin
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 1.0.2
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Hunter
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-01-10 00:00:00 -05:00
19
+ date: 2011-02-03 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies: []
22
22