nice_partials 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +8 -0
- data/Rakefile +4 -4
- data/lib/nice_partials/helper.rb +1 -1
- data/lib/nice_partials/monkey_patch.rb +29 -0
- data/lib/nice_partials/version.rb +1 -1
- data/lib/nice_partials.rb +0 -1
- data/nice_partials.gemspec +2 -0
- data/test/fixtures/_basic.html.erb +2 -0
- data/test/fixtures/_card.html.erb +13 -0
- data/test/fixtures/card_test.html.erb +9 -0
- data/test/renderer_test.rb +57 -0
- data/test/test_helper.rb +7 -0
- metadata +30 -9
- data/lib/partials.rb +0 -2
- data/spec/nice_partials_spec.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d42a736129588d106251452b5d8357a54b610105302f7fddd25d4658211f6b1b
|
4
|
+
data.tar.gz: 66788e79de27fbddefaaef582dc4768bb3bd9a4e50eb43dd306c5c39919dac08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dfd842004c659c711e34675fd57a555e75dba71dd73990f73b1b8a37071c93e0ac8441b4248100b0faf6d930a70216e5d927b5aa9692ee13be9ffc6fc3507ff
|
7
|
+
data.tar.gz: 65c451b1ddca8dab4bc9d523e6d9f14095c33cfe59df34f321b724445c60ab68e4aab23c26fd153929d48d5dfdad351cc230a0a0cb7970de32410e078e380bfd
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -150,6 +150,14 @@ Then later in the partial you can use the helper method like so:
|
|
150
150
|
<td><%= p.reference_to(user) %></td>
|
151
151
|
```
|
152
152
|
|
153
|
+
## Development
|
154
|
+
|
155
|
+
### Testing
|
156
|
+
|
157
|
+
```sh
|
158
|
+
bundle exec rake test
|
159
|
+
```
|
160
|
+
|
153
161
|
## MIT License
|
154
162
|
|
155
163
|
Copyright (C) 2020 Andrew Culver <https://bullettrain.co> and Dom Christie <https://domchristie.co.uk>. Released under the MIT license.
|
data/Rakefile
CHANGED
@@ -30,8 +30,8 @@ end
|
|
30
30
|
# # #
|
31
31
|
# Run specs
|
32
32
|
|
33
|
-
desc "#{gemspec.name} |
|
34
|
-
task :
|
35
|
-
sh "for file in
|
33
|
+
desc "#{gemspec.name} | Test"
|
34
|
+
task :test do
|
35
|
+
sh "for file in test/*_test.rb; do ruby $file; done"
|
36
36
|
end
|
37
|
-
task default: :
|
37
|
+
task default: :test
|
data/lib/nice_partials/helper.rb
CHANGED
@@ -20,4 +20,33 @@ class ActionView::PartialRenderer
|
|
20
20
|
|
21
21
|
return result
|
22
22
|
end
|
23
|
+
|
24
|
+
# This and ActionView::Template#render below are for compatibility
|
25
|
+
# with Ruby 3, as opposed to altering the original functionality.
|
26
|
+
def render_partial_template(view, locals, template, layout, block)
|
27
|
+
ActiveSupport::Notifications.instrument(
|
28
|
+
"render_partial.action_view",
|
29
|
+
identifier: template.identifier,
|
30
|
+
layout: layout && layout.virtual_path
|
31
|
+
) do |payload|
|
32
|
+
content = template.render(view, locals, ActionView::OutputBuffer.new, {add_to_stack: !block}) do |*name|
|
33
|
+
view._layout_for(*name, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
content = layout.render(view, locals) { content } if layout
|
37
|
+
payload[:cache_hit] = view.view_renderer.cache_hits[template.virtual_path]
|
38
|
+
build_rendered_template(content, template)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ActionView::Template
|
44
|
+
def render(view, locals, buffer = ActionView::OutputBuffer.new, flag = {add_to_stack: true}, &block)
|
45
|
+
instrument_render_template do
|
46
|
+
compile!(view)
|
47
|
+
view._run(method_name, self, locals, buffer, **flag, &block)
|
48
|
+
end
|
49
|
+
rescue => e
|
50
|
+
handle_render_error(view, e)
|
51
|
+
end
|
23
52
|
end
|
data/lib/nice_partials.rb
CHANGED
data/nice_partials.gemspec
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
<% yield p = np %>
|
2
|
+
|
3
|
+
<div class="card">
|
4
|
+
<%= p.yield :image %>
|
5
|
+
<div class="card-body">
|
6
|
+
<h5 class="card-title"><%= title %></h5>
|
7
|
+
<% if p.content_for? :body %>
|
8
|
+
<p class="card-text">
|
9
|
+
<%= p.content_for :body %>
|
10
|
+
</p>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
</div>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative "./test_helper"
|
2
|
+
|
3
|
+
class RendererTest < ActiveSupport::TestCase
|
4
|
+
# from actionview/render_test
|
5
|
+
class TestController < ActionController::Base
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup_view(paths)
|
9
|
+
ActionView::Base.include(NicePartials::Helper)
|
10
|
+
|
11
|
+
@assigns = { secret: "in the sauce" }
|
12
|
+
|
13
|
+
@view = Class.new(ActionView::Base.with_empty_template_cache) do
|
14
|
+
def view_cache_dependencies; []; end
|
15
|
+
|
16
|
+
def combined_fragment_cache_key(key)
|
17
|
+
[:views, key]
|
18
|
+
end
|
19
|
+
end.with_view_paths(paths, @assigns)
|
20
|
+
|
21
|
+
controller = TestController.new
|
22
|
+
controller.perform_caching = true
|
23
|
+
controller.cache_store = :memory_store
|
24
|
+
@view.controller = controller
|
25
|
+
|
26
|
+
@controller_view = controller.view_context_class.with_empty_template_cache.new(
|
27
|
+
controller.lookup_context,
|
28
|
+
controller.view_assigns,
|
29
|
+
controller)
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
ActionView::LookupContext::DetailsKey.clear
|
34
|
+
path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
|
35
|
+
view_paths = ActionView::PathSet.new([path])
|
36
|
+
assert_equal ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH), view_paths.first
|
37
|
+
setup_view(view_paths)
|
38
|
+
end
|
39
|
+
|
40
|
+
def teardown
|
41
|
+
ActionController::Base.view_paths.map(&:clear_cache)
|
42
|
+
end
|
43
|
+
|
44
|
+
test "render basic nice partial" do
|
45
|
+
rendered = @view.render("basic") { |p| p.content_for :message, "hello from nice partials" }.squish
|
46
|
+
|
47
|
+
assert_equal "hello from nice partials", rendered
|
48
|
+
end
|
49
|
+
|
50
|
+
test "render nice partial in card template" do
|
51
|
+
rendered = @view.render(template: "card_test").squish
|
52
|
+
|
53
|
+
assert_match "Some Title", rendered
|
54
|
+
assert_match "Lorem Ipsum", rendered
|
55
|
+
assert_match "https://example.com/image.jpg", rendered
|
56
|
+
end
|
57
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nice_partials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
- Dom Christie
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionview
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 4.2.6
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
description: A little bit of magic to make partials perfect for components.
|
29
43
|
email:
|
30
44
|
- andrew.culver@gmail.com
|
@@ -46,14 +60,17 @@ files:
|
|
46
60
|
- lib/nice_partials/monkey_patch.rb
|
47
61
|
- lib/nice_partials/partial.rb
|
48
62
|
- lib/nice_partials/version.rb
|
49
|
-
- lib/partials.rb
|
50
63
|
- nice_partials.gemspec
|
51
|
-
-
|
64
|
+
- test/fixtures/_basic.html.erb
|
65
|
+
- test/fixtures/_card.html.erb
|
66
|
+
- test/fixtures/card_test.html.erb
|
67
|
+
- test/renderer_test.rb
|
68
|
+
- test/test_helper.rb
|
52
69
|
homepage: https://github.com/bullet-train-co/nice_partials
|
53
70
|
licenses:
|
54
71
|
- MIT
|
55
72
|
metadata: {}
|
56
|
-
post_install_message:
|
73
|
+
post_install_message:
|
57
74
|
rdoc_options: []
|
58
75
|
require_paths:
|
59
76
|
- lib
|
@@ -68,9 +85,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
85
|
- !ruby/object:Gem::Version
|
69
86
|
version: '0'
|
70
87
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
88
|
+
rubygems_version: 3.0.3
|
89
|
+
signing_key:
|
73
90
|
specification_version: 4
|
74
91
|
summary: A little bit of magic to make partials perfect for components.
|
75
92
|
test_files:
|
76
|
-
-
|
93
|
+
- test/fixtures/_basic.html.erb
|
94
|
+
- test/fixtures/_card.html.erb
|
95
|
+
- test/fixtures/card_test.html.erb
|
96
|
+
- test/renderer_test.rb
|
97
|
+
- test/test_helper.rb
|
data/lib/partials.rb
DELETED