blocks 2.2.1 → 2.3.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.
@@ -1,3 +1,6 @@
1
+ 2.3.0 (August 27, 2013)
2
+ * Moved all of the call call_if_proc and call_each_hash_value_if_proc and ProcWithArgs class into a separate gem (https://github.com/hunterae/call_with_params), now a dependency.
3
+
1
4
  2.2.0 (August 16, 2013)
2
5
  * Moved evaluated_procs and evaulated_proc into their own class and renamed to call_each_hash_value and call and created view helpers called call_each_hash_value_if_proc and call_if_proc
3
6
 
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "rails", ">= 3.0.0"
4
+ gem "call_with_params"
4
5
 
5
6
  group :development do
6
7
  gem "bundler", "~> 1.1.5"
@@ -1 +1,7 @@
1
- Note: I am going to be completely rewriting this documentation, and what was here may have been invalid so stay tuned.
1
+ = Blocks
2
+
3
+ How do you render your blocks of code?
4
+
5
+ The idea of this gem is simple (yet difficult to see the practical application for): blocks of code, regardless of code, whether they are a ruby block or a rails partial, are, or should be, completely interchangeable.
6
+
7
+ This gem seeks to set an order of precedence for how rails determines how to render a block of code.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "blocks"
8
- s.version = "2.2.1"
8
+ s.version = "2.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Hunter"]
12
- s.date = "2013-08-20"
12
+ s.date = "2013-08-27"
13
13
  s.description = "Blocks goes beyond blocks and partials"
14
14
  s.email = "hunterae@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -29,12 +29,10 @@ Gem::Specification.new do |s|
29
29
  "lib/blocks/base.rb",
30
30
  "lib/blocks/container.rb",
31
31
  "lib/blocks/controller_additions.rb",
32
- "lib/blocks/proc_with_args.rb",
33
32
  "lib/blocks/view_additions.rb",
34
33
  "rails/init.rb",
35
34
  "spec/blocks/base_spec.rb",
36
35
  "spec/blocks/blocks_spec.rb",
37
- "spec/blocks/proc_with_args_spec.rb",
38
36
  "spec/blocks/view_additions_spec.rb",
39
37
  "spec/spec_helper.rb"
40
38
  ]
@@ -49,17 +47,20 @@ Gem::Specification.new do |s|
49
47
 
50
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
49
  s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
50
+ s.add_runtime_dependency(%q<call_with_params>, [">= 0"])
52
51
  s.add_development_dependency(%q<bundler>, ["~> 1.1.5"])
53
52
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
54
53
  s.add_development_dependency(%q<rcov>, [">= 0"])
55
54
  else
56
55
  s.add_dependency(%q<rails>, [">= 3.0.0"])
56
+ s.add_dependency(%q<call_with_params>, [">= 0"])
57
57
  s.add_dependency(%q<bundler>, ["~> 1.1.5"])
58
58
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
59
  s.add_dependency(%q<rcov>, [">= 0"])
60
60
  end
61
61
  else
62
62
  s.add_dependency(%q<rails>, [">= 3.0.0"])
63
+ s.add_dependency(%q<call_with_params>, [">= 0"])
63
64
  s.add_dependency(%q<bundler>, ["~> 1.1.5"])
64
65
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
66
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -1,5 +1,6 @@
1
1
  require "action_view"
2
2
  require "action_controller"
3
+ require "call_with_params"
3
4
 
4
5
  module Blocks
5
6
  autoload :Base, "blocks/base"
@@ -1,5 +1,7 @@
1
1
  module Blocks
2
2
  class Base
3
+ include CallWithParams
4
+
3
5
  # a pointer to the ActionView that called Blocks
4
6
  attr_accessor :view
5
7
 
@@ -57,7 +59,7 @@ module Blocks
57
59
 
58
60
  if collection
59
61
  collection.each do |object|
60
- define(view.call_if_proc(name, object, options), options, &block)
62
+ define(call_with_params(name, object, options), options, &block)
61
63
  end
62
64
  else
63
65
  self.define_block_container(name, options, &block)
@@ -155,7 +157,7 @@ module Blocks
155
157
  cloned_options = cloned_options.merge(object.options) if object.is_a?(Blocks::Container)
156
158
  cloned_args.push(cloned_options)
157
159
 
158
- block_name = view.call_if_proc(name_or_container, *cloned_args)
160
+ block_name = call_with_params(name_or_container, *cloned_args)
159
161
  as_name = (as.presence || block_name).to_sym
160
162
  cloned_options[as_name] = object
161
163
 
@@ -657,7 +659,7 @@ module Blocks
657
659
 
658
660
  def content_tag(tag, tag_html, *args, &block)
659
661
  if tag
660
- view.content_tag(tag, block.call, view.call_each_hash_value_if_proc(tag_html, *args))
662
+ view.content_tag(tag, block.call, call_each_hash_value_with_params(tag_html, *args))
661
663
  else
662
664
  block.call
663
665
  end
@@ -7,14 +7,6 @@ module Blocks
7
7
  @blocks.blocks.merge! @controller_blocks.blocks if @controller_blocks
8
8
  @blocks
