blocks 2.8.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +4 -4
  3. data/.travis.yml +51 -0
  4. data/Gemfile +15 -2
  5. data/Guardfile +15 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +41 -0
  8. data/Rakefile +3 -7
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/blocks.gemspec +18 -11
  12. data/gemfiles/Gemfile.rails-3-0-stable +13 -0
  13. data/gemfiles/Gemfile.rails-3-1-stable +13 -0
  14. data/gemfiles/Gemfile.rails-3-2-stable +13 -0
  15. data/gemfiles/Gemfile.rails-4-0-stable +12 -0
  16. data/gemfiles/Gemfile.rails-4-1-stable +12 -0
  17. data/gemfiles/Gemfile.rails-4-2-stable +12 -0
  18. data/gemfiles/Gemfile.rails-5-0-stable +10 -0
  19. data/gemfiles/Gemfile.rails-5-1-stable +10 -0
  20. data/lib/blocks.rb +41 -20
  21. data/lib/blocks/action_view_extensions/view_extensions.rb +26 -0
  22. data/lib/blocks/builders/block_definition.rb +71 -0
  23. data/lib/blocks/builders/builder.rb +159 -0
  24. data/lib/blocks/builders/hook_definition.rb +25 -0
  25. data/lib/blocks/experimental/builder_permissions.rb +52 -0
  26. data/lib/blocks/experimental/invalid_permissions_handler.rb +27 -0
  27. data/lib/blocks/renderers/abstract_renderer.rb +69 -0
  28. data/lib/blocks/renderers/adjacent_blocks_renderer.rb +15 -0
  29. data/lib/blocks/renderers/block_placeholder.rb +13 -0
  30. data/lib/blocks/renderers/block_renderer.rb +13 -0
  31. data/lib/blocks/renderers/block_with_hooks_renderer.rb +35 -0
  32. data/lib/blocks/renderers/collection_renderer.rb +17 -0
  33. data/lib/blocks/renderers/nesting_blocks_renderer.rb +24 -0
  34. data/lib/blocks/renderers/partial_renderer.rb +18 -0
  35. data/lib/blocks/renderers/renderer.rb +43 -0
  36. data/lib/blocks/renderers/runtime_context.rb +193 -0
  37. data/lib/blocks/renderers/wrapper_renderer.rb +19 -0
  38. data/lib/blocks/utilities/configurator.rb +26 -0
  39. data/lib/blocks/utilities/dynamic_configuration.rb +71 -0
  40. data/lib/blocks/utilities/hash_with_caller.rb +73 -0
  41. data/lib/blocks/utilities/hash_with_render_strategy.rb +47 -0
  42. data/lib/blocks/utilities/options_set.rb +95 -0
  43. data/lib/blocks/version.rb +1 -1
  44. metadata +70 -80
  45. data/.ruby-gemset +0 -1
  46. data/.ruby-version +0 -1
  47. data/README.rdoc +0 -99
  48. data/blocks_render_order.graffle +0 -1397
  49. data/blocks_render_order.png +0 -0
  50. data/lib/blocks/base.rb +0 -580
  51. data/lib/blocks/container.rb +0 -5
  52. data/lib/blocks/controller_additions.rb +0 -9
  53. data/lib/blocks/view_additions.rb +0 -10
  54. data/rails/init.rb +0 -1
  55. data/spec/blocks/base_spec.rb +0 -641
  56. data/spec/blocks/blocks_spec.rb +0 -12
  57. data/spec/blocks/view_additions_spec.rb +0 -22
  58. data/spec/spec_helper.rb +0 -22
