jap_mag 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,177 +1,175 @@
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
- # navigation helper
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
- return content_tag :ul, :id => options[:id], :class => options[:class] do
63
- items.collect {|item| concat(item)}
64
- end
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 clearfix options={}
68
- opt = {:class => " clearfix"}
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 link_to_user(user, options={})
44
+ def time_difference time
45
+ "#{distance_of_time_in_words(time, Time.now, true)} ago" if time
46
+ end
76
47
 
77
- default_options = {
78
- :href => user,
79
- :avatar => false,
80
- :title => user.name,
81
- :class => ""
82
- }
48
+ def current_or_null(condition)
49
+ condition ? "current" : nil
50
+ end
83
51
 
84
- options = default_options.merge(options)
52
+ def last_deployed_at
53
+ file = File.join("tmp", "restart.txt")
54
+ File.exists?(file) ? File.atime(file) : nil
55
+ end
85
56
 
86
- if options[:avatar]
87
- return unless user.avatar?
57
+ def bootstrap_menu links
58
+ links.collect do |link|
59
+ klass = []
60
+ klass << link[:klass] if link[:klass]
61
+ klass << "last-child" if link == links.last
88
62
 
89
- text = image_tag(user.avatar.url(options[:avatar]), :alt => user.name, :class => "avatar")
63
+ if (link[:controller_action].is_a?(Array) and current_controller_action_in?(*link[:controller_action])) \
64
+ or (current_controller_action_in?(link[:controller_action]))
65
+ klass << "active"
66
+ end
90
67
 
91
- options[:class] += " avatar".strip
92
- else
93
- text = user.name
94
- end
68
+ klass = klass.empty? ? nil : klass.join(" ")
95
69
 
96
- #raise url_for(user)#user_path(:subdomain => "aaa").inspect
97
- link_to(text, options[:href], :title => options[:title], :class => options[:class])
70
+ content_tag :li, class: klass do
71
+ link_to link[:text], link[:path], link[:html_options]
72
+ end
73
+ end.join.html_safe
98
74
  end
99
75
 
100
- def title(*titles)
101
- seperator = " - "
76
+ def bootstrap_scope_button scopes, options = {}
77
+ content_tag :ul, class: "nav nav-tabs" do
78
+ scopes.collect do |scope|
79
+ url = eval("#{options[:path].to_s}(scope: :#{scope[:key]})")
80
+ current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and scope[:default] == true and params[:scope].blank?))
81
+ link = link_to("#{content_tag(:span, scope[:text])} (#{scope[:count]})".html_safe, url)
102
82
 
103
- default_options = {:sitename => true}
104
- options = titles.last.is_a?(Hash) ? titles.pop : {}
105
- options = default_options.merge(options)
83
+ concat content_tag(:li, link, class: (current ? :active : nil))
84
+ end
85
+ end
86
+ end
106
87
 
107
- page_title = page_title_for_return = titles.join(seperator)
108
- page_title = t("logo") + seperator + page_title_for_return if options[:sitename]
88
+ def bootstrap_button_group checkbox, id = nil, status = nil, default = nil
89
+ status ||= %w(turned_on turned_off)
90
+ default ||= "turned_off"
109
91
 
110
- content_for(:title, page_title)
92
+ content_tag :div, "id" => id, "class" => "bootstrap-toggle" do
93
+ buttons = content_tag :div, "class" => "btn-group", "data-toggle" => "buttons-radio" do
94
+ status.collect do |s|
95
+ content_tag :button, "type" => "button", "class" => "btn btn-default #{s}#{" active" if s == default}", "data-status" => s do
96
+ _("/page.my.pac.status.#{s}")
97
+ end
98
+ end.join.html_safe
99
+ end
111
100
 
112
- page_title_for_return
101
+ buttons + checkbox
102
+ end
113
103
  end
114
104
 
115
- def random_disable_with_status
116
- status = [
117
- "Just a moment",
118
- "Let's stay together",
119
- "On the highway to hell",
120
- "Don't worry baby",
121
- "Let it be",
122
- "Getting you away from here",
123
- "Let's get it started",
124
- "It's now or never"
125
- ]
105
+ def bootstrap_stacked_progress_bar percent, options = {}
106
+ klass = if percent < 50
107
+ :success
108
+ elsif percent >= 50 and percent < 80
109
+ :warning
110
+ else
111
+ :danger
112
+ end
126
113
 
