jap_mag 1.3.5 → 1.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a65ff965780098ac76734497dee642f07790f98115a9d84e2dfb29b1960b6a5
4
- data.tar.gz: 202a22e1358394c15bfc8e64f19ea6f655466adf01f1ed6385af892eec328a2e
3
+ metadata.gz: f935d63a9bee80b8fb48337976b552478f1ba382c95e825a544880b1b38d9b29
4
+ data.tar.gz: 5605139d72747e7a967d4e75bf98355f3d47952c9492b739f34e1218e6183dbc
5
5
  SHA512:
6
- metadata.gz: f4c962c085d78a3837788b98ef79dca79cffe5cc671de5dfbe6176b30bde0fe84faff6454dfd5935497f41196bcf3690fc42f0eb5336664be4366606b6d676f3
7
- data.tar.gz: 856b253088bd36722764e0080d49a25b4896e0a8342c25e809d302dbb92671288d8d1b22822a961d07366f3b3396bbbf33c8dadf2ff1726ed561a40d475902bc
6
+ metadata.gz: e5bafdff72acdb6d593a1633cd18314d6bb54f6433c87566c974c1289d70a345d5b601aebb9adeda136d2f799d3bf0ebe1f644847e41c2691a10f53c48b5f504
7
+ data.tar.gz: 0c308548e44afa4a64347d2014fb06c9b7cf4b71af31d42b5ffd3aa31c7630e7794c792f79b346a10b0947f874b69dd7d04845b37e72f48313d00348a1916c7f
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jap_mag (1.4.1)
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
 
@@ -190,6 +190,20 @@ module JapMagWidgetsHelper
190
190
  image_tag name_at_1x, options
191
191
  end
192
192
 
193
+ def section_t key, opts = {}
194
+ I18n.t "#{params[:controller]}.#{params[:action]}.sections.#{key}", **opts
195
+ end
196
+
197
+ def render_sections *args, **opts
198
+ opts = {locals: {}}.merge(opts)
199
+
200
+ args.collect do |section|
201
+ tpl = "#{params[:controller].gsub('#', '/')}/#{params[:action]}/#{section}"
202
+
203
+ render partial: tpl, locals: opts[:locals]
204
+ end.join.html_safe
205
+ end
206
+
193
207
  protected
194
208
 
195
209
  def current_template
@@ -0,0 +1,9 @@
1
+ version: "3.8"
2
+
3
+ services:
4
+ ruby:
5
+ image: 'ruby:3.1.2-alpine'
6
+ working_dir: /app/
7
+ volumes:
8
+ - .:/app:cached
9
+ command: sh -c "bundle && bundle exec rspec"
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
@@ -1,3 +1,3 @@
1
1
  module JapMag
2
- VERSION = "1.3.5"
2
+ VERSION = "1.4.2"
3
3
  end
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
- controller = params[:controller]
47
- action = params[:action]
48
- #raise args.inspect if args != 'homepage/page#index'
49
-
50
- args = args.first if args.size == 1 && args.first.is_a?(Array)
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
@@ -0,0 +1,4 @@
1
+ module JapMag
2
+ def self.included base
3
+ end
4
+ end
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
@@ -0,0 +1,9 @@
1
+ class RailsApp
2
+ include JapMag
3
+
4
+ attr :params, true
5
+
6
+ def initialize params
7
+ @params = params
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ class Rails
2
+ class Engine
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ RSpec.configure do |config|
5
+ end
6
+
7
+ require 'rails_engine'
8
+ require_relative '../lib/jap_mag'
9
+ require_relative 'jap_mag'
10
+ require 'rails_app'
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.3.5
4
+ version: 1.4.2
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-07 00:00:00.000000000 Z
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
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .DS_Store