jap_mag 0.0.5 → 1.3.1
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 +5 -5
- data/README.md +8 -10
- data/app/helpers/jap_mag_widgets_helper.rb +43 -23
- data/jap_mag.gemspec +4 -2
- data/lib/jap_mag.rb +25 -0
- data/lib/jap_mag/version.rb +1 -1
- metadata +24 -11
- data/LICENSE +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e12032e8112941ff8369025bf1756381d5a5b22a76e21292563929ec89782596
|
|
4
|
+
data.tar.gz: e43f8d23973ccb798833fa483cec7f836a64409583ebde40946492e16985519c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6279e898283afdc86c595b23f9cb460fd4060bee96a7c2c0e7c4b597794660bb602c7cf6e734a07daaf525d69456dd04395afcfdc9adf784aa8455390d5ae4bd
|
|
7
|
+
data.tar.gz: '01790e45450d4eab622000f333619716bcc2e5fc1cc3c4538d39ca9745032b2d599af2ad5178793e6260c57235282965fb2e5d04ec5d6585d8585f5488fb63cb'
|
data/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Introduction
|
|
2
2
|
|
|
3
|
-
JapMag is
|
|
3
|
+
JapMag is a collection of frequently-used Rails controller methods and helpers.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
5
|
+
## Installation & Usage
|
|
8
6
|
|
|
9
7
|
Please note JapMag only supports Rails 3+.
|
|
10
8
|
|
|
@@ -29,14 +27,10 @@ In your Javascript manifest (application.js in default):
|
|
|
29
27
|
In your app/controllers/application_controll.rb, add
|
|
30
28
|
|
|
31
29
|
include JapMag
|
|
32
|
-
|
|
30
|
+
|
|
33
31
|
For a new Rails app, delete app/views/layout/application.html.erb.
|
|
34
32
|
|
|
35
33
|
Done! Now start your Rails app and you will see a JapMag-powered website!
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
Documentation is on the way. Stay tuned!
|
|
40
34
|
|
|
41
35
|
## Contributing
|
|
42
36
|
|
|
@@ -45,3 +39,7 @@ Documentation is on the way. Stay tuned!
|
|
|
45
39
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
46
40
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
47
41
|
5. Create new Pull Request
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Code released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -23,7 +23,7 @@ module JapMagWidgetsHelper
|
|
|
23
23
|
c.collect{|e| e.titleize.gsub(/\s/, "")}.join " "
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def title
|
|
26
|
+
def title *titles
|
|
27
27
|
seperator = " - "
|
|
28
28
|
|
|
29
29
|
default_options = {sitename: _("/logo")}
|
|
@@ -32,23 +32,15 @@ module JapMagWidgetsHelper
|
|
|
32
32
|
page_title = page_title_for_return = titles.join(seperator)
|
|
33
33
|
page_title = options[:sitename] + seperator + page_title_for_return if not options[:sitename].blank?
|
|
34
34
|
|
|
35
|
-
content_for
|
|
35
|
+
content_for :title, page_title
|
|
36
36
|
|
|
37
37
|
page_title_for_return
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def paginator
|
|
40
|
+
def paginator collections, options = {}
|
|
41
41
|
will_paginate collections, options
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def time_difference time
|
|
45
|
-
"#{distance_of_time_in_words(time, Time.now, true)} ago" if time
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def current_or_null(condition)
|
|
49
|
-
condition ? "current" : nil
|
|
50
|
-
end
|
|
51
|
-
|
|
52
44
|
def last_deployed_at
|
|
53
45
|
file = File.join("tmp", "restart.txt")
|
|
54
46
|
File.exists?(file) ? File.atime(file) : nil
|
|
@@ -74,13 +66,15 @@ module JapMagWidgetsHelper
|
|
|
74
66
|
end
|
|
75
67
|
|
|
76
68
|
def bootstrap_scope_button scopes, options = {}
|
|
77
|
-
content_tag :ul, class: "nav nav-tabs" do
|
|
69
|
+
content_tag :ul, class: "nav nav-tabs simple-tabs" do
|
|
78
70
|
scopes.collect do |scope|
|
|
79
71
|
url = eval("#{options[:path].to_s}(scope: :#{scope[:key]})")
|
|
80
72
|
current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and scope[:default] == true and params[:scope].blank?))
|
|
81
|
-
|
|
73
|
+
klass = %w(nav-link)
|
|
74
|
+
klass << :active if current
|
|
75
|
+
link = link_to("#{content_tag(:span, scope[:text])} (#{scope[:count]})".html_safe, url, class: klass.join(' '))
|
|
82
76
|
|
|
83
|
-
concat content_tag(:li, link, class:
|
|
77
|
+
concat content_tag(:li, link, class: 'nav-item')
|
|
84
78
|
end
|
|
85
79
|
end
|
|
86
80
|
end
|
|
@@ -128,7 +122,7 @@ module JapMagWidgetsHelper
|
|
|
128
122
|
end
|
|
129
123
|
end
|
|
130
124
|
|
|
131
|
-
def link_to_external text, link, options={}
|
|
125
|
+
def link_to_external text, link, options = {}
|
|
132
126
|
options.merge!(target: :_blank)
|
|
133
127
|
|
|
134
128
|
if options[:anonymous]
|
|
@@ -136,26 +130,26 @@ module JapMagWidgetsHelper
|
|
|
136
130
|
options.delete(:anonymous)
|
|
137
131
|
end
|
|
138
132
|
|
|
139
|
-
link_to "#{text}#{fa_icon "external-link"}".html_safe, link, options
|
|
133
|
+
link_to "#{text}#{fa_icon "external-link-alt", type: :fas}".html_safe, link, options
|
|
140
134
|
end
|
|
141
135
|
|
|
142
136
|
def input_for_selection text
|
|
143
|
-
(content_tag :input, nil, value: text, class: "form-input for-selection").html_safe
|
|
137
|
+
(content_tag :input, nil, value: text, size: text.length, class: "form-input for-selection").html_safe
|
|
144
138
|
end
|
|
145
139
|
|
|
146
140
|
#
|
|
147
141
|
# call to action
|
|
148
142
|
#
|
|
149
|
-
def cta text, url,
|
|
143
|
+
def cta text, url, options = {}
|
|
150
144
|
klass = %w(button button-rounded button-caution)
|
|
151
|
-
klass <<
|
|
152
|
-
|
|
145
|
+
klass << options[:class] if options[:class].present?
|
|
146
|
+
options[:class] = klass.join(" ")
|
|
153
147
|
|
|
154
|
-
link_to text, url,
|
|
148
|
+
link_to text, url, options
|
|
155
149
|
end
|
|
156
150
|
|
|
157
|
-
def cta_params
|
|
158
|
-
{data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge
|
|
151
|
+
def cta_params options = {}
|
|
152
|
+
{data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge options
|
|
159
153
|
end
|
|
160
154
|
|
|
161
155
|
def long_date date
|
|
@@ -167,6 +161,32 @@ module JapMagWidgetsHelper
|
|
|
167
161
|
I18n.l date, format: :short
|
|
168
162
|
end
|
|
169
163
|
|
|
164
|
+
def retina_image_tag name_at_1x, options = {}
|
|
165
|
+
# webp for Chrome
|
|
166
|
+
if options[:webp]
|
|
167
|
+
name_at_1x = name_at_1x.gsub /\.[a-zA-Z]+$/, '.webp'
|
|
168
|
+
|
|
169
|
+
options.delete :webp
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# retina
|
|
173
|
+
name_at_2x = name_at_1x.gsub /\.\w+$/, "@2x\\0"
|
|
174
|
+
|
|
175
|
+
# i18n
|
|
176
|
+
if options[:i18n]
|
|
177
|
+
name_at_1x = name_at_1x.gsub /\.[a-zA-Z]+$/, ".#{I18n.locale}\\0"
|
|
178
|
+
name_at_2x = name_at_2x.gsub /\.[a-zA-Z]+$/, ".#{I18n.locale}\\0"
|
|
179
|
+
|
|
180
|
+
options.delete :i18n
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# HTML 5 specific tag attributes
|
|
184
|
+
srcset = "#{asset_path(name_at_1x)} 1x, #{asset_path(name_at_2x)} 2x"
|
|
185
|
+
options = options.merge(srcset: srcset)
|
|
186
|
+
|
|
187
|
+
image_tag name_at_1x, options
|
|
188
|
+
end
|
|
189
|
+
|
|
170
190
|
protected
|
|
171
191
|
|
|
172
192
|
def current_template
|
data/jap_mag.gemspec
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
require File.expand_path('../lib/jap_mag/version', __FILE__)
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |gem|
|
|
5
|
-
gem.authors = ["
|
|
5
|
+
gem.authors = ["DING Yu"]
|
|
6
6
|
gem.email = ["felixding@gmail.com"]
|
|
7
|
-
gem.description = %q{JapMag is
|
|
7
|
+
gem.description = %q{JapMag is a collection of frequently-used Rails controller methods and helpers.}
|
|
8
8
|
gem.summary = "jap_mag-#{gem.version}"
|
|
9
9
|
gem.homepage = "https://github.com/felixding/JapMag"
|
|
10
10
|
|
|
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
|
|
|
14
14
|
gem.name = "jap_mag"
|
|
15
15
|
gem.require_paths = ["lib"]
|
|
16
16
|
gem.version = JapMag::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_runtime_dependency :will_paginate
|
|
17
19
|
end
|
data/lib/jap_mag.rb
CHANGED
|
@@ -13,6 +13,28 @@ module JapMag
|
|
|
13
13
|
t(key, options)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def current_locale
|
|
17
|
+
params[:locale] || I18n.default_locale || extract_locale_from_accept_language_header
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def extract_locale_from_accept_language_header
|
|
21
|
+
if request.env and request.env['HTTP_ACCEPT_LANGUAGE']
|
|
22
|
+
lang = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
|
|
23
|
+
else
|
|
24
|
+
lang = nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
lang == "zh" ? "zh-CN" : "en"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def current_path
|
|
31
|
+
URI.encode(request.fullpath)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def current_url
|
|
35
|
+
URI.encode(request.original_url)
|
|
36
|
+
end
|
|
37
|
+
|
|
16
38
|
#
|
|
17
39
|
# the args can be one of the following:
|
|
18
40
|
#
|
|
@@ -56,6 +78,9 @@ module JapMag
|
|
|
56
78
|
def self.included base
|
|
57
79
|
base.helper_method :_
|
|
58
80
|
base.helper_method :current_controller_action_in?
|
|
81
|
+
base.helper_method :current_locale
|
|
82
|
+
base.helper_method :current_url
|
|
83
|
+
base.helper_method :current_path
|
|
59
84
|
end
|
|
60
85
|
|
|
61
86
|
class Engine < Rails::Engine
|
data/lib/jap_mag/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jap_mag
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- DING Yu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: will_paginate
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: JapMag is a collection of frequently-used Rails controller methods and
|
|
28
|
+
helpers.
|
|
15
29
|
email:
|
|
16
30
|
- felixding@gmail.com
|
|
17
31
|
executables: []
|
|
18
32
|
extensions: []
|
|
19
33
|
extra_rdoc_files: []
|
|
20
34
|
files:
|
|
21
|
-
- .gitignore
|
|
35
|
+
- ".gitignore"
|
|
22
36
|
- Gemfile
|
|
23
|
-
- LICENSE
|
|
24
37
|
- README.md
|
|
25
38
|
- Rakefile
|
|
26
39
|
- app/assets/javascripts/jap_mag.js
|
|
@@ -50,17 +63,17 @@ require_paths:
|
|
|
50
63
|
- lib
|
|
51
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
65
|
requirements:
|
|
53
|
-
- -
|
|
66
|
+
- - ">="
|
|
54
67
|
- !ruby/object:Gem::Version
|
|
55
68
|
version: '0'
|
|
56
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
70
|
requirements:
|
|
58
|
-
- -
|
|
71
|
+
- - ">="
|
|
59
72
|
- !ruby/object:Gem::Version
|
|
60
73
|
version: '0'
|
|
61
74
|
requirements: []
|
|
62
75
|
rubyforge_project:
|
|
63
|
-
rubygems_version: 2.
|
|
76
|
+
rubygems_version: 2.7.7
|
|
64
77
|
signing_key:
|
|
65
78
|
specification_version: 4
|
|
66
79
|
summary: jap_mag-
|
data/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2012 Felix Ding
|
|
2
|
-
|
|
3
|
-
MIT License
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|