@@ -0,0 +1,73 @@
1
+ module Blocks
2
+ class HashWithCaller < HashWithIndifferentAccess
3
+ attr_accessor :callers
4
+
5
+ def initialize(*args)
6
+ self.callers = HashWithIndifferentAccess.new
7
+ options = args.extract_options!
8
+ add_options(args.first, options)
9
+ super &nil
10
+ end
11
+
12
+ def to_s
13
+ description = []
14
+
15
+ description << "{"
16
+ description << map do |key, value|
17
+ value_display = case value
18
+ when Symbol
19
+ ":#{value}"
20
+ when String
21
+ "\"#{value}\""
22
+ when Proc
23
+ "Proc"
24
+ else
25
+ value
26
+ end
27
+ "\"#{key}\" => #{value_display}, # [#{callers[key]}]"
28
+ end.join(",\n")
29
+ description << "}"
30
+ description.join("\n")
31
+ end
32
+
33
+ def add_options(*args)
34
+ options = args.extract_options!
35
+
36
+ caller_id = args.first.to_s.presence || ""
37
+
38
+ if !options.is_a?(HashWithCaller) && Blocks.lookup_caller_location?
39
+ caller_location = caller.detect do |c|
40
+ !c.include?("/lib/blocks") &&
41
+ !c.include?("/lib/ruby") &&
42
+ !c.include?("patch")
43
+ end.try(:split, ":in").try(:[], 0)
44
+
45
+ caller_id += " from #{caller_location}" if caller_location
46
+ end
47
+
48
+ options.each do |key, value|
49
+ current_value = self[key]
50
+
51
+ if options.is_a?(HashWithCaller)
52
+ setter = options.callers[key]
53
+ else
54
+ setter = "set by #{caller_id}"
55
+ end
56
+
57
+ if !self.key?(key)
58
+ self[key] = value
59
+ callers[key] = setter
60
+
61
+ elsif current_value.is_a?(Hash) && value.is_a?(Hash)
62
+ self[key] = value.deep_merge(current_value)
63
+ callers[key] = "#{callers[key]}, #{setter}"
64
+ # TODO: handle attribute merges here
65
+ end
66
+ end
67
+ end
68
+
69
+ def nested_under_indifferent_access
70
+ self
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,47 @@
1
+ module Blocks
2
+ class HashWithRenderStrategy < HashWithCaller
3
+ attr_accessor :render_strategy
4
+
5
+ RENDER_WITH_PROXY = :with
6
+ RENDER_WITH_BLOCK = :block
7
+ RENDER_WITH_PARTIAL = :partial
8
+
9
+ RENDERING_STRATEGIES = [RENDER_WITH_PROXY, RENDER_WITH_BLOCK, RENDER_WITH_PARTIAL]
10
+
11
+ def initialize_copy(original)
12
+ super
13
+ self.callers = original.callers.clone
14
+ self.render_strategy = nil
15
+ RENDERING_STRATEGIES.each do |rs|
16
+ self.delete(rs)
17
+ end
18
+ end
19
+
20
+ alias_method :dup, :clone
21
+
22
+ def reverse_merge(options)
23
+ self.clone.tap {|cloned| cloned.add_options(options) }
24
+ end
25
+
26
+ def add_options(*args, &block)
27
+ options = args.extract_options!
28
+ if !options.is_a?(HashWithIndifferentAccess)
29
+ options = options.with_indifferent_access
30
+ end
31
+ options[:block] = block if block
32
+ if render_strategy.nil?
33
+ self.render_strategy = if options.is_a?(HashWithRenderStrategy)
34
+ options.render_strategy
35
+ else
36
+ RENDERING_STRATEGIES.detect {|render_strategy| options[render_strategy].present? }
37
+ end
38
+ end
39
+
40
+ super(*args, options)
41
+ end
42
+
43
+ def render_strategy_and_item
44
+ [render_strategy, self[render_strategy]] if render_strategy
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,95 @@
1
+ module Blocks
2
+ class OptionsSet < HashWithIndifferentAccess
3
+ attr_accessor :name
4
+
5
+ attr_accessor :runtime_options
6
+ attr_accessor :standard_options
7
+ attr_accessor :default_options
8
+
9
+ def initialize(*args, &block)
10
+ options = args.extract_options!
11
+ self.name = args.first
12
+ reset
13
+ add_options options, &block
14
+ super(&nil)
15
+ end
16
+
17
+ def initialize_copy(original)
18
+ super
19
+ control_fields = (
20
+ RuntimeContext::CONTROL_VARIABLES.keys +
21
+ RuntimeContext::CONTROL_VARIABLES.values
22
+ ).flatten.compact
23
+ self.runtime_options = original.runtime_options.clone.except(*control_fields)
24
+ self.default_options = original.default_options.clone.except(*control_fields)
25
+ self.standard_options = original.standard_options.clone.except(*control_fields)
26
+ end
27
+
28
+ def to_s
29
+ description = []
30
+ description << "Block Name: #{name}"
31
+ description << "------------------------------"
32
+ description << "Runtime Options:"
33
+ description << runtime_options.to_s
34
+ description << "------------------------------"
35
+ description << "Standard Options:"
36
+ description << standard_options.to_s
37
+ description << "------------------------------"
38
+ description << "Default Options:"
39
+ description << default_options.to_s
40
+ description.join("\n")
41
+ end
42
+
43
+ def inspect
44
+ hash = standard_options.to_hash
45
+ hash[:defaults] = default_options if default_options.present?
46
+ hash[:runtime] = runtime_options if runtime_options.present?
47
+ hash
48
+ end
49
+
50
+ def add_options(*args, &block)
51
+ options = args.extract_options!
52
+ caller_id = args.first
53
+
54
+ runtime, defaults, standard = if options.is_a?(OptionsSet)
55
+ caller_id ||= options.name
56
+ [options.runtime_options, options.default_options, options.standard_options]
57
+ else
58
+ if !options.is_a?(HashWithIndifferentAccess)
59
+ options = options.with_indifferent_access
60
+ end
61
+ [options.delete(:runtime), options.delete(:defaults), options]
62
+ end
63
+
64
+ caller_id ||= self.name
65
+
66
+ runtime_options.add_options caller_id, runtime
67
+ standard_options.add_options caller_id, standard, &block
68
+ default_options.add_options caller_id, defaults
69
+
70
+ self
71
+ end
72
+
73
+ def reset
74
+ self.runtime_options = HashWithRenderStrategy.new "#{name} Runtime Options"
75
+ self.standard_options = HashWithRenderStrategy.new "#{name} Standard Options"
76
+ self.default_options = HashWithRenderStrategy.new "#{name} Default Options"
77
+ end
78
+
79
+ def current_render_strategy_and_item
80
+ render_strategies_and_items.compact.first
81
+ end
82
+
83
+ def render_strategies_and_items
84
+ [
85
+ runtime_options.render_strategy_and_item,
86
+ standard_options.render_strategy_and_item,
87
+ default_options.render_strategy_and_item
88
+ ]
89
+ end
90
+
91
+ def nested_under_indifferent_access
92
+ self
93
+ end
94
+ end
95
+ end
@@ -1,3 +1,3 @@
1
1
  module Blocks