127
- status.shuffle.first + "..."
114
+ #percent = "#{percent * 100}%"
115
+ options[:precision] ||= 2
116
+ percent = number_to_percentage percent, options
117
+
118
+ opts_for_container = {class: :progress}
119
+ if options[:tooltip]
120
+ placement = options[:tooltip][:placement] || "top"
121
+ opts_for_container.merge!("data-toggle" => "tooltip", "data-placement" => placement, title: options[:tooltip][:title])
122
+ end
123
+
124
+ content_tag :div, opts_for_container do
125
+ content_tag :div, class: "progress-bar progress-bar-#{klass}", role: :progressbar, style: "width: #{percent}" do
126
+ percent
127
+ end
128
+ end
128
129
  end
129
130
 
130
- #
131
- # call to action
132
- #
133
- def cta text, url, html_options={}
131
+ def link_to_external text, link, options={}
132
+ options.merge!(target: :_blank)
134
133
 
135
- html_options[:class] = (html_options[:class].to_s + " cta").strip
134
+ if options[:anonymous]
135
+ link = "http://anonym.to/?#{link}"
136
+ options.delete(:anonymous)
137
+ end
136
138
 
137
- link_to content_tag(:span, text), url, html_options
139
+ link_to "#{text}#{fa_icon "external-link"}".html_safe, link, options
140
+ end
141
+
142
+ def input_for_selection text
143
+ (content_tag :input, nil, value: text, class: "form-input for-selection").html_safe
138
144
  end
139
145
 
140
146
  #
141
- # paginator
147
+ # call to action
142
148
  #
143
- def paginator(collections, options={})
144
- will_paginate collections, options
149
+ def cta text, url, opts = {}
150
+ klass = %w(button button-rounded button-caution)
151
+ klass << opts[:class] if opts[:class].present?
152
+ opts[:class] = klass.join(" ")
153
+
154
+ link_to text, url, opts
145
155
  end
146
156
 
147
- def time_difference time
148
- "#{distance_of_time_in_words(time, Time.now, true)} ago" if time
157
+ def cta_params opts = {}
158
+ {data: {disable_with: _("/actions.wait")}, class: "button button-rounded button-caution"}.merge opts
149
159
  end
150
-
151
- def current_or_null(condition)
152
- condition ? "current" : nil
160
+
161
+ def long_date date
162
+ I18n.l date, format: :long
153
163
  end
154
164
 
155
- def scope_button scopes, options={}
156
- content_tag :ul, class: :scopes do
157
- scopes.collect do |scope|
158
- count = options[:count][scope[:key]]
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?))
161
165
 
162
- concat content_tag(:li, link_to("#{content_tag(:span, scope[:text])} (#{count})".html_safe, url, class: current_or_null(current)))
163
- end
164
- end
165
- end
166
-
167
- def last_deployed_at
168
- file = File.join("tmp", "restart.txt")
169
- File.exists?(file) ? File.atime(file) : nil
166
+ def short_date date
167
+ I18n.l date, format: :short
170
168
  end
171
169
 
172
170
  protected
173
-
171
+
174
172
  def current_template
175
173
  File.basename(lookup_context.find_all(params[:action], params[:controller]).first.inspect)
176
174
  end
177
- end
175
+ 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>
@@ -1,7 +0,0 @@
1
- <div id="header">
2
- <div class="gutter">
3
- <h1><%= link_to t("logo"), root_path %></h1>
4
- <p class="slogan"><%= t("slogan") %></p>
5
- <%= render "layouts/navigation" %>
6
- </div>
7
- </div>
File without changes
@@ -1,3 +0,0 @@
1
- <ul class="navigation">
2
- <li><%= link_to_unless_current t("navigation.home"), root_path %></li>
3
- </ul>
@@ -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"
@@ -1,3 +1,3 @@
1
1
  module JapMag
