jap_mag 0.0.5 → 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/README.md +8 -10
- data/app/helpers/jap_mag_widgets_helper.rb +37 -19
- 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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15de12aae70facaeefe817bfc856fb6d1f9a371f
|
4
|
+
data.tar.gz: a899e3798ffff6a12c600da6c48a570151df9c2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52277feb465aa0ab1901843b57f04498f38a5e0e72bb10d3b3d43efa6379d13c86ff2a14bd169a93c630a3daa848994eee1a297659dccdc4773f41dd94e68cdc
|
7
|
+
data.tar.gz: a91a79a2d247b5ed808a292eb9e27052e7f1157dd10e73ae9b829c80d27887c40ca7a5addf676b5f3611d594071bd5d6ff5ac9635ecaba33d4aebeaadae8d24f
|
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
|
@@ -128,7 +120,7 @@ module JapMagWidgetsHelper
|
|
128
120
|
end
|
129
121
|
end
|
130
122
|
|
131
|
-
def link_to_external text, link, options={}
|
123
|
+
def link_to_external text, link, options = {}
|
132
124
|
options.merge!(target: :_blank)
|
133
125
|
|
134
126
|
if options[:anonymous]
|
@@ -140,22 +132,22 @@ module JapMagWidgetsHelper
|
|
140
132
|
end
|
141
133
|
|
142
134
|
def input_for_selection text
|
143
|
-
(content_tag :input, nil, value: text, class: "form-input for-selection").html_safe
|
135
|
+
(content_tag :input, nil, value: text, size: text.length, class: "form-input for-selection").html_safe
|
144
136
|
end
|
145
137
|
|
146
138
|
#
|
147
139
|
# call to action
|
148
140
|
#
|
149
|
-
def cta text, url,
|
141
|
+
def cta text, url, options = {}
|
150
142
|
klass = %w(button button-rounded button-caution)
|
151
|
-
klass <<
|
152
|
-
|
143
|
+
klass << options[:class] if options[:class].present?
|
144
|
+
options[:class] = klass.join(" ")
|
153
145
|
|
154
|
-
link_to text, url,
|
146
|
+
link_to text, url, options
|
155
147
|
end
|
156
148
|
|
157
|
-
def cta_params
|
158
|
-
{data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge
|
149
|
+
def cta_params options = {}
|
150
|
+
{data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge options
|
159
151
|
end
|
160
152
|
|
161
153
|
def long_date date
|
@@ -167,6 +159,32 @@ module JapMagWidgetsHelper
|
|
167
159
|
I18n.l date, format: :short
|
168
160
|
end
|
169
161
|
|
162
|
+
def retina_image_tag name_at_1x, options = {}
|
163
|
+
# webp for Chrome
|
164
|
+
if options[:webp]
|
165
|
+
name_at_1x = name_at_1x.gsub /\.[a-zA-Z]+$/, '.webp'
|
166
|
+
|
167
|
+
options.delete :webp
|
168
|
+
end
|
169
|
+
|
170
|
+
# retina
|
171
|
+
name_at_2x = name_at_1x.gsub /\.\w+$/, "@2x\\0"
|
172
|
+
|
173
|
+
# i18n
|
174
|
+
if options[:i18n]
|
175
|
+
name_at_1x = name_at_1x.gsub /\.[a-zA-Z]+$/, ".#{current_locale}\\0"
|
176
|
+
name_at_2x = name_at_2x.gsub /\.[a-zA-Z]+$/, ".#{current_locale}\\0"
|
177
|
+
|
178
|
+
options.delete :i18n
|
179
|
+
end
|
180
|
+
|
181
|
+
# HTML 5 specific tag attributes
|
182
|
+
srcset = "#{asset_path(name_at_1x)} 1x, #{asset_path(name_at_2x)} 2x"
|
183
|
+
options = options.merge(srcset: srcset)
|
184
|
+
|
185
|
+
image_tag name_at_1x, options
|
186
|
+
end
|
187
|
+
|
170
188
|
protected
|
171
189
|
|
172
190
|
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: 0.0
|
4
|
+
version: 1.0.0
|
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: 2017-11-12 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.6.10
|
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.
|