2
- VERSION = "2.8.0"
2
+ VERSION = "3.0.0.rc1"
3
3
  end
metadata CHANGED
@@ -1,169 +1,159 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 3.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hunter
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2017-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: 3.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: 3.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: call_with_params
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 0.0.2
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 0.0.2
41
- - !ruby/object:Gem::Dependency
42
- name: hashie
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
17
+ - - ">="
46
18
  - !ruby/object:Gem::Version
47
19
  version: '0'
48
20
  type: :runtime
49
21
  prerelease: false
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
52
- - - ! '>='
24
+ - - ">="
53
25
  - !ruby/object:Gem::Version
54
26
  version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
- name: simplecov
28
+ name: rails
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
- - - ! '>='
31
+ - - ">="
60
32
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
33
+ version: 3.0.0
34
+ type: :runtime
63
35
  prerelease: false
64
36
  version_requirements: !ruby/object:Gem::Requirement
65
37
  requirements:
66
- - - ! '>='
38
+ - - ">="
67
39
  - !ruby/object:Gem::Version
68
- version: '0'
40
+ version: 3.0.0
69
41
  - !ruby/object:Gem::Dependency
70
- name: rspec-rails
42
+ name: nokogiri
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
- - - ! '>='
45
+ - - '='
74
46
  - !ruby/object:Gem::Version
75
- version: '0'
47
+ version: 1.6.8.1
76
48
  type: :development
77
49
  prerelease: false
78
50
  version_requirements: !ruby/object:Gem::Requirement
79
51
  requirements:
80
- - - ! '>='
52
+ - - '='
81
53
  - !ruby/object:Gem::Version
82
- version: '0'
54
+ version: 1.6.8.1
83
55
  - !ruby/object:Gem::Dependency
84
- name: mocha
56
+ name: capybara
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
- - - ! '>='
59
+ - - ">="
88
60
  - !ruby/object:Gem::Version
89
61
  version: '0'
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
- - - ! '>='
66
+ - - ">="
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: debugger
70
+ name: simplecov
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
- - - ! '>='
73
+ - - ">="
102
74
  - !ruby/object:Gem::Version
103
75
  version: '0'
104
76
  type: :development
105
77
  prerelease: false
106
78
  version_requirements: !ruby/object:Gem::Requirement
107
79
  requirements:
108
- - - ! '>='
80
+ - - ">="
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
- description: Blocks goes beyond blocks and partials
83
+ description: Blocks gives you total control over how your blocks of code render.
112
84
  email:
113
85
  - hunterae@gmail.com
114
86
  executables: []
115
87
  extensions: []
116
88
  extra_rdoc_files: []
