blocks 3.0.4 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +61 -17
- data/CHANGELOG.rdoc +27 -0
- data/Gemfile +11 -10
- data/Guardfile +1 -0
- data/README.md +2 -0
- data/bin/deploy_docs +1 -1
- data/blocks.gemspec +3 -1
- data/docs/_includes/configuration.md +3 -6
- data/docs/_includes/defining.md +7 -7
- data/docs/_includes/{introduction.md → features.md} +2 -2
- data/docs/_includes/helper-blocks.md +5 -0
- data/docs/_includes/helper-blocks/content_tag.md +44 -0
- data/docs/_includes/installation.md +16 -2
- data/docs/_includes/overview.md +21 -0
- data/docs/_includes/templating.md +1 -1
- data/docs/_includes/templating/bootstrap_4_cards.md +9 -9
- data/docs/_layouts/slate.html +11 -9
- data/docs/index.md +3 -1
- data/gemfiles/Gemfile.rails-3-0-stable +1 -0
- data/gemfiles/Gemfile.rails-3-1-stable +1 -0
- data/gemfiles/Gemfile.rails-3-2-stable +1 -0
- data/gemfiles/Gemfile.rails-4-0-stable +2 -1
- data/gemfiles/Gemfile.rails-4-1-stable +2 -1
- data/gemfiles/Gemfile.rails-4-2-stable +2 -1
- data/gemfiles/Gemfile.rails-5-0-stable +4 -3
- data/gemfiles/Gemfile.rails-5-1-stable +4 -3
- data/gemfiles/Gemfile.rails-5-2-stable +13 -0
- data/lib/blocks.rb +37 -29
- data/lib/blocks/builders/block_definition.rb +45 -43
- data/lib/blocks/builders/builder.rb +96 -60
- data/lib/blocks/builders/hook_definition.rb +19 -4
- data/lib/blocks/engine.rb +14 -0
- data/lib/blocks/helpers/controller_extensions.rb +13 -0
- data/lib/blocks/helpers/haml_capture.rb +44 -0
- data/lib/blocks/{action_view_extensions → helpers}/view_extensions.rb +10 -4
- data/lib/blocks/renderers/adjacent_blocks_renderer.rb +9 -7
- data/lib/blocks/renderers/block_placeholder.rb +2 -0
- data/lib/blocks/renderers/block_renderer.rb +26 -5
- data/lib/blocks/renderers/block_with_hooks_renderer.rb +29 -19
- data/lib/blocks/renderers/collection_renderer.rb +19 -6
- data/lib/blocks/renderers/nesting_blocks_renderer.rb +9 -11
- data/lib/blocks/renderers/partial_renderer.rb +16 -14
- data/lib/blocks/renderers/renderer.rb +9 -24
- data/lib/blocks/renderers/runtime_context.rb +174 -152
- data/lib/blocks/renderers/wrapper_renderer.rb +21 -10
- data/lib/blocks/utilities/configurator.rb +30 -6
- data/lib/blocks/utilities/hash_with_caller.rb +36 -32
- data/lib/blocks/utilities/hash_with_render_strategy.rb +67 -19
- data/lib/blocks/utilities/options_set.rb +38 -63
- data/lib/blocks/version.rb +3 -1
- metadata +22 -21
- data/docs/_includes/wip.md +0 -34
- data/lib/blocks/experimental/builder_permissions.rb +0 -52
- data/lib/blocks/experimental/invalid_permissions_handler.rb +0 -27
- data/lib/blocks/renderers/abstract_renderer.rb +0 -69
- data/lib/blocks/utilities/dynamic_configuration.rb +0 -71
metadata
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Hunter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: memory_profiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -82,10 +82,13 @@ files:
|
|
82
82
|
- docs/_includes/custom-builders.md
|
83
83
|
- docs/_includes/defining.md
|
84
84
|
- docs/_includes/demos/hooks-and-wrappers-output.html
|
85
|
+
- docs/_includes/features.md
|
86
|
+
- docs/_includes/helper-blocks.md
|
87
|
+
- docs/_includes/helper-blocks/content_tag.md
|
85
88
|
- docs/_includes/hooks.md
|
86
89
|
- docs/_includes/installation.md
|
87
|
-
- docs/_includes/introduction.md
|
88
90
|
- docs/_includes/option-merging.md
|
91
|
+
- docs/_includes/overview.md
|
89
92
|
- docs/_includes/rendering.md
|
90
93
|
- docs/_includes/reserved-keywords.md
|
91
94
|
- docs/_includes/skipping.md
|
@@ -94,7 +97,6 @@ files:
|
|
94
97
|
- docs/_includes/templating.md
|
95
98
|
- docs/_includes/templating/bootstrap_4_cards.md
|
96
99
|
- docs/_includes/use-cases.md
|
97
|
-
- docs/_includes/wip.md
|
98
100
|
- docs/_includes/wrappers.md
|
99
101
|
- docs/_layouts/slate.html
|
100
102
|
- docs/_plugins/gem_version.rb
|
@@ -147,14 +149,15 @@ files:
|
|
147
149
|
- gemfiles/Gemfile.rails-4-2-stable
|
148
150
|
- gemfiles/Gemfile.rails-5-0-stable
|
149
151
|
- gemfiles/Gemfile.rails-5-1-stable
|
152
|
+
- gemfiles/Gemfile.rails-5-2-stable
|
150
153
|
- lib/blocks.rb
|
151
|
-
- lib/blocks/action_view_extensions/view_extensions.rb
|
152
154
|
- lib/blocks/builders/block_definition.rb
|
153
155
|
- lib/blocks/builders/builder.rb
|
154
156
|
- lib/blocks/builders/hook_definition.rb
|
155
|
-
- lib/blocks/
|
156
|
-
- lib/blocks/
|
157
|
-
- lib/blocks/
|
157
|
+
- lib/blocks/engine.rb
|
158
|
+
- lib/blocks/helpers/controller_extensions.rb
|
159
|
+
- lib/blocks/helpers/haml_capture.rb
|
160
|
+
- lib/blocks/helpers/view_extensions.rb
|
158
161
|
- lib/blocks/renderers/adjacent_blocks_renderer.rb
|
159
162
|
- lib/blocks/renderers/block_placeholder.rb
|
160
163
|
- lib/blocks/renderers/block_renderer.rb
|
@@ -166,7 +169,6 @@ files:
|
|
166
169
|
- lib/blocks/renderers/runtime_context.rb
|
167
170
|
- lib/blocks/renderers/wrapper_renderer.rb
|
168
171
|
- lib/blocks/utilities/configurator.rb
|
169
|
-
- lib/blocks/utilities/dynamic_configuration.rb
|
170
172
|
- lib/blocks/utilities/hash_with_caller.rb
|
171
173
|
- lib/blocks/utilities/hash_with_render_strategy.rb
|
172
174
|
- lib/blocks/utilities/options_set.rb
|
@@ -187,12 +189,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
189
|
version: '0'
|
188
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
191
|
requirements:
|
190
|
-
- - "
|
192
|
+
- - ">"
|
191
193
|
- !ruby/object:Gem::Version
|
192
|
-
version:
|
194
|
+
version: 1.3.1
|
193
195
|
requirements: []
|
194
|
-
|
195
|
-
rubygems_version: 2.6.13
|
196
|
+
rubygems_version: 3.1.2
|
196
197
|
signing_key:
|
197
198
|
specification_version: 4
|
198
199
|
summary: Blocks gives you total control over how your blocks of code render.
|
data/docs/_includes/wip.md
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
<!-- Defining multiple blocks at once -->
|
2
|
-
## Multiple Blocks at Once
|
3
|
-
|
4
|
-
```haml
|
5
|
-
- namer = Proc.new {|i| "block #{i}" }
|
6
|
-
blocks.define_each ["a", 1, "b"],
|
7
|
-
namer do |item|
|
8
|
-
="Hello from #{item}"
|
9
|
-
&br
|
10
|
-
|
11
|
-
= blocks.render("block a")
|
12
|
-
= blocks.render("block 1")
|
13
|
-
= blocks.render("block b")
|
14
|
-
```
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
# where builder is an instance of
|
18
|
-
# Blocks::Builder
|
19
|
-
namer = Proc.new {|i| "block #{i}" }
|
20
|
-
builder.define_each ["a", 1, "b"],
|
21
|
-
namer do |item|
|
22
|
-
"Hello from #{item}<br>".html_safe
|
23
|
-
end
|
24
|
-
|
25
|
-
builder.render("block a") +
|
26
|
-
builder.render("block 1") +
|
27
|
-
builder.render("block b")
|
28
|
-
```
|
29
|
-
|
30
|
-
Multiple different blocks may be defined at once using the #define_each method.
|
31
|
-
|
32
|
-
#define_each expects at least two parameters: the collection and a proc that can be used to calculate the block name. The proc must at least one parameter, the first being the item in the collection.
|
33
|
-
|
34
|
-
The method also expects either an options hash designating the render strategy or a Ruby block.
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# WIP
|
2
|
-
module Blocks
|
3
|
-
module BuilderPermissions
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
METHODS_TO_PROTECT = [:render, :define, :deferred_render, :replace, :skip]
|
7
|
-
|
8
|
-
included do
|
9
|
-
attr_writer :permitted_blocks
|
10
|
-
attr_accessor :allow_all_blocks
|
11
|
-
attr_accessor :allow_anonymous_blocks
|
12
|
-
|
13
|
-
METHODS_TO_PROTECT.each do |method_name|
|
14
|
-
alias_method "original_#{method_name}", method_name
|
15
|
-
define_method(method_name) do |*args, &block|
|
16
|
-
if permitted?(args.first)
|
17
|
-
self.send("original_#{method_name}", *args, &block)
|
18
|
-
else
|
19
|
-
InvalidPermissionsHandler.build(method_name, args.first)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def restrict_blocks
|
26
|
-
self.allow_all_blocks = false
|
27
|
-
end
|
28
|
-
|
29
|
-
def permitted_blocks
|
30
|
-
@permitted_blocks ||= []
|
31
|
-
end
|
32
|
-
|
33
|
-
def permit(*names)
|
34
|
-
self.permitted_blocks += names
|
35
|
-
end
|
36
|
-
|
37
|
-
def permit_all
|
38
|
-
self.allow_all_blocks = true
|
39
|
-
end
|
40
|
-
|
41
|
-
def permit_anonymous_blocks
|
42
|
-
self.allow_anonymous_blocks = true
|
43
|
-
end
|
44
|
-
|
45
|
-
def permitted?(name)
|
46
|
-
allow_all_blocks ||
|
47
|
-
(block_definitions[name].try(:anonymous) && allow_anonymous_blocks) ||
|
48
|
-
!name.respond_to?(:to_sym) ||
|
49
|
-
permitted_blocks.any? {|e| e.to_sym == name.to_sym }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# WIP
|
2
|
-
module Blocks
|
3
|
-
class InvalidPermissionsHandler
|
4
|
-
LOG = :log
|
5
|
-
RAISE = :raise
|
6
|
-
|
7
|
-
def self.build(method_name, block_name)
|
8
|
-
message = "Cannot #{method_name} #{block_name}; #{block_name} is not in the permitted_blocks list"
|
9
|
-
new(message)
|
10
|
-
nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(message)
|
14
|
-
send("handle_#{Blocks.invalid_permissions_approach}", message)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def handle_log(message)
|
20
|
-
Rails.logger.info message
|
21
|
-
end
|
22
|
-
|
23
|
-
def handle_raise(message)
|
24
|
-
raise message
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Blocks
|
2
|
-
class AbstractRenderer
|
3
|
-
RENDERERS = [
|
4
|
-
AdjacentBlocksRenderer,
|
5
|
-
BlockRenderer,
|
6
|
-
BlockWithHooksRenderer,
|
7
|
-
CollectionRenderer,
|
8
|
-
PartialRenderer,
|
9
|
-
NestingBlocksRenderer,
|
10
|
-
WrapperRenderer
|
11
|
-
]
|
12
|
-
|
13
|
-
attr_accessor :main_renderer
|
14
|
-
|
15
|
-
delegate :builder, *(RENDERERS.map {|r| r.to_s.demodulize.underscore }), to: :main_renderer
|
16
|
-
delegate :block_definitions, :block_for, :view, to: :builder
|
17
|
-
delegate :with_output_buffer, :output_buffer, to: :view
|
18
|
-
|
19
|
-
def initialize(main_renderer=nil)
|
20
|
-
self.main_renderer = main_renderer
|
21
|
-
end
|
22
|
-
|
23
|
-
def render(*args)
|
24
|
-
raise NotImplementedError
|
25
|
-
end
|
26
|
-
|
27
|
-
def capture(*args, &block)
|
28
|
-
without_haml_interference do
|
29
|
-
if block.arity > 0
|
30
|
-
args = args[0, block.arity]
|
31
|
-
end
|
32
|
-
|
33
|
-
with_output_buffer do
|
34
|
-
output_buffer << view.capture(*args, &block)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
# Complete hack to get around issues with Haml
|
42
|
-
# Haml does some hacking to ActionView's with_output_buffer and
|
43
|
-
# output_buffer. In doing so, they make certain assumptions about
|
44
|
-
# the layout and the view template. The Blocks gem doesn't capture
|
45
|
-
# blocks immediately but rather stores them for later capturing.
|
46
|
-
# This can produce an issue if a block that is stored was in Haml
|
47
|
-
# but the Layout is in ERB. Haml will think that any blocks it
|
48
|
-
# captures while rendering the layout will be in ERB format. However,
|
49
|
-
# the block would need to be captured in Haml using a Haml buffer.
|
50
|
-
# This workaround accomplishes that.
|
51
|
-
def without_haml_interference(&block)
|
52
|
-
if defined?(::Haml) && view.instance_variables.include?(:@haml_buffer)
|
53
|
-
haml_buffer = view.instance_variable_get(:@haml_buffer)
|
54
|
-
if haml_buffer
|
55
|
-
was_active = haml_buffer.active?
|
56
|
-
haml_buffer.active = false
|
57
|
-
else
|
58
|
-
haml_buffer = Haml::Buffer.new(nil, Haml::Options.new.for_buffer)
|
59
|
-
haml_buffer.active = false
|
60
|
-
kill_buffer = true
|
61
|
-
view.instance_variable_set(:@haml_buffer, haml_buffer)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
yield
|
65
|
-
ensure
|
66
|
-
haml_buffer.active = was_active if haml_buffer
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module Blocks
|
2
|
-
module DynamicConfiguration
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
def add_config(*attrs)
|
7
|
-
options = attrs.extract_options!
|
8
|
-
instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
|
9
|
-
instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
|
10
|
-
instance_predicate = options.fetch(:instance_predicate, true)
|
11
|
-
default_value = options.fetch(:default, nil)
|
12
|
-
|
13
|
-
attrs.each do |name|
|
14
|
-
define_singleton_method(name) do |value="UNDEFINED"|
|
15
|
-
if value == "UNDEFINED"
|
16
|
-
default_value
|
17
|
-
else
|
18
|
-
public_send("#{name}=", value)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
|
22
|
-
|
23
|
-
ivar = "@#{name}"
|
24
|
-
|
25
|
-
define_singleton_method("#{name}=") do |val|
|
26
|
-
singleton_class.class_eval do
|
27
|
-
remove_possible_method(name)
|
28
|
-
define_method(name) do |value="UNDEFINED"|
|
29
|
-
if value == "UNDEFINED"
|
30
|
-
val
|
31
|
-
else
|
32
|
-
public_send("#{name}=", value)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class_eval do
|
38
|
-
remove_possible_method(name)
|
39
|
-
define_method(name) do
|
40
|
-
if instance_variable_defined? ivar
|
41
|
-
instance_variable_get ivar
|
42
|
-
else
|
43
|
-
singleton_class.send name
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
val
|
48
|
-
end
|
49
|
-
|
50
|
-
if instance_reader
|
51
|
-
remove_possible_method name
|
52
|
-
define_method(name) do
|
53
|
-
if instance_variable_defined?(ivar)
|
54
|
-
instance_variable_get ivar
|
55
|
-
else
|
56
|
-
self.class.public_send name
|
57
|
-
end
|
58
|
-
end
|
59
|
-
define_method("#{name}?") { !!public_send(name) } if instance_predicate
|
60
|
-
end
|
61
|
-
|
62
|
-
attr_writer name if instance_writer
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def configure
|
67
|
-
yield self
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|