content_pack_rails 0.1.0 → 1.0.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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +34 -0
- data/CHANGELOG.md +25 -0
- data/README.md +14 -5
- data/content_pack_rails.gemspec +7 -3
- data/lib/content_pack_rails/version.rb +1 -1
- data/lib/content_pack_rails.rb +10 -5
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a26d8a1b263627df989ef8d8d97f33b489c8322c92eb503c158b9b2b7cad37b
|
4
|
+
data.tar.gz: f721a69bbed4ed7d6d2c98bf1a3ac10394f4efa8a9946528b3c1193927676d04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe733e4d00555d3963a70c7d310063e21feebd17c4392fa1c8930bed30043c12192d17809c0d2906781ed8ab924442835de8a77aa253bb3ff55f5b7296719d90
|
7
|
+
data.tar.gz: 65b7a42f9b7b3bfa5dcf459d9cc52ba02b08793297dae4a7cedb2a7e9aaae74643e0aa178b2750849f2737bfc5ec76f15c2b9e2f88843dccae48dbf7105ec243
|
@@ -0,0 +1,34 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
ruby: ['2.7', '3.0']
|
15
|
+
rails: ['6.1', '7.0']
|
16
|
+
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
|
23
|
+
- name: Set up Ruby
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
27
|
+
|
28
|
+
- name: Install gems and run tests
|
29
|
+
env:
|
30
|
+
TEST_RAILS_VERSION: ${{ matrix.rails }}
|
31
|
+
run: |
|
32
|
+
gem install bundler
|
33
|
+
bundle install --jobs 4 --retry 3
|
34
|
+
bundle exec rake
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.0.0 (2022-02-14)
|
4
|
+
|
5
|
+
### Bug Fixes
|
6
|
+
|
7
|
+
* github workflow - tests with ruby versions 2.7, 3.0, and rails versions 6.1, 7.0
|
8
|
+
|
9
|
+
## 0.2.2 (2021-12-08)
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* prevent provide_content_pack from crash when no content collected
|
14
|
+
|
15
|
+
## 0.2.1 (2021-12-08)
|
16
|
+
|
17
|
+
### Bug Fixes
|
18
|
+
|
19
|
+
* make sure getter helpers return instance of ActiveSupport::SafeBuffer
|
20
|
+
|
21
|
+
## 0.2.0 (2021-12-03)
|
22
|
+
|
23
|
+
### Features
|
24
|
+
|
25
|
+
* ability to get content entry from pack
|
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# ContentPackRails
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/content_pack_rails)
|
4
|
+
[](https://github.com/a-bohush/content_pack_rails/actions/workflows/tests.yml)
|
5
|
+
|
2
6
|
A thin wrapper around [`ActionView::Helpers::CaptureHelper#content_for`](https://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-content_for).
|
3
7
|
Useful when you need to collect multiple content entries during page rendering, for example <script type="text/template"> templates, without woring about possible duplications and name clashes.
|
4
8
|
|
@@ -23,7 +27,7 @@ module ApplicationHelper
|
|
23
27
|
end
|
24
28
|
```
|
25
29
|
|
26
|
-
By default, this will add
|
30
|
+
By default, this will add three view helpers `content_pack`, `provide_content_pack` and `content_pack_get`.
|
27
31
|
To avoid collisions with a helper of the same name you might already have in your app, provide a different name:
|
28
32
|
|
29
33
|
```ruby
|
@@ -33,7 +37,7 @@ module ApplicationHelper
|
|
33
37
|
end
|
34
38
|
```
|
35
39
|
|
36
|
-
Helper `content_pack` declares the same parameters as
|
40
|
+
Helper `content_pack` declares the same parameters as the standard rails `content_for` and can be used similarly to capture content like this:
|
37
41
|
|
38
42
|
```erb
|
39
43
|
<% content_pack 'content-id' do |id| %>
|
@@ -45,14 +49,14 @@ Helper `content_pack` declares the same parameters as a standard rails `content_
|
|
45
49
|
-->
|
46
50
|
<% end %>
|
47
51
|
```
|
48
|
-
or pass content as
|
52
|
+
or pass content as the second argument:
|
49
53
|
```erb
|
50
54
|
<% content_pack 'content-id', 'Your content' %>
|
51
55
|
```
|
52
56
|
|
53
57
|
Unlike `content_for`, by default, `content_pack` will not concatenate content with the same name.
|
54
58
|
Multiple calls to `content_pack` with the same content name will result in only the first content being added to the pack.
|
55
|
-
If you would like to add additional content on a given name, you should pass
|
59
|
+
If you would like to add additional content on a given name, you should pass the `append: true` option like so:
|
56
60
|
|
57
61
|
```erb
|
58
62
|
<% content_pack 'content-id', 'first content' %>
|
@@ -60,7 +64,7 @@ If you would like to add additional content on a given name, you should pass an
|
|
60
64
|
<% content_pack 'content-id', 'second content', append: true %>
|
61
65
|
```
|
62
66
|
|
63
|
-
In case you want to override content on a given name, provide
|
67
|
+
In case you want to override content on a given name, provide the `flush: true` option:
|
64
68
|
```erb
|
65
69
|
<% content_pack 'content-id', 'first content' %>
|
66
70
|
<!-- following will override the first one -->
|
@@ -73,6 +77,11 @@ So later on, you can render the whole pack somewhere in your view, like this:
|
|
73
77
|
<%= provide_content_pack %>
|
74
78
|
```
|
75
79
|
|
80
|
+
To access a single content entry from the pack, use `content_pack_get`:
|
81
|
+
```erb
|
82
|
+
<%= content_pack_get('content-id') %>
|
83
|
+
```
|
84
|
+
|
76
85
|
Should you want to have multiple packs, for example, to group content, you can set up those by including this module as many times as needed with different names:
|
77
86
|
```ruby
|
78
87
|
module ApplicationHelper
|
data/content_pack_rails.gemspec
CHANGED
@@ -10,14 +10,18 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.license = "MIT"
|
11
11
|
|
12
12
|
spec.metadata["source_code_uri"] = spec.homepage
|
13
|
-
|
14
|
-
|
13
|
+
spec.metadata["changelog_uri"] = "https://github.com/a-bohush/content_pack_rails/blob/main/CHANGELOG.md"
|
14
|
+
spec.extra_rdoc_files = ['README.md']
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
16
16
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
17
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
if ENV['TEST_RAILS_VERSION'].nil?
|
22
|
+
spec.add_development_dependency "rails", "~> 6.1.4", ">= 6.1.4.1"
|
23
|
+
else
|
24
|
+
spec.add_development_dependency "rails", ENV['TEST_RAILS_VERSION'].to_s
|
25
|
+
end
|
22
26
|
spec.add_development_dependency "pry-byebug"
|
23
27
|
end
|
data/lib/content_pack_rails.rb
CHANGED
@@ -4,9 +4,10 @@ module ContentPackRails
|
|
4
4
|
def self.init(configs = { pack_name: 'content_pack' })
|
5
5
|
Module.new do
|
6
6
|
silent = proc { |&block| v = $VERBOSE; $VERBOSE = nil; res = block.call; $VERBOSE = v; res }
|
7
|
+
to_content_id = -> (id) { "_id_#{configs[:pack_name]}_#{id}".to_sym }
|
7
8
|
|
8
9
|
define_method configs[:pack_name] do |id, content=nil, options={}, &block|
|
9
|
-
_id =
|
10
|
+
_id = to_content_id.call(id)
|
10
11
|
_block = proc { block.call(id) } if block
|
11
12
|
options[:append] || options[:flush] || content_for?(_id) && return
|
12
13
|
content_for(_id, content, options.slice(:flush), &_block)
|
@@ -15,11 +16,15 @@ module ContentPackRails
|
|
15
16
|
end
|
16
17
|
|
17
18
|
define_method "provide_#{configs[:pack_name]}" do
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
return unless (ids = silent.call { instance_variable_get(:"@_#{configs[:pack_name]}_ids") })
|
20
|
+
ids.inject(nil) do |acc, id|
|
21
|
+
return acc unless (content = content_for(id))
|
22
|
+
acc ? acc.safe_concat(content) : content
|
21
23
|
end
|
22
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method "#{configs[:pack_name]}_get" do |id|
|
27
|
+
content_for(to_content_id.call(id))
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: content_pack_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bohush
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -49,9 +49,12 @@ email:
|
|
49
49
|
- a.bohush01@gmail.com
|
50
50
|
executables: []
|
51
51
|
extensions: []
|
52
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
53
|
+
- README.md
|
53
54
|
files:
|
55
|
+
- ".github/workflows/tests.yml"
|
54
56
|
- ".gitignore"
|
57
|
+
- CHANGELOG.md
|
55
58
|
- Gemfile
|
56
59
|
- MIT-LICENSE
|
57
60
|
- README.md
|
@@ -64,6 +67,7 @@ licenses:
|
|
64
67
|
- MIT
|
65
68
|
metadata:
|
66
69
|
source_code_uri: https://github.com/a-bohush/content_pack_rails.git
|
70
|
+
changelog_uri: https://github.com/a-bohush/content_pack_rails/blob/main/CHANGELOG.md
|
67
71
|
post_install_message:
|
68
72
|
rdoc_options: []
|
69
73
|
require_paths:
|