blocks 0.3 → 0.4

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.
@@ -1,11 +1,18 @@
1
1
  module Blocks
2
2
  module Helper
3
+ def blocks
4
+ options = {}
5
+ options[:view] = self
6
+
7
+ @blocks ||= Blocks::Context.new(options)
8
+ end
9
+
10
+ def evaluated_content_options(options={})
11
+ evaluated_options = {}
12
+ options.each_pair { |k, v| evaluated_options[k] = (v.is_a?(Proc) ? v.call : v)}
13
+ evaluated_options
14
+ end
3
15
 
4
- # def self.included(base)
5
- # base.extend Helper
6
- # # base.helper_method :table_for, :evaluated_content_options, :request_blocks
7
- # end
8
-
9
16
  def table_for(records, options={}, &block)
10
17
  options[:view] = self
11
18
  options[:records] = records
@@ -14,18 +21,15 @@ module Blocks
14
21
 
15
22
  Blocks::TableFor.new(options).render
16
23
  end
17
-
18
- def evaluated_content_options(options={})
19
- evaluated_options = {}
20
- options.each_pair { |k, v| evaluated_options[k] = (v.is_a?(Proc) ? v.call : v)}
21
- evaluated_options
22
- end
23
-
24
- def request_blocks
25
- options = {}
24
+
25
+ def list_for(*args, &block)
26
+ options = args.extract_options!
27
+
26
28
  options[:view] = self
29
+ options[:records] = args.first
30
+ options[:block] = block
27
31
 
28
- @request_blocks ||= Blocks::Context.new(options)
32
+ Blocks::ListFor.new(options).render
29
33
  end
30
34
  end
31
35
  end
@@ -0,0 +1,35 @@
1
+ <%= list.define :list_items do %>
2
+ <% if records %>
3
+ <% records.each do |record| %>
4
+ <%= list.use :item, :record => record %>
5
+ <% end %>
6
+ <% else %>
7
+ <%= list.use :items %>
8
+ <% end %>
9
+ <% end %>
10
+
11
+ <%= list.define :item do |options| %>
12
+ <%= content_tag :li, options[:item_html] do %>
13
+ <%= options[:field] ? options[:record].send(:field) : options[:record].to_s %>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <%= list.define :items do |options| %>
18
+ <% list.items.each do |item| %>
19
+ <%= content_tag :li, options.merge(item.options)[:item_html] do %>
20
+ <%= list.use item.name %>
21
+ <% end %>
22
+ <% end %>
23
+ <% end %>
24
+
25
+ <% list.items.each do |item| %>
26
+ <%= list.define item.name, :item => item do |options| %>
27
+ <%= item.name %>
28
+ <% end %>
29
+ <% end %>
30
+
31
+ <%= list.use :list do |options| %>
32
+ <%= content_tag :ul, options[:list_html] do %>
33
+ <%= list.use :list_items %>
34
+ <% end %>
35
+ <% end %>
@@ -1,8 +1,5 @@
1
- module Blocks; end
2
-
1
+ require 'blocks/container'
3
2
  require 'blocks/context'
4
3
  require 'blocks/table_for'
5
- require 'blocks/engine'
6
- # require 'blocks/helper'
7
-
8
-
4
+ require 'blocks/list_for'
5
+ require 'blocks/engine'
@@ -0,0 +1,5 @@
1
+ module Blocks
2
+ class Container
3
+ attr_accessor :name, :options, :block
4
+ end
5
+ end
@@ -1,8 +1,4 @@
1
1
  module Blocks
2
- class Container
3
- attr_accessor :name, :options, :block
4
- end
5
-
6
2
  class Context
7
3
 
8
4
  attr_accessor :view, :blocks, :block_positions, :anonymous_block_number,
@@ -142,8 +138,8 @@ module Blocks
142
138
  if blocks[name]
143
139
  block_container = blocks[name]
144
140
  ret.concat(view.capture shared_options.merge(block_container.options).merge(render_options), &block_container.block)
