nice_partials 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3275a33c9f1de9e8267042ab36b485297451804bb1c704082576890d800a20cd
4
- data.tar.gz: 7b55dd85d2d291eb411b564819c602e039dc412ec8cbb82df7b58f8472d062e4
3
+ metadata.gz: d42a736129588d106251452b5d8357a54b610105302f7fddd25d4658211f6b1b
4
+ data.tar.gz: 66788e79de27fbddefaaef582dc4768bb3bd9a4e50eb43dd306c5c39919dac08
5
5
  SHA512:
6
- metadata.gz: ef49218a25d20bb8b0446b5b0dd975fb173191ea1e236e9dfa6a700fec717ef9b24f8f06fcc114b4e1e731ddf62aed143cd225193cd6ebc64acb4fd06edb0e3b
7
- data.tar.gz: 52e0f030102269996e35132ad2ff16bcb94100faca76787b13059a31450c0d65456961b71bf69d2610f46bb8f48a9b410f4a01090c96f946d2d5b1ec6ece9b8c
6
+ metadata.gz: 0dfd842004c659c711e34675fd57a555e75dba71dd73990f73b1b8a37071c93e0ac8441b4248100b0faf6d930a70216e5d927b5aa9692ee13be9ffc6fc3507ff
7
+ data.tar.gz: 65c451b1ddca8dab4bc9d523e6d9f14095c33cfe59df34f321b724445c60ab68e4aab23c26fd153929d48d5dfdad351cc230a0a0cb7970de32410e078e380bfd
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  /pkg
3
+ *~
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} | Spec"
34
- task :spec do
35
- sh "for file in spec/*_spec.rb; do ruby $file; done"
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: :spec
37
+ task default: :test
@@ -20,6 +20,6 @@ module NicePartials::Helper
20
20
  key = "#{@_nice_partials_t_prefixes.last}#{key}"
21
21
  end
22
22
 
23
- super(key, options)
23
+ super(key, **options)
24
24
  end
25
25
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NicePartials
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/nice_partials.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require_relative "nice_partials/version"
4
4
  require_relative "nice_partials/helper"
5
5
  require_relative "nice_partials/monkey_patch"
6
- require_relative "partials"
7
6
 
8
7
  module NicePartials
9
8
  end
@@ -20,4 +20,6 @@ Gem::Specification.new do |gem|
20
20
  gem.required_ruby_version = ">= 2.0"
21
21
 
22
22
  gem.add_dependency "actionview", '>= 4.2.6'
23
+
24
+ gem.add_development_dependency "rails"
23
25
  end
@@ -0,0 +1,2 @@
1
+ <% yield p = np %>
2
+ <%= p.yield :message %>
@@ -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,9 @@
1
+ <%= render "card", title: "Some Title" do |p| %>
2
+ <% p.content_for :body do %>
3
+ Lorem Ipsum
4
+ <% end %>
5
+
6
+ <% p.content_for :image do %>
7
+ <img src="https://example.com/image.jpg" />
8
+ <% end %>
9
+ <% end %>
@@ -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
@@ -0,0 +1,7 @@
1
+ require "active_support"
2
+ require "active_support/testing/autorun"
3
+ require "action_controller"
4
+ require "action_view"
5
+ require "nice_partials"
6
+
7
+ FIXTURE_LOAD_PATH = File.expand_path("fixtures", __dir__)
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
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-10-05 00:00:00.000000000 Z
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
- - spec/nice_partials_spec.rb
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.1.4
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
- - spec/nice_partials_spec.rb
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
@@ -1,2 +0,0 @@
1
- module Partials
2
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/nice_partials"
4
- require "minitest/autorun"
5
-
6
- describe NicePartials do
7
- it "works" do
8
- assert_equal true, false
9
- end
10
- end
11
-