jap_mag 0.0.4 → 1.3.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 +7 -0
- data/README.md +8 -10
- data/app/assets/stylesheets/jap_mag.css +1 -3
- data/app/assets/stylesheets/jap_mag/buttons.css +1273 -0
- data/app/assets/stylesheets/jap_mag/mixins.scss +0 -99
- data/app/assets/stylesheets/jap_mag/widgets.scss +8 -421
- data/app/helpers/jap_mag_widgets_helper.rb +134 -116
- data/app/views/layouts/_footer.erb +0 -13
- data/app/views/layouts/_header.erb +0 -7
- data/app/views/layouts/{_rss.erb → _javascript.html} +0 -0
- data/app/views/layouts/_navigation.erb +0 -3
- data/app/views/layouts/application.haml +34 -0
- data/jap_mag.gemspec +4 -2
- data/lib/jap_mag.rb +57 -9
- data/lib/jap_mag/version.rb +2 -2
- metadata +29 -20
- data/LICENSE +0 -22
- data/app/assets/stylesheets/jap_mag/base.scss +0 -174
- data/app/assets/stylesheets/jap_mag/reset.scss +0 -48
- data/app/assets/stylesheets/jap_mag/variables.scss +0 -17
- data/app/views/layouts/application.erb +0 -36
@@ -1,177 +1,195 @@
|
|
1
1
|
module JapMagWidgetsHelper
|
2
|
-
|
3
2
|
def is_mobile_device?
|
4
3
|
mobile_user_agents = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile'
|
5
4
|
request.user_agent.to_s.downcase =~ Regexp.new(mobile_user_agents)
|
6
5
|
end
|
7
|
-
|
6
|
+
|
8
7
|
def get_body_class
|
9
8
|
c = []
|
10
9
|
c << controller.controller_name
|
11
10
|
c << "mobile" if is_mobile_device?
|
12
|
-
|
11
|
+
|
13
12
|
c.collect{|e| e.titleize.gsub(/\s/, "")}.join " "
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
def get_body_id
|
17
16
|
content_for(:id).to_s.titleize.gsub(/\s/, "") unless content_for(:id).blank?
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
def get_wrapper_class
|
21
20
|
c = []
|
22
21
|
c << controller.action_name
|
23
|
-
|
22
|
+
|
24
23
|
c.collect{|e| e.titleize.gsub(/\s/, "")}.join " "
|
25
24
|
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
# by Felix
|
30
|
-
#
|
31
|
-
# the helper matches params with request.request_uri
|
32
|
-
#
|
33
|
-
# example:
|
34
|
-
# sections = {
|
35
|
-
# 'radio'=>{:title => 'Station', :url => radio_path},
|
36
|
-
# 'edit_station'=>{:url => 'Radio', :url => edit_station_path}
|
37
|
-
# }
|
38
|
-
# options = {
|
39
|
-
# :id => 'test_menu'
|
40
|
-
# :current => 'current'
|
41
|
-
# }
|
42
|
-
# outputs:
|
43
|
-
# <ul id="test_menu">
|
44
|
-
# <li><a href="/station">Station</a></li>
|
45
|
-
# <li class="current"><a href="/radio/">Radio</a></li>
|
46
|
-
# </ul>
|
47
|
-
#:title
|
48
|
-
def menu(sections, options=nil)
|
49
|
-
items = Array.new
|
50
|
-
|
51
|
-
# default options
|
52
|
-
options ||= Hash.new
|
53
|
-
options[:id] ||= nil
|
54
|
-
options[:class] ||= nil
|
55
|
-
options[:current] ||= 'current' # jquery ui tabs plugin needs the later one
|
56
|
-
|
57
|
-
sections.each do |section|
|
58
|
-
klass = section[:current] ? "#{options[:current]} #{section[:class]}".strip : section[:class]
|
59
|
-
items << content_tag(:li, link_to(section[:title], section[:url], :class => klass))
|
60
|
-
end
|
26
|
+
def title *titles
|
27
|
+
seperator = " - "
|
61
28
|
|
62
|
-
|
63
|
-
|
64
|
-
|
29
|
+
default_options = {sitename: _("/logo")}
|
30
|
+
options = titles.last.is_a?(Hash) ? titles.pop : {}
|
31
|
+
options = default_options.merge(options)
|
32
|
+
page_title = page_title_for_return = titles.join(seperator)
|
33
|
+
page_title = options[:sitename] + seperator + page_title_for_return if not options[:sitename].blank?
|
34
|
+
|
35
|
+
content_for :title, page_title
|
36
|
+
|
37
|
+
page_title_for_return
|
65
38
|
end
|
66
39
|
|
67
|
-
def
|
68
|
-
|
69
|
-
options[:class] += opt[:class] if options[:class]
|
70
|
-
(options[:class] || opt[:class]).strip!
|
71
|
-
opt = opt.merge(options)
|
72
|
-
content_tag(:div, nil, opt)
|
40
|
+
def paginator collections, options = {}
|
41
|
+
will_paginate collections, options
|
73
42
|
end
|
74
43
|
|
75
|
-
def
|
44
|
+
def last_deployed_at
|
45
|
+
file = File.join("tmp", "restart.txt")
|
46
|
+
File.exists?(file) ? File.atime(file) : nil
|
47
|
+
end
|
76
48
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
:
|
81
|
-
|
82
|
-
}
|
49
|
+
def bootstrap_menu links
|
50
|
+
links.collect do |link|
|
51
|
+
klass = []
|
52
|
+
klass << link[:klass] if link[:klass]
|
53
|
+
klass << "last-child" if link == links.last
|
83
54
|
|
84
|
-
|
55
|
+
if (link[:controller_action].is_a?(Array) and current_controller_action_in?(*link[:controller_action])) \
|
56
|
+
or (current_controller_action_in?(link[:controller_action]))
|
57
|
+
klass << "active"
|
58
|
+
end
|
85
59
|
|
86
|
-
|
87
|
-
return unless user.avatar?
|
60
|
+
klass = klass.empty? ? nil : klass.join(" ")
|
88
61
|
|
89
|
-
|
62
|
+
content_tag :li, class: klass do
|
63
|
+
link_to link[:text], link[:path], link[:html_options]
|
64
|
+
end
|
65
|
+
end.join.html_safe
|
66
|
+
end
|
90
67
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
68
|
+
def bootstrap_scope_button scopes, options = {}
|
69
|
+
content_tag :ul, class: "nav-tabs simple-tabs" do
|
70
|
+
scopes.collect do |scope|
|
71
|
+
url = eval("#{options[:path].to_s}(scope: :#{scope[:key]})")
|
72
|
+
current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and scope[:default] == true and params[:scope].blank?))
|
73
|
+
link = link_to("#{content_tag(:span, scope[:text])} (#{scope[:count]})".html_safe, url, class: 'nav-link')
|
74
|
+
klass = %w(nav-item)
|
75
|
+
klass << :active if current
|
95
76
|
|
96
|
-
|
97
|
-
|
77
|
+
concat content_tag(:li, link, class: klass.join(' '))
|
78
|
+
end
|
79
|
+
end
|
98
80
|
end
|
99
81
|
|
100
|
-
def
|
101
|
-
|
82
|
+
def bootstrap_button_group checkbox, id = nil, status = nil, default = nil
|
83
|
+
status ||= %w(turned_on turned_off)
|
84
|
+
default ||= "turned_off"
|
102
85
|
|
103
|
-
|
104
|
-
|
105
|
-
|
86
|
+
content_tag :div, "id" => id, "class" => "bootstrap-toggle" do
|
87
|
+
buttons = content_tag :div, "class" => "btn-group", "data-toggle" => "buttons-radio" do
|
88
|
+
status.collect do |s|
|
89
|
+
content_tag :button, "type" => "button", "class" => "btn btn-default #{s}#{" active" if s == default}", "data-status" => s do
|
90
|
+
_("/page.my.pac.status.#{s}")
|
91
|
+
end
|
92
|
+
end.join.html_safe
|
93
|
+
end
|
106
94
|
|
107
|
-
|
108
|
-
|
95
|
+
buttons + checkbox
|
96
|
+
end
|
97
|
+
end
|
109
98
|
|
110
|
-
|
99
|
+
def bootstrap_stacked_progress_bar percent, options = {}
|
100
|
+
klass = if percent < 50
|
101
|
+
:success
|
102
|
+
elsif percent >= 50 and percent < 80
|
103
|
+
:warning
|
104
|
+
else
|
105
|
+
:danger
|
106
|
+
end
|
111
107
|
|
112
|
-
|
108
|
+
#percent = "#{percent * 100}%"
|
109
|
+
options[:precision] ||= 2
|
110
|
+
percent = number_to_percentage percent, options
|
111
|
+
|
112
|
+
opts_for_container = {class: :progress}
|
113
|
+
if options[:tooltip]
|
114
|
+
placement = options[:tooltip][:placement] || "top"
|
115
|
+
opts_for_container.merge!("data-toggle" => "tooltip", "data-placement" => placement, title: options[:tooltip][:title])
|
116
|
+
end
|
117
|
+
|
118
|
+
content_tag :div, opts_for_container do
|
119
|
+
content_tag :div, class: "progress-bar progress-bar-#{klass}", role: :progressbar, style: "width: #{percent}" do
|
120
|
+
percent
|
121
|
+
end
|
122
|
+
end
|
113
123
|
end
|
114
124
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
]
|
125
|
+
def link_to_external text, link, options = {}
|
126
|
+
options.merge!(target: :_blank)
|
127
|
+
|
128
|
+
if options[:anonymous]
|
129
|
+
link = "http://anonym.to/?#{link}"
|
130
|
+
options.delete(:anonymous)
|
131
|
+
end
|
132
|
+
|
133
|
+
link_to "#{text}#{fa_icon "external-link-alt", type: :fas}".html_safe, link, options
|
134
|
+
end
|
126
135
|
|
127
|
-
|
136
|
+
def input_for_selection text
|
137
|
+
(content_tag :input, nil, value: text, size: text.length, class: "form-input for-selection").html_safe
|
128
138
|
end
|
129
139
|
|
130
140
|
#
|
131
141
|
# call to action
|
132
142
|
#
|
133
|
-
def cta text, url,
|
134
|
-
|
135
|
-
|
143
|
+
def cta text, url, options = {}
|
144
|
+
klass = %w(button button-rounded button-caution)
|
145
|
+
klass << options[:class] if options[:class].present?
|
146
|
+
options[:class] = klass.join(" ")
|
136
147
|
|
137
|
-
link_to
|
148
|
+
link_to text, url, options
|
138
149
|
end
|
139
150
|
|
140
|
-
|
141
|
-
|
142
|
-
#
|
143
|
-
def paginator(collections, options={})
|
144
|
-
will_paginate collections, options
|
151
|
+
def cta_params options = {}
|
152
|
+
{data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge options
|
145
153
|
end
|
146
154
|
|
147
|
-
def
|
148
|
-
|
155
|
+
def long_date date
|
156
|
+
I18n.l date, format: :long
|
149
157
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
158
|
+
|
159
|
+
|
160
|
+
def short_date date
|
161
|
+
I18n.l date, format: :short
|
153
162
|
end
|
154
163
|
|
155
|
-
def
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
url = eval("#{options[:path].to_s}(scope: :#{scope[:key]})")
|
160
|
-
current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and params[:scope].blank?))
|
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'
|
161
168
|
|
162
|
-
|
163
|
-
end
|
169
|
+
options.delete :webp
|
164
170
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
170
188
|
end
|
171
189
|
|
172
190
|
protected
|
173
|
-
|
191
|
+
|
174
192
|
def current_template
|
175
193
|
File.basename(lookup_context.find_all(params[:action], params[:controller]).first.inspect)
|
176
194
|
end
|
177
|
-
end
|
195
|
+
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
<div id="footer">
|
2
|
-
<div class="gutter">
|
3
|
-
<p><%= t :copyright %></p>
|
4
|
-
<%= clearfix %>
|
5
|
-
<ul class="languages">
|
6
|
-
<%
|
7
|
-
p = params.dup.delete_if{|key| %w(action controller locale).include?(key)}
|
8
|
-
%>
|
9
|
-
<li class="en"><%= link_to_unless_current t(:english), locale: :en, params: p %></li>
|
10
|
-
<li class="zh-CN"><%= link_to_unless_current t(:chinese), locale: "zh-CN", params: p %></li>
|
11
|
-
</ul>
|
12
|
-
</div>
|
13
|
-
</div>
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
!!! 5
|
2
|
+
-# paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
|
3
|
+
<!--[if IE 8 ]> <html class="ie8" lang="zh-CN"> <![endif]-->
|
4
|
+
<!--[if IE 9 ]> <html class="ie9" lang="zh-CN"> <![endif]-->
|
5
|
+
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="zh-CN"> <!--<![endif]-->
|
6
|
+
%head
|
7
|
+
%meta{ :charset => "utf-8" }/
|
8
|
+
|
9
|
+
-# Always force latest IE rendering engine (even in intranet) & Chrome Frame
|
10
|
+
-# Remove this if you use the .htaccess
|
11
|
+
%meta{ "http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1" }/
|
12
|
+
|
13
|
+
%title
|
14
|
+
= content_for(:title)
|
15
|
+
%meta{ :name => "description", :content => "" }/
|
16
|
+
%meta{ :name => "keywords", :content => "" }/
|
17
|
+
%meta{ :name => "viewport", :content => "width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no" }/
|
18
|
+
= favicon_link_tag "/favicon.ico"
|
19
|
+
= stylesheet_link_tag "application", media: "all", 'data-turbolinks-track' => true
|
20
|
+
= javascript_include_tag "application", 'data-turbolinks-track' => true
|
21
|
+
= csrf_meta_tags
|
22
|
+
|
23
|
+
%body{class: get_body_class, id: get_body_id}
|
24
|
+
#wrapper{class: "#{get_wrapper_class} container"}
|
25
|
+
= render partial: "layouts/header"
|
26
|
+
|
27
|
+
#body
|
28
|
+
= render partial: "layouts/flash", locals: {flash: flash}
|
29
|
+
= content_for(:content).blank? ? yield : yield(:content)
|
30
|
+
|
31
|
+
%footer#footer
|
32
|
+
= render partial: "layouts/footer"
|
33
|
+
= render "layouts/tracking"
|
34
|
+
= render "layouts/javascript"
|
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
@@ -3,38 +3,86 @@ module JapMag
|
|
3
3
|
def _ key, options={}
|
4
4
|
# for absolute pathes /
|
5
5
|
if (key[0] == "/")
|
6
|
-
key = key.
|
7
|
-
|
8
|
-
# for all other cases
|
6
|
+
key = key.sub("/", "")
|
7
|
+
|
8
|
+
# for all other cases
|
9
9
|
else
|
10
10
|
key = "#{params[:controller]}.#{params[:action]}.#{key}"
|
11
11
|
end
|
12
12
|
|
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
|
+
|
38
|
+
#
|
39
|
+
# the args can be one of the following:
|
40
|
+
#
|
41
|
+
# String: "page#index"
|
42
|
+
# Array: %w(page#index page#intro)
|
43
|
+
# multiple arguments: "page#index", "page#intro"
|
44
|
+
#
|
16
45
|
def current_controller_action_in?(*args)
|
17
46
|
controller = params["controller"]
|
18
47
|
action = params["action"]
|
19
48
|
|
20
|
-
args.
|
49
|
+
if args.size == 1
|
50
|
+
if args.first.is_a?(Array)
|
51
|
+
arguments = args.first.split(" ").first
|
52
|
+
elsif args.first.is_a?(String)
|
53
|
+
if args.first.split(" ").size > 1
|
54
|
+
arguments = args.first.split(" ")
|
55
|
+
else
|
56
|
+
arguments = args
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
arguments = args
|
61
|
+
end
|
62
|
+
|
63
|
+
#raise arguments.inspect
|
64
|
+
|
65
|
+
arguments.each do |element|
|
21
66
|
if element.include?("#")
|
22
|
-
array = element.match(/([a-z\-\_]*)#([a-z\-\_]*)/).to_a
|
67
|
+
array = element.match(/([a-z\-\_\/]*)#([a-z\-\_]*)/).to_a
|
23
68
|
c, a = array[1], array[2]
|
24
69
|
return true if controller == c && action == a
|
25
70
|
else
|
26
71
|
return true if controller == element
|
27
72
|
end
|
28
73
|
end
|
29
|
-
|
74
|
+
|
30
75
|
false
|
31
76
|
end
|
32
|
-
|
77
|
+
|
33
78
|
def self.included base
|
34
79
|
base.helper_method :_
|
35
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
|
36
84
|
end
|
37
|
-
|
85
|
+
|
38
86
|
class Engine < Rails::Engine
|
39
87
|
end
|
40
88
|
end
|