145
- elsif view.request_blocks.blocks[name]
146
- block_container = view.request_blocks.blocks[name]
141
+ elsif view.blocks.blocks[name]
142
+ block_container = view.blocks.blocks[name]
147
143
  ret.concat(view.capture shared_options.merge(block_container.options).merge(render_options), &block_container.block)
148
144
  else
149
145
  begin
@@ -166,8 +162,8 @@ module Blocks
166
162
  end
167
163
  end
168
164
 
169
- unless view.request_blocks.blocks[name].nil?
170
- view.request_blocks.blocks[name].each do |block_container|
165
+ unless view.blocks.blocks[name].nil?
166
+ view.blocks.blocks[name].each do |block_container|
171
167
  ret.concat(view.capture shared_options.merge(block_container.options).merge(options), &block_container.block)
172
168
  end
173
169
  end
@@ -185,8 +181,8 @@ module Blocks
185
181
  end
186
182
  end
187
183
 
188
- unless view.request_blocks.blocks[name].nil?
189
- view.request_blocks.blocks[name].each do |block_container|
184
+ unless view.blocks.blocks[name].nil?
185
+ view.blocks.blocks[name].each do |block_container|
190
186
  ret.concat(view.capture shared_options.merge(block_container.options).merge(options), &block_container.block)
191
187
  end
192
188
  end
@@ -3,11 +3,10 @@ require "rails"
3
3
 
4
4
  module Blocks
5
5
  class Engine < Rails::Engine
6
- engine_name :blocks
7
- initializer "blocks.initialize_helpers" do
8
- ActionView::Base.class_eval do
6
+ initializer "blocks.initialize" do
7
+ ActiveSupport.on_load(:action_view) do
9
8
  include Blocks::Helper
10
- end
9
+ end
11
10
  end
12
11
  end
13
12
  end
@@ -0,0 +1,18 @@
1
+ module Blocks
2
+ class ListFor < Blocks::Context
3
+ alias items block_positions
4
+ alias item use
5
+
6
+ def header(name, options={}, &block)
7
+ define("#{name.to_s}_header", options, &block)
8
+ end
9
+
10
+ def initialize(options)
11
+ options[:template] = "blocks/list"
12
+ options[:templates_folder] = "blocks/lists"
13
+ options[:record_variable] = "records"
14
+ options[:variable] = "list"
15
+ super
16
+ end
17
+ end
18
+ end
@@ -8,8 +8,8 @@ module Blocks
8
8
  end
9
9
 
10
10
  def initialize(options)
11
- options[:template] = "blocks/tables/table"
12
- options[:templates_folder] = "tables"
11
+ options[:template] = "blocks/table"
12
+ options[:templates_folder] = "blocks/tables"
13
13
  options[:record_variable] = "records"
14
14
  options[:variable] = "table"
15
15
  super
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- version: "0.3"
8
+ - 4
9
+ version: "0.4"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Hunter
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-06 00:00:00 -05:00
18
+ date: 2010-12-07 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: Blocks makes it easy to create advanced ERB helpers
22
+ description: content_for with parameters, with advanced options such as a table generator (table_for)
23
23
  email: andrew@captico.com
24
24
  executables: []
25
25
 
@@ -29,12 +29,15 @@ extra_rdoc_files:
29
29
  - LICENSE
30
30
  - README
31
31
  files:
32
+ - lib/blocks/container.rb
32
33
  - lib/blocks/context.rb
33
34
  - lib/blocks/engine.rb
35
+ - lib/blocks/list_for.rb
34
36
  - lib/blocks/table_for.rb
35
37
  - lib/blocks.rb
36
38
  - app/helpers/blocks/helper.rb
37
- - app/views/blocks/tables/_table.html.erb
39
+ - app/views/blocks/_list.html.erb
40
+ - app/views/blocks/_table.html.erb
38
41
  - README
39
42
  - LICENSE
40
43
  has_rdoc: true
@@ -71,6 +74,6 @@ rubyforge_project: blocks
71
74
  rubygems_version: 1.3.7
72
75
  signing_key:
73
76
  specification_version: 3
74
- summary: blocks makes erb fun again
77
+ summary: content_for with parameters, with advanced options such as a table generator (table_for)
75
78
  test_files: []
76
79