2
- VERSION = "0.0.4"
3
- end
2
+ VERSION = "0.0.5"
3
+ end
data/lib/jap_mag.rb CHANGED
@@ -3,38 +3,61 @@ module JapMag
3
3
  def _ key, options={}
4
4
  # for absolute pathes /
5
5
  if (key[0] == "/")
6
- key = key.gsub("/", "")
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
+ #
17
+ # the args can be one of the following:
18
+ #
19
+ # String: "page#index"
20
+ # Array: %w(page#index page#intro)
21
+ # multiple arguments: "page#index", "page#intro"
22
+ #
16
23
  def current_controller_action_in?(*args)
17
24
  controller = params["controller"]
18
25
  action = params["action"]
19
26
 
20
- args.each do |element|
27
+ if args.size == 1
28
+ if args.first.is_a?(Array)
29
+ arguments = args.first.split(" ").first
30
+ elsif args.first.is_a?(String)
31
+ if args.first.split(" ").size > 1
32
+ arguments = args.first.split(" ")
33
+ else
34
+ arguments = args
35
+ end
36
+ end
37
+ else
38
+ arguments = args
39
+ end
40
+
41
+ #raise arguments.inspect
42
+
43
+ arguments.each do |element|
21
44
  if element.include?("#")
22
- array = element.match(/([a-z\-\_]*)#([a-z\-\_]*)/).to_a
45
+ array = element.match(/([a-z\-\_\/]*)#([a-z\-\_]*)/).to_a
23
46
  c, a = array[1], array[2]
24
47
  return true if controller == c && action == a
25
48
  else
26
49
  return true if controller == element
27
50
  end
28
51
  end
29
-
52
+
30
53
  false
31
54
  end
32
-
55
+
33
56
  def self.included base
34
57
  base.helper_method :_
35
58
  base.helper_method :current_controller_action_in?
36
59
  end
37
-
60
+
38
61
  class Engine < Rails::Engine
39
62
  end
40
63
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jap_mag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Felix Ding
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: JapMag is the design language created by Felix Ding. This gem helps designers
15
14
  start a project that follows JapMag.
@@ -27,45 +26,42 @@ files:
27
26
  - app/assets/javascripts/jap_mag.js
28
27
  - app/assets/javascripts/jap_mag/base.js
29
28
  - app/assets/stylesheets/jap_mag.css
30
- - app/assets/stylesheets/jap_mag/base.scss
29
+ - app/assets/stylesheets/jap_mag/buttons.css
31
30
  - app/assets/stylesheets/jap_mag/mixins.scss
32
- - app/assets/stylesheets/jap_mag/reset.scss
33
- - app/assets/stylesheets/jap_mag/variables.scss
34
31
  - app/assets/stylesheets/jap_mag/widgets.scss
35
32
  - app/helpers/jap_mag_widgets_helper.rb
36
33
  - app/views/layouts/_flash.erb
37
34
  - app/views/layouts/_footer.erb
38
35
  - app/views/layouts/_header.erb
36
+ - app/views/layouts/_javascript.html
39
37
  - app/views/layouts/_navigation.erb
40
- - app/views/layouts/_rss.erb
41
38
  - app/views/layouts/_tracking.erb
42
- - app/views/layouts/application.erb
39
+ - app/views/layouts/application.haml
43
40
  - config/locales/en.yml
44
41
  - jap_mag.gemspec
45
42
  - lib/jap_mag.rb
46
43
  - lib/jap_mag/version.rb
47
44
  homepage: https://github.com/felixding/JapMag
48
45
  licenses: []
46
+ metadata: {}
49
47
  post_install_message:
50
48
  rdoc_options: []
51
49
  require_paths:
52
50
  - lib
53
51
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
52
  requirements:
56
- - - ! '>='
53
+ - - '>='
57
54
  - !ruby/object:Gem::Version
58
55
  version: '0'
59
56
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
57
  requirements:
62
- - - ! '>='
58
+ - - '>='
63
59
  - !ruby/object:Gem::Version
64
60
  version: '0'
65
61
  requirements: []
66
62
  rubyforge_project:
67
- rubygems_version: 1.8.24
63
+ rubygems_version: 2.1.11
68
64
  signing_key:
69
- specification_version: 3
65
+ specification_version: 4
70
66
  summary: jap_mag-
71
67
  test_files: []
@@ -1,174 +0,0 @@
1
- @import 'variables';
2
- @import "mixins";
3
-
4
- body {
5
- font: 12px / 130% "Lucida Grande", Arial, Helvetica, Verdana, sans-serif;
6
- color: $color_body;
7
- }
8
-
9
- #wrapper {
10
- width: $base_width;
11
- padding: 10px;
12
- margin: 0 auto;
13
- }
14
-
15
- a {
16
- color: $color_blue;
17
- text-decoration: none;
18
-
19
- &.dangerous {
20
- color: red;
21
- }
22
-
23
- &.edit {
24
- color: $color_yellow;
25
- }
26
-
27
- &:hover {
28
- color: #fff;
29
- background-color: #000;
30
- }
31
-
32
- img {
33
- border: none;
34
- }
35
- }
36
-
37
- em {
38
- font-style: italic;
39
- }
40
-
41
- .hidden {
42
- display: none;
43
- }
44
-
45
- h1, h2, h3, h4 {
46
- font-weight: normal;
47
- line-height: 1em;
48
- margin: 0 0 1em;
49
- -webkit-font-smoothing: antialiased;
50
- }
51
-
52
- h1 {
53
- margin: 0 0 15px 0;
54
- font-size: (40px / 12px) * 100%;
55
-
56
- a {
57
- color: black;
58
- }
59
- }
60
-
61
- h2 {
62
- font-size: 1.6em;
63
- line-height: 1.6em;
64
- }
65
-
66
- h3 {
67
- font-size: 1.4em;
68
- line-height: 1.4em;
69
- }
70
-
71
- p {
72
- margin: 0.5em 0;
73
- }
74
-
75
- blockquote {
76
- border-left: 2px solid #ccc;
77
- margin: 0 0 0 3em;
78
- padding: 0 0px 0 1em;
79
- }
80
-
81
- #header {
82
- overflow: hidden;
83
- padding: 0 0 10px;
84
- margin: 0 0 20px;
85
-
86
- .slogan {
87
- font-size: (20px / 12px) * 100%;
88
- }
89
-
90
- .navigation {
91
- overflow: hidden;
92
- margin: 20px 0 0;
93
-
94
- &.left {
95
- float: left;
96
- }
97
-
98
- li {
99
- float: left;
100
- margin: 0 10px 0 0;
101
- padding: 0 10px 0 0;
102
- border-right: 1px solid #ccc;
103
-
104
- &:last-child {
105
- border: none;
106
- margin-right: 0;
107
- padding-right: 0;
108
- }
109
-
110
- .highlight {
111
- color: red;
112
-
113
- &:hover {
114
- color: white;
115
- }
116
- }
117
- }
118
- }
119
-
120
- .admin-navigation {
121
- @extend .navigation;
122
- margin: 10px 0 0;
123
- padding: 10px;
124
- background: #eee;
125
- float: left;
126
-
127
- li {
128
- border: none;
129
- }
130
- }
131
- }
132
-
133
- #body {
134
- margin: 0;
135
- padding: 0;
136
- overflow: hidden;
137
-
138
- .primary {
139
- width: (720px / $base_width) * 100%;
140
- margin-right: 30px;
141
- float: right;
142
- overflow: hidden;
143
- }
144
-
145
- .secondary {
146
- float: left;
147
- width: (150px / $base_width) * 100%;
148
- overflow: hidden;
149
- }
150
- }
151
-
152
- #footer {
153
- margin: 50px 0 10px;
154
- color: #666;
155
-
156
- .languages {
157
- overflow: hidden;
158
- margin: 5px 0 0;
159
-
160
- li {
161
- float: left;
162
- margin: 0 20px 0 0;
163
- padding: 0 0 0 20px;
164
- }
165
-
166
- .zh-CN {
167
- background: url($flag_zh-cn) no-repeat 0 2px;
168
- }
169
-
170
- .en {
171
- background: url($flag_en) no-repeat 0 2px;
172
- }
173
- }
174
- }