117
89
  files:
118
- - .gitignore
119
- - .rspec
120
- - .ruby-gemset
121
- - .ruby-version
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
122
93
  - CHANGELOG.rdoc
123
94
  - Gemfile
124
- - README.rdoc
95
+ - Guardfile
96
+ - LICENSE.txt
97
+ - README.md
125
98
  - Rakefile
99
+ - bin/console
100
+ - bin/setup
126
101
  - blocks.gemspec
127
- - blocks_render_order.graffle
128
- - blocks_render_order.png
102
+ - gemfiles/Gemfile.rails-3-0-stable
103
+ - gemfiles/Gemfile.rails-3-1-stable
104
+ - gemfiles/Gemfile.rails-3-2-stable
105
+ - gemfiles/Gemfile.rails-4-0-stable
106
+ - gemfiles/Gemfile.rails-4-1-stable
107
+ - gemfiles/Gemfile.rails-4-2-stable
108
+ - gemfiles/Gemfile.rails-5-0-stable
109
+ - gemfiles/Gemfile.rails-5-1-stable
129
110
  - lib/blocks.rb
130
- - lib/blocks/base.rb
131
- - lib/blocks/container.rb
132
- - lib/blocks/controller_additions.rb
111
+ - lib/blocks/action_view_extensions/view_extensions.rb
112
+ - lib/blocks/builders/block_definition.rb
113
+ - lib/blocks/builders/builder.rb
114
+ - lib/blocks/builders/hook_definition.rb
115
+ - lib/blocks/experimental/builder_permissions.rb
116
+ - lib/blocks/experimental/invalid_permissions_handler.rb
117
+ - lib/blocks/renderers/abstract_renderer.rb
118
+ - lib/blocks/renderers/adjacent_blocks_renderer.rb
119
+ - lib/blocks/renderers/block_placeholder.rb
120
+ - lib/blocks/renderers/block_renderer.rb
121
+ - lib/blocks/renderers/block_with_hooks_renderer.rb
122
+ - lib/blocks/renderers/collection_renderer.rb
123
+ - lib/blocks/renderers/nesting_blocks_renderer.rb
124
+ - lib/blocks/renderers/partial_renderer.rb
125
+ - lib/blocks/renderers/renderer.rb
126
+ - lib/blocks/renderers/runtime_context.rb
127
+ - lib/blocks/renderers/wrapper_renderer.rb
128
+ - lib/blocks/utilities/configurator.rb
129
+ - lib/blocks/utilities/dynamic_configuration.rb
130
+ - lib/blocks/utilities/hash_with_caller.rb
131
+ - lib/blocks/utilities/hash_with_render_strategy.rb
132
+ - lib/blocks/utilities/options_set.rb
133
133
  - lib/blocks/version.rb
134
- - lib/blocks/view_additions.rb
135
- - rails/init.rb
136
- - spec/blocks/base_spec.rb
137
- - spec/blocks/blocks_spec.rb
138
- - spec/blocks/view_additions_spec.rb
139
- - spec/spec_helper.rb
140
- homepage: http://github.com/hunterae/blocks
134
+ homepage: https://github.com/hunterae/blocks
141
135
  licenses:
142
136
  - MIT
143
- metadata: {}
137
+ metadata:
138
+ allowed_push_host: https://rubygems.org
144
139
  post_install_message:
145
140
  rdoc_options: []
146
141
  require_paths:
147
142
  - lib
148
143
  required_ruby_version: !ruby/object:Gem::Requirement
149
144
  requirements:
150
- - - ! '>='
145
+ - - ">="
151
146
  - !ruby/object:Gem::Version
152
147
  version: '0'
153
148
  required_rubygems_version: !ruby/object:Gem::Requirement
154
149
  requirements:
155
- - - ! '>='
150
+ - - ">"
156
151
  - !ruby/object:Gem::Version
157
- version: '0'
152
+ version: 1.3.1
158
153
  requirements: []
159
154
  rubyforge_project:
160
- rubygems_version: 2.4.2
155
+ rubygems_version: 2.6.11
161
156
  signing_key:
162
157
  specification_version: 4
163
- summary: Blocks goes beyond blocks and partials
164
- test_files:
165
- - spec/blocks/base_spec.rb
166
- - spec/blocks/blocks_spec.rb
167
- - spec/blocks/view_additions_spec.rb
168
- - spec/spec_helper.rb
169
- has_rdoc:
158
+ summary: Blocks gives you total control over how your blocks of code render.
159
+ test_files: []