jap_mag 1.4.0 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -0
- data/README.md +2 -2
- data/app/helpers/jap_mag_widgets_helper.rb +1 -1
- data/docker-compose.yml +9 -0
- data/jap_mag.gemspec +3 -1
- data/lib/jap_mag/version.rb +1 -1
- data/lib/jap_mag.rb +11 -8
- data/spec/jap_mag.rb +4 -0
- data/spec/lib_spec.rb +85 -0
- data/spec/rails_app.rb +9 -0
- data/spec/rails_engine.rb +4 -0
- data/spec/spec_helper.rb +10 -0
- metadata +29 -4
- data/.gitignore +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7daaa3350ef3ac573901e3a17449442385db09a92fe853bcddd6fbb5e0a957f
|
4
|
+
data.tar.gz: 1b99b84a47affc024cc5861d8f8f59907578b8c9bedbf253bc9cec701227a1f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '01654418aba5ce14c4f835e8930e07ffb388d5556aa0ac8fabcf1472b9f24ab5e83faedec8df450d5322db01668182a7f91d05c313628729bb1a547e861dad77'
|
7
|
+
data.tar.gz: 0eb99fd441a1ea76f07b261a99108b822c6f7808417b91a97b5aaea08cd50cc023bd97eaf37dbce75f29085c91a3365e5d8fb97022df65e943b27e9b3b4dc28b
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jap_mag (1.4.2)
|
5
|
+
will_paginate
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
rspec (3.11.0)
|
12
|
+
rspec-core (~> 3.11.0)
|
13
|
+
rspec-expectations (~> 3.11.0)
|
14
|
+
rspec-mocks (~> 3.11.0)
|
15
|
+
rspec-core (3.11.0)
|
16
|
+
rspec-support (~> 3.11.0)
|
17
|
+
rspec-expectations (3.11.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.11.0)
|
20
|
+
rspec-mocks (3.11.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.11.0)
|
23
|
+
rspec-support (3.11.0)
|
24
|
+
will_paginate (3.3.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
aarch64-linux-musl
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
jap_mag!
|
31
|
+
rspec
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.3.7
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
JapMag is a collection of frequently-used Rails controller methods, helpers, Javascript functions and SASS mixins. It helps quickly bootstrap a Rails app.
|
4
4
|
|
5
|
-
For example, [current_controller_action_in?](https://github.com/felixding/JapMag/blob/master/lib/jap_mag.rb#L38) is a helper that checks if current request.controller and request.action match with a set of given rules. You can then for example show or hide certain things on your app depending if it matches or not.
|
5
|
+
For example, [current_controller_action_in?](https://github.com/felixding/JapMag/blob/master/lib/jap_mag.rb#L38) is a helper that checks if current request.controller and request.action match with a set of given rules. You can then for example show or hide certain things on your app depending if it matches or not.
|
6
6
|
|
7
7
|
Another example is [retina_image_tag](https://github.com/felixding/JapMag/blob/master/app/helpers/jap_mag_widgets_helper.rb#L164) which can easily generate HTML `img` tags for Retina/Non-retina screens. It also helps you deal with localized images.
|
8
8
|
|
@@ -10,7 +10,7 @@ This project was first created in 2012.
|
|
10
10
|
|
11
11
|
## Installation & Usage
|
12
12
|
|
13
|
-
Please note JapMag only supports Rails 3+.
|
13
|
+
Please note JapMag only supports Rails 3+. And starting from v1.4.0, Ruby 3.0+ is required.
|
14
14
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
@@ -191,7 +191,7 @@ module JapMagWidgetsHelper
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def section_t key, opts = {}
|
194
|
-
I18n.t "#{params[:controller]}.#{params[:action]}.sections.#{key}", opts
|
194
|
+
I18n.t "#{params[:controller]}.#{params[:action]}.sections.#{key}", **opts
|
195
195
|
end
|
196
196
|
|
197
197
|
def render_sections *args, **opts
|
data/docker-compose.yml
ADDED
data/jap_mag.gemspec
CHANGED
@@ -8,7 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = "jap_mag-#{gem.version}"
|
9
9
|
gem.homepage = "https://github.com/felixding/JapMag"
|
10
10
|
|
11
|
-
gem.files = `git ls-files`.split($\)
|
11
|
+
#gem.files = `git ls-files`.split($\)
|
12
|
+
gem.files = Dir['**/*'].keep_if { |file| File.file?(file) }
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
14
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
15
|
gem.name = "jap_mag"
|
@@ -16,4 +17,5 @@ Gem::Specification.new do |gem|
|
|
16
17
|
gem.version = JapMag::VERSION
|
17
18
|
|
18
19
|
gem.add_runtime_dependency :will_paginate
|
20
|
+
gem.add_development_dependency "rspec"
|
19
21
|
end
|
data/lib/jap_mag/version.rb
CHANGED
data/lib/jap_mag.rb
CHANGED
@@ -38,23 +38,26 @@ module JapMag
|
|
38
38
|
#
|
39
39
|
# the args can be one of the following:
|
40
40
|
#
|
41
|
-
# String: "page#index"
|
41
|
+
# String: "page#index page#intro"
|
42
42
|
# Array: %w(page#index page#intro)
|
43
43
|
# multiple arguments: "page#index", "page#intro"
|
44
44
|
#
|
45
45
|
def current_controller_action_in?(*args)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
if args.size == 1
|
47
|
+
case args.first.class.to_s
|
48
|
+
when 'Array'
|
49
|
+
args = args.first
|
50
|
+
when 'String'
|
51
|
+
args = args.first.split(' ')
|
52
|
+
end
|
53
|
+
end
|
51
54
|
|
52
55
|
args.each do |element|
|
53
56
|
if element.to_s.include?("#")
|
54
57
|
c, a = element.split('#')
|
55
|
-
return true if controller == c && action == a
|
58
|
+
return true if params[:controller] == c && params[:action] == a
|
56
59
|
else
|
57
|
-
return true if controller == element
|
60
|
+
return true if params[:controller] == element
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
data/spec/jap_mag.rb
ADDED
data/spec/lib_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe JapMag do
|
4
|
+
#let(:rails_app) { Class.new { include JapMag } }
|
5
|
+
|
6
|
+
describe 'current_controller_action_in?' do
|
7
|
+
let(:rails_app) { RailsApp.new(controller: 'page', action: 'index') }
|
8
|
+
|
9
|
+
context 'string' do
|
10
|
+
it 'returns true when controller matches' do
|
11
|
+
s = 'page'
|
12
|
+
|
13
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns true when more than one controlers matches' do
|
17
|
+
s = 'page users'
|
18
|
+
|
19
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns true when controller#action matches' do
|
23
|
+
s = 'page#index'
|
24
|
+
|
25
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns true when more than one controler#action matches' do
|
29
|
+
s = 'page#index users#new users#create'
|
30
|
+
|
31
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns true when it is a mix of controller and controler#action' do
|
35
|
+
s = 'page users users#new users#create'
|
36
|
+
|
37
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns false when controller doesnot match' do
|
41
|
+
s = 'page1'
|
42
|
+
|
43
|
+
expect(rails_app.current_controller_action_in?(s)).to be(false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'splat' do
|
48
|
+
it 'returns true when controller matches' do
|
49
|
+
s = *%w(page)
|
50
|
+
|
51
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns true when more than one controlers matches' do
|
55
|
+
s = *%w(page users)
|
56
|
+
|
57
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns true when controller#action matches' do
|
61
|
+
s = *%w(page#index)
|
62
|
+
|
63
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns true when more than one controler#action matches' do
|
67
|
+
s = *%w(page#index users#new users#create)
|
68
|
+
|
69
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns true when it is a mix of controller and controler#action' do
|
73
|
+
s = *%w(page users users#new users#create)
|
74
|
+
|
75
|
+
expect(rails_app.current_controller_action_in?(s)).to be(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns false when controller doesnot match' do
|
79
|
+
s = *%w(page1)
|
80
|
+
|
81
|
+
expect(rails_app.current_controller_action_in?(s)).to be(false)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/spec/rails_app.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jap_mag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DING Yu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: will_paginate
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: JapMag is a collection of frequently-used Rails controller methods and
|
28
42
|
helpers.
|
29
43
|
email:
|
@@ -32,8 +46,8 @@ executables: []
|
|
32
46
|
extensions: []
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
35
|
-
- ".gitignore"
|
36
49
|
- Gemfile
|
50
|
+
- Gemfile.lock
|
37
51
|
- README.md
|
38
52
|
- Rakefile
|
39
53
|
- app/assets/javascripts/jap_mag.js
|
@@ -51,9 +65,15 @@ files:
|
|
51
65
|
- app/views/layouts/_tracking.erb
|
52
66
|
- app/views/layouts/application.haml
|
53
67
|
- config/locales/en.yml
|
68
|
+
- docker-compose.yml
|
54
69
|
- jap_mag.gemspec
|
55
70
|
- lib/jap_mag.rb
|
56
71
|
- lib/jap_mag/version.rb
|
72
|
+
- spec/jap_mag.rb
|
73
|
+
- spec/lib_spec.rb
|
74
|
+
- spec/rails_app.rb
|
75
|
+
- spec/rails_engine.rb
|
76
|
+
- spec/spec_helper.rb
|
57
77
|
homepage: https://github.com/felixding/JapMag
|
58
78
|
licenses: []
|
59
79
|
metadata: {}
|
@@ -76,4 +96,9 @@ rubygems_version: 3.3.5
|
|
76
96
|
signing_key:
|
77
97
|
specification_version: 4
|
78
98
|
summary: jap_mag-
|
79
|
-
test_files:
|
99
|
+
test_files:
|
100
|
+
- spec/jap_mag.rb
|
101
|
+
- spec/lib_spec.rb
|
102
|
+
- spec/rails_app.rb
|
103
|
+
- spec/rails_engine.rb
|
104
|
+
- spec/spec_helper.rb
|