9
9
  end
10
-
11
- def call_if_proc(*args)
12
- Blocks::ProcWithArgs.call(*args)
13
- end
14
-
15
- def call_each_hash_value_if_proc(*args)
16
- Blocks::ProcWithArgs.call_each_hash_value(*args)
17
- end
18
10
  end
19
11
  end
20
12
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 2
9
- - 1
10
- version: 2.2.1
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Hunter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-08-20 00:00:00 Z
18
+ date: 2013-08-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -35,6 +35,20 @@ dependencies:
35
35
  type: :runtime
36
36
  - !ruby/object:Gem::Dependency
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
47
+ prerelease: false
48
+ name: call_with_params
49
+ type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
38
52
  none: false
39
53
  requirements:
40
54
  - - ~>
@@ -45,12 +59,12 @@ dependencies:
45
59
  - 1
46
60
  - 5
47
61
  version: 1.1.5
48
- requirement: *id002
62
+ requirement: *id003
49
63
  prerelease: false
50
64
  name: bundler
51
65
  type: :development
52
66
  - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
54
68
  none: false
55
69
  requirements:
56
70
  - - ~>
@@ -61,12 +75,12 @@ dependencies:
61
75
  - 6
62
76
  - 4
63
77
  version: 1.6.4
64
- requirement: *id003
78
+ requirement: *id004
65
79
  prerelease: false
66
80
  name: jeweler
67
81
  type: :development
68
82
  - !ruby/object:Gem::Dependency
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
70
84
  none: false
71
85
  requirements:
72
86
  - - ">="
@@ -75,7 +89,7 @@ dependencies:
75
89
  segments:
76
90
  - 0
77
91
  version: "0"
78
- requirement: *id004
92
+ requirement: *id005
79
93
  prerelease: false
80
94
  name: rcov
81
95
  type: :development
@@ -101,12 +115,10 @@ files:
101
115
  - lib/blocks/base.rb
102
116
  - lib/blocks/container.rb
103
117
  - lib/blocks/controller_additions.rb
104
- - lib/blocks/proc_with_args.rb
105
118
  - lib/blocks/view_additions.rb
106
119
  - rails/init.rb
107
120
  - spec/blocks/base_spec.rb
108
121
  - spec/blocks/blocks_spec.rb
109
- - spec/blocks/proc_with_args_spec.rb
110
122
  - spec/blocks/view_additions_spec.rb
111
123
  - spec/spec_helper.rb
112
124
  homepage: http://github.com/hunterae/blocks
@@ -1,18 +0,0 @@
1
- module Blocks
2
- class ProcWithArgs
3
- def self.call(*args)
4
- return nil unless args.present?
5
- v = args.shift
6
- v.is_a?(Proc) ? v.call(*(args[0, v.arity])) : v
7
- end
8
-
9
- def self.call_each_hash_value(*args)
10
- options = args.shift.presence || {}
11
- if options.is_a?(Proc)
12
- call(options, *args)
13
- else
14
- options.inject({}) { |hash, (k, v)| hash[k] = call(v, *args); hash}
15
- end
16
- end
17
- end
18
- end
@@ -1,50 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Blocks::ProcWithArgs do
4
- before :each do
5
- @view = ActionView::Base.new
6
- end
7
-
8
- describe "call_each_hash_value method" do
9
- it "should evaluate any proc options" do
10
- proc1 = lambda {@view.cycle("even", "odd")}
11
- proc2 = lambda {@view.cycle("one", "two")}
12
- evaluated_procs = Blocks::ProcWithArgs.call_each_hash_value(:class => proc1, :id => proc2, :style => "color:red")
13
- evaluated_procs[:class].should eql "even"
14
- evaluated_procs[:id].should eql "one"
15
- evaluated_procs[:style].should eql "color:red"
16
- end
17
-
18
- it "should pass any additional arguments to evaluated procs" do
19
- proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
20
- evaluated_procs = Blocks::ProcWithArgs.call_each_hash_value({:class => proc1}, 1, 2)
21
- evaluated_procs[:class].should eql "user_1_2"
22
- end
23
- end
24
-
25
- describe "call method" do
26
- it "should evaluate a proc" do
27
- proc = lambda {@view.cycle("even", "odd")}
28
- Blocks::ProcWithArgs.call(proc).should eql "even"
29
- Blocks::ProcWithArgs.call(proc).should eql "odd"
30
- Blocks::ProcWithArgs.call(proc).should eql "even"
31
- end
32
-
33
- it "should just return the value if it is not a proc" do
34
- Blocks::ProcWithArgs.call("1234").should eql "1234"
35
- end
36
-
37
- it "should return nil if no arguments are specified" do
38
- Blocks::ProcWithArgs.call.should be_nil
39
- end
40
-
41
- it "should treat the first argument as the potential proc to evaluate" do
42
- Blocks::ProcWithArgs.call(1, 2, 3).should eql 1
43
- end
44
-
45
- it "should pass any additional arguments to the evaluated proc" do
46
- proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
47
- Blocks::ProcWithArgs.call(proc1, 1, 2).should eql "user_1_2"
48
- end
49
- end
50
- end