andy_rails_toolbox 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09558d094c0ae5cdf3d627a0cca25cdaf278c090
4
- data.tar.gz: 5ab9aff7165be3c1417ddbfe14a87d3df1e3a64a
3
+ metadata.gz: 7ec7999c1f2abf182ec385152af0025d4fd7864e
4
+ data.tar.gz: 818c24d74ccb8af8e928a88db5b5874367d0efe4
5
5
  SHA512:
6
- metadata.gz: c3e52ad10fe2ae6b9d656f8c31e5fdca5ccb3b4e4e9c09fd373ecece131664112e2893ab4676f8a07327666074cb72ab7b40ae8017fef44049c38af4e506934e
7
- data.tar.gz: 7daa0744291b77cf196cd9ca18f7b866c95f75fc5147e5b7dc6984115776c7ce3c33be1d0ec55cb8144f61e018344e97db5b7b03f8410e70faee2a7f1d6bf881
6
+ metadata.gz: 392ca668c9f2f7328ca759696495babed7dddb910734431032d241a8fd2aaad7892b3e96a56450c9c91124830fa392f8e61cfa1fc676244ad6f4285622905b91
7
+ data.tar.gz: a043389d4987a619dc966e9a154178be73831c80e16bee7bc22a5e127a27c1e42da76393b888df1170681a3fe878b2d91e30ce74a39db3f1928aed35e81b40d0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Andy Rails Toolbox
1
+ # Andy Rails Toolbox [![Gem Version](https://badge.fury.io/rb/andy_rails_toolbox.svg)](http://badge.fury.io/rb/andy_rails_toolbox)
2
2
 
3
3
  Andy Rails Toolbox includes many useful helpers for rails development.
4
4
 
@@ -39,14 +39,14 @@ Examples
39
39
 
40
40
  ICONS
41
41
 
42
- ``` rb
42
+ ``` ruby
43
43
  bs_icon 'user'
44
44
  # => <span class="glyphicon glyphicon-user"></span>
45
45
  ```
46
46
 
47
47
  BUTTONS
48
48
 
49
- ``` rb
49
+ ``` ruby
50
50
  html_button 'button'
51
51
  # => <button name="button" type="button" class="btn btn-default">button</button>
52
52
  html_button 'button', color: 'primary'
@@ -73,7 +73,7 @@ input_submit 'input button'
73
73
 
74
74
  IMAGES
75
75
 
76
- ``` rb
76
+ ``` ruby
77
77
  image_responsive 'pic.png'
78
78
  # => <img class="img-responsive" src="/images/pic.png" alt="Pic" />
79
79
  image_rounded 'pic.png'
@@ -105,7 +105,7 @@ irb(main):002:0> Pygments.styles
105
105
 
106
106
  Examples
107
107
 
108
- ``` rb
108
+ ``` ruby
109
109
  markdown '# h1'
110
110
  # => <h1>h1</h1>
111
111
  markdown '## h2'
@@ -118,7 +118,7 @@ markdown @post.content
118
118
 
119
119
  #### QrcodeHelper Examples
120
120
 
121
- ``` rb
121
+ ``` ruby
122
122
  qrcode 'Hello world!'
123
123
  ```
124
124
 
@@ -126,7 +126,7 @@ qrcode 'Hello world!'
126
126
 
127
127
  QRCode options parameters: <a href="https://google-developers.appspot.com/chart/infographics/docs/qr_codes#overview" target="_blank">Here</a>
128
128
 
129
- ``` rb
129
+ ``` ruby
130
130
  qrcode 'Hello world!', width: '300', output_encoding: 'Shift_JIS', error_correction_level: 'H', margin: '10'
131
131
  ```
132
132
 
@@ -134,17 +134,18 @@ qrcode 'Hello world!', width: '300', output_encoding: 'Shift_JIS', error_correct
134
134
 
135
135
  Font Awesome icons Homepage: <a href="http://fortawesome.github.io/Font-Awesome/" target="_blank">http://fortawesome.github.io/Font-Awesome/</a>
136
136
 
137
- Add below codes to layout `app/views/layout/application.html.erb`
137
+ In your `application.css`, include the css file:
138
138
 
139
- ``` erb
140
- ...
141
- <%= stylesheet_link_tag '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' %>
142
- ...
139
+ ```css
140
+ /*
141
+ *= require font-awesome
142
+ */
143
143
  ```
144
+ Then restart your webserver if it was previously running
144
145
 
145
146
  Examples
146
147
 
147
- ``` rb
148
+ ``` ruby
148
149
  fa_icon "user"
149
150
  # => <i class="fa fa-user"></i>
150
151
 
@@ -160,7 +161,7 @@ fa_icon "user 4x"
160
161
 
161
162
  #### HashHelper Examples
162
163
 
163
- ``` rb
164
+ ``` ruby
164
165
  options = { a: '1', b: '2', c: '3' }
165
166
 
166
167
  get_value :a, options
@@ -194,7 +195,7 @@ Add below codes to file `app/assets/javascripts/application.js`
194
195
 
195
196
  Use in View
196
197
 
197
- ``` rb
198
+ ``` ruby
198
199
  timeago '2014-11-21 09:38:27.256503'
199
200
  # => '2個月之前'
200
201
  ```
data/Rakefile CHANGED
@@ -14,10 +14,4 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
-
20
-
21
-
22
17
  Bundler::GemHelper.install_tasks
23
-
@@ -1,3 +1,4 @@
1
1
  $ ->
2
2
  # timeago
3
- $('abbr.timeago').timeago();
3
+ $('abbr.timeago').timeago()
4
+ $('abbr.timeago').tooltip()
@@ -1,111 +1,160 @@
1
1
  module BootstrapHelper
2
- #############
3
- ### ICONS ###
4
- #############
2
+
3
+ # --------- #
4
+ # - ICONS - #
5
+ # --------- #
5
6
 
6
7
  # Generates an icon.
7
- def bs_icon(icon, options = {})
8
- icon = %(glyphicon glyphicon-#{icon})
9
- add_css_class icon, options
10
- tag = pop_value :tag, options, :span
11
- content_tag tag, '', options
8
+ def bs_icon(icon, html_options = {})
9
+ html_options = html_options.stringify_keys
10
+ classes = ['glyphicon']
11
+ classes << "glyphicon-#{icon}"
12
+ if preset_class = html_options.delete('class')
13
+ classes << preset_class
14
+ end
15
+ html_options['class'] = classes * ' '
16
+
17
+ content_tag(:span, nil, html_options)
12
18
  end
13
19
 
14
- ###############
15
- ### BUTTONS ###
16
- ###############
20
+ # ---------------- #
21
+ # - LINK BUTTONS - #
22
+ # ---------------- #
17
23
 
18
- # Generates a button.
19
- def button(label = 'Button', options = {})
20
- html_button label, options
24
+ # Generates a link button.
25
+ def link_button(label = nil, options = nil, html_options = nil, &block)
26
+ html_options, options, label = options, label, capture(&block) if block_given?
27
+
28
+ html_options ||= {}
29
+ html_options = html_options.stringify_keys
30
+ html_options = normalize_button_options_for_bootstrap(html_options)
31
+
32
+ if (label_hidden = html_options.delete('label_hidden')) && !block_given?
33
+ label = content_tag :span, label, class: "hidden-#{label_hidden}"
34
+ end
35
+
36
+ if (icon = html_options.delete('icon')) && !block_given?
37
+ label = fa_icon(icon, text: label)
38
+ end
39
+
40
+ if html_options['confirm']
41
+ html_options['data-confirm'] = html_options.delete('confirm')
42
+ end
43
+
44
+ if html_options['disable_with']
45
+ html_options['data-disable-with'] = html_options.delete('disable_with')
46
+ end
47
+
48
+ link_to(label, options, html_options)
21
49
  end
22
50
 
23
- # Generates a html submit button.
24
- def html_button(label = 'Button', options = {})
25
- btn :html_button, label, options
51
+ def new_button(label = nil, options = nil, html_options = nil)
52
+ button_options = { icon: 'plus', color: 'primary' }
53
+ html_options ||= {}
54
+ html_options.update button_options
55
+
56
+ link_button(label, options, html_options)
26
57
  end
27
58
 
28
- # Generates a submit button.
29
- def submit_button(label = 'Submit', options = {})
30
- btn :submit_button, label, options
59
+ # Generates a link show button.
60
+ def show_button(label = nil, options = nil, html_options = nil)
61
+ button_options = { icon: 'search', color: 'info' }
62
+ html_options ||= {}
63
+ html_options.update button_options
64
+
65
+ link_button(label, options, html_options)
31
66
  end
32
67
 
33
- # Generates a reset button.
34
- def reset_button(label = 'Reset', options = {})
35
- btn :reset_button, label, options
68
+ # Generates a link edit button.
69
+ def edit_button(label = nil, options = nil, html_options = nil)
70
+ button_options = { icon: 'edit', color: 'warning' }
71
+ html_options ||= {}
72
+ html_options.update button_options
73
+
74
+ link_button(label, options, html_options)
36
75
  end
37
76
 
38
- # Generates a link submit button.
39
- def link_button(label = 'Submit', options = {})
40
- btn :link_button, label, options
77
+ # Generates a link destroy button.
78
+ def destroy_button(label = nil, options = nil, html_options = nil)
79
+ button_options = { icon: 'trash', color: 'danger', method: :delete, confirm: 'Are you sure?' }
80
+ html_options ||= {}
81
+ html_options.update button_options
82
+
83
+ link_button(label, options, html_options)
41
84
  end
42
85
 
43
- # Generates a input button.
44
- def input_button(label = 'Button', options = {})
45
- btn :input_button, label, options
86
+ # Generates a link back button.
87
+ def back_button(label = nil, options = nil, html_options = nil)
88
+ button_options = { icon: 'reply' }
89
+ html_options ||= {}
90
+ html_options.update button_options
91
+
92
+ link_button(label, options, html_options)
46
93
  end
47
94
 
48
- # Generates a input submit button.
49
- def input_submit(label = 'Submit', options = {})
50
- btn :input_submit, label, options
95
+ # Generates a link cancel button.
96
+ def cancel_button(label = nil, options = nil, html_options = nil)
97
+ button_options = { icon: 'ban' }
98
+ html_options ||= {}
99
+ html_options.update button_options
100
+
101
+ link_button(label, options, html_options)
51
102
  end
52
103
 
104
+ # ----------- #
105
+ # - BUTTONS - #
106
+ # ----------- #
107
+
53
108
  # Generates a button.
54
- def btn(type, label, options = {})
55
- add_css_class 'btn', options
109
+ def button(label = nil, html_options = nil, &block)
110
+ html_options, label = label, capture(&block) if block_given?
56
111
 
57
- color = pop_value :color, options, 'default'
58
- add_css_class(%(btn-#{color}), options) if color
112
+ html_options ||= {}
113
+ html_options = html_options.stringify_keys
114
+ html_options = normalize_button_options_for_bootstrap(html_options, :button)
59
115
 
60
- size = pop_value :size, options
61
- add_css_class(%(btn-#{size}), options) if size
116
+ html_options['type'] ||= 'button'
62
117
 
63
- block = pop_value :block, options
64
- add_css_class('btn-block', options) if block
118
+ if (label_hidden = html_options.delete('label_hidden')) && !block_given?
119
+ label = content_tag :span, label, class: "hidden-#{label_hidden}"
120
+ end
65
121
 
66
- add_active_class options
122
+ if (icon = html_options.delete('icon')) && !block_given?
123
+ label = fa_icon(icon, text: label)
124
+ end
67
125
 
68
- icon = pop_value :icon, options
69
- unless type.to_s.include? 'input'
70
- if icon
71
- label = fa_icon(icon) + ' ' + label
72
- end
126
+ if html_options['confirm']
127
+ html_options['data-confirm'] = html_options.delete('confirm')
73
128
  end
74
129
 
75
- create_button type, label, options
76
- end
77
-
78
- def create_button(type, label, options)
79
- url = pop_value :url, options, '#'
80
- case type
81
- when :html_button
82
- options[:type] = :button unless options[:type]
83
- button_tag label, options
84
- when :submit_button
85
- options[:name] = nil
86
- options[:type] = :submit
87
- button_tag label, options
88
- when :reset_button
89
- options[:name] = nil
90
- options[:type] = :reset
91
- button_tag label, options
92
- when :link_button
93
- options[:role] = :button
94
- link_to label, url, options
95
- when :input_button
96
- options[:value] = label
97
- options[:type] = :button
98
- tag 'input', options
99
- when :input_submit
100
- submit_tag label, options
101
- else
102
- # type code here
130
+ if html_options['disable_with']
131
+ html_options['data-disable-with'] = html_options.delete('disable_with')
103
132
  end
133
+
134
+ button_tag(label, html_options)
135
+ end
136
+
137
+ # Generates a submit button.
138
+ def submit_button(label = nil, html_options = nil)
139
+ button_options = { icon: 'check', color: 'primary', name: 'submit', type: 'submit' }
140
+ html_options ||= {}
141
+ html_options.update button_options
142
+
143
+ button(label, html_options)
104
144
  end
105
145
 
106
- ##############
107
- ### IMAGES ###
108
- ##############
146
+ # Generates a reset button.
147
+ def reset_button(label = nil, html_options = nil)
148
+ button_options = { icon: 'eraser', name: 'reset', type: 'reset' }
149
+ html_options ||= {}
150
+ html_options.update button_options
151
+
152
+ button(label, html_options)
153
+ end
154
+
155
+ # ---------- #
156
+ # - IMAGES - #
157
+ # ---------- #
109
158
 
110
159
  # Generates a responsive-friendly image tag
111
160
  def image_responsive(source, options = {})
@@ -131,9 +180,55 @@ module BootstrapHelper
131
180
  image_tag source, options
132
181
  end
133
182
 
134
- #################
135
- ### UTILITIES ###
136
- #################
183
+ # ------------ #
184
+ # - OVERRIDE - #
185
+ # ------------ #
186
+
187
+ # override rails helper: content_tag
188
+ def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
189
+ if block_given?
190
+ options = content_or_options_with_block if content_or_options_with_block.is_a? Hash
191
+ normalize_typography_options(options) if options
192
+ content_tag_string name, capture(&block), options, escape
193
+ else
194
+ normalize_typography_options(options) if options
195
+ content_tag_string name, content_or_options_with_block, options, escape
196
+ end
197
+ end
198
+
199
+ private
200
+
201
+ def normalize_button_options_for_bootstrap(html_options = {}, type = :link)
202
+ classes = ['btn']
203
+ if color = html_options.delete('color')
204
+ classes << "btn-#{color}"
205
+ else
206
+ classes << 'btn-default'
207
+ end
208
+ if size = html_options.delete('size')
209
+ classes << "btn-#{size}"
210
+ end
211
+ if block = html_options.delete('block')
212
+ classes << 'btn-block'
213
+ end
214
+ if active = html_options.delete('active')
215
+ classes << 'active'
216
+ end
217
+ if type == :link && html_options['disabled']
218
+ html_options.delete('disabled')
219
+ classes << 'disabled'
220
+ end
221
+ if preset_class = html_options.delete('class')
222
+ classes << preset_class
223
+ end
224
+
225
+ html_options['class'] = classes * ' '
226
+ html_options
227
+ end
228
+
229
+ # ------------- #
230
+ # - UTILITIES - #
231
+ # ------------- #
137
232
 
138
233
  # Appends new class names to the given options.
139
234
  def add_css_class(class_names, options)
@@ -192,20 +287,4 @@ module BootstrapHelper
192
287
  add_color_class options
193
288
  add_bgcolor_class options
194
289
  end
195
-
196
- ################
197
- ### OVERRIDE ###
198
- ################
199
-
200
- # override rails helper: content_tag
201
- def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
202
- if block_given?
203
- options = content_or_options_with_block if content_or_options_with_block.is_a? Hash
204
- normalize_typography_options(options) unless options.nil?
205
- content_tag_string name, capture(&block), options, escape
206
- else
207
- normalize_typography_options(options) unless options.nil?
208
- content_tag_string name, content_or_options_with_block, options, escape
209
- end
210
- end
211
290
  end
@@ -1,7 +1,8 @@
1
1
  module HashHelper
2
- ############
3
- ### Hash ###
4
- ############
2
+
3
+ # -------- #
4
+ # - Hash - #
5
+ # -------- #
5
6
 
6
7
  # Returns a specific value from the given hash (or the default value if not set).
7
8
  def get_value(key, hash, default_value = nil)
@@ -1,5 +1,5 @@
1
1
  module QrcodeHelper
2
- def qrcode(data='', options = {})
2
+ def qrcode(data = '', options = {})
3
3
  # Google API: https://google-developers.appspot.com/chart/infographics/docs/qr_codes
4
4
  width = pop_value :width, options, '200'
5
5
  output_encoding = pop_value :output_encoding, options
@@ -0,0 +1 @@
1
+ require 'bootstrap-sass'
@@ -0,0 +1 @@
1
+ require 'font-awesome-rails'
@@ -1,3 +1,3 @@
1
1
  module AndyRailsToolbox
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,3 +1,6 @@
1
+ require 'andy_rails_toolbox/font-awesome-rails'
2
+ require 'andy_rails_toolbox/bootstrap-sass'
3
+
1
4
  module AndyRailsToolbox
2
5
  class Engine < ::Rails::Engine
3
6
  initializer 'andy_rails_toolbox' do
metadata CHANGED
@@ -1,43 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: andy_rails_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChouAndy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bootstrap-sass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.3.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.3.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: sass-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: font-awesome-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.3'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 4.3.0.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '4.3'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 4.3.0.0
13
67
  - !ruby/object:Gem::Dependency
14
68
  name: redcarpet
15
69
  requirement: !ruby/object:Gem::Requirement
16
70
  requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '3.2'
17
74
  - - ">="
18
75
  - !ruby/object:Gem::Version
19
- version: '0'
76
+ version: 3.2.3
20
77
  type: :runtime
21
78
  prerelease: false
22
79
  version_requirements: !ruby/object:Gem::Requirement
23
80
  requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.2'
24
84
  - - ">="
25
85
  - !ruby/object:Gem::Version
26
- version: '0'
86
+ version: 3.2.3
27
87
  - !ruby/object:Gem::Dependency
28
88
  name: pygments.rb
29
89
  requirement: !ruby/object:Gem::Requirement
30
90
  requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '0.6'
31
94
  - - ">="
32
95
  - !ruby/object:Gem::Version
33
- version: '0'
96
+ version: 0.6.3
34
97
  type: :runtime
35
98
  prerelease: false
36
99
  version_requirements: !ruby/object:Gem::Requirement
37
100
  requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
38
104
  - - ">="
39
105
  - !ruby/object:Gem::Version
40
- version: '0'
106
+ version: 0.6.3
41
107
  description: Andy Rails Toolbox includes many useful helpers for rails development.
42
108
  email:
43
109
  - chouandy625@gmail.com
@@ -52,12 +118,13 @@ files:
52
118
  - app/assets/javascripts/jquery.timeago.load.coffee
53
119
  - app/assets/javascripts/jquery.timeago.zh-TW.js
54
120
  - app/helpers/bootstrap_helper.rb
55
- - app/helpers/font_awesome_helper.rb
56
121
  - app/helpers/hash_helper.rb
57
122
  - app/helpers/markdown_helper.rb
58
123
  - app/helpers/qrcode_helper.rb
59
124
  - app/helpers/timeago_helper.rb
60
125
  - lib/andy_rails_toolbox.rb
126
+ - lib/andy_rails_toolbox/bootstrap-sass.rb
127
+ - lib/andy_rails_toolbox/font-awesome-rails.rb
61
128
  - lib/andy_rails_toolbox/version.rb
62
129
  homepage: https://github.com/ChouAndy/andy_rails_toolbox
63
130
  licenses:
@@ -71,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
138
  requirements:
72
139
  - - ">="
73
140
  - !ruby/object:Gem::Version
74
- version: '0'
141
+ version: 1.9.3
75
142
  required_rubygems_version: !ruby/object:Gem::Requirement
76
143
  requirements:
77
144
  - - ">="
@@ -79,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
146
  version: '0'
80
147
  requirements: []
81
148
  rubyforge_project:
82
- rubygems_version: 2.4.5
149
+ rubygems_version: 2.4.7
83
150
  signing_key:
84
151
  specification_version: 4
85
152
  summary: Includes many useful helpers for rails development.
@@ -1,94 +0,0 @@
1
- module FontAwesomeHelper
2
- # Creates an icon tag given an icon name and possible icon
3
- # modifiers.
4
- #
5
- # Examples
6
- #
7
- # fa_icon "camera-retro"
8
- # # => <i class="fa fa-camera-retro"></i>
9
- #
10
- # fa_icon "camera-retro", text: "Take a photo"
11
- # # => <i class="fa fa-camera-retro"></i> Take a photo
12
- # fa_icon "chevron-right", text: "Get started", right: true
13
- # # => Get started <i class="fa fa-chevron-right"></i>
14
- #
15
- # fa_icon "camera-retro 2x"
16
- # # => <i class="fa fa-camera-retro fa-2x"></i>
17
- # fa_icon ["camera-retro", "4x"]
18
- # # => <i class="fa fa-camera-retro fa-4x"></i>
19
- # fa_icon "spinner spin lg"
20
- # # => <i class="fa fa-spinner fa-spin fa-lg">
21
- #
22
- # fa_icon "quote-left 4x", class: "pull-left"
23
- # # => <i class="fa fa-quote-left fa-4x pull-left"></i>
24
- #
25
- # fa_icon "user", data: { id: 123 }
26
- # # => <i class="fa fa-user" data-id="123"></i>
27
- #
28
- # content_tag(:li, fa_icon("check li", text: "Bulleted list item"))
29
- # # => <li><i class="fa fa-check fa-li"></i> Bulleted list item</li>
30
- def fa_icon(names = 'flag', options = {})
31
- classes = ['fa']
32
- classes.concat Private.icon_names(names)
33
- classes.concat Array(options.delete(:class))
34
- text = options.delete(:text)
35
- right_icon = options.delete(:right)
36
- icon = content_tag(:i, nil, options.merge(class: classes))
37
- Private.icon_join(icon, text, right_icon)
38
- end
39
-
40
- # Creates an stack set of icon tags given a base icon name, a main icon
41
- # name, and possible icon modifiers.
42
- #
43
- # Examples
44
- #
45
- # fa_stacked_icon "twitter", base: "square-o"
46
- # # => <span class="fa-stack">
47
- # # => <i class="fa fa-square-o fa-stack-2x"></i>
48
- # # => <i class="fa fa-twitter fa-stack-1x"></i>
49
- # # => </span>
50
- #
51
- # fa_stacked_icon "terminal inverse", base: "square", class: "pull-right", text: "Hi!"
52
- # # => <span class="fa-stack pull-right">
53
- # # => <i class="fa fa-square fa-stack-2x"></i>
54
- # # => <i class="fa fa-terminal fa-inverse fa-stack-1x"></i>
55
- # # => </span> Hi!
56
- #
57
- # fa_stacked_icon "camera", base: "ban-circle", reverse: true
58
- # # => <span class="fa-stack">
59
- # # => <i class="fa fa-camera fa-stack-1x"></i>
60
- # # => <i class="fa fa-ban-circle fa-stack-2x"></i>
61
- # # => </span>
62
- def fa_stacked_icon(names = 'flag', options = {})
63
- classes = Private.icon_names('stack').concat(Array(options.delete(:class)))
64
- base_names = Private.array_value(options.delete(:base) || 'square-o').push('stack-2x')
65
- names = Private.array_value(names).push('stack-1x')
66
- base = fa_icon(base_names, options.delete(:base_options) || {})
67
- icon = fa_icon(names, options.delete(:icon_options) || {})
68
- icons = [base, icon]
69
- icons.reverse! if options.delete(:reverse)
70
- text = options.delete(:text)
71
- right_icon = options.delete(:right)
72
- stacked_icon = content_tag(:span, safe_join(icons), options.merge(class: classes))
73
- Private.icon_join(stacked_icon, text, right_icon)
74
- end
75
-
76
- module Private
77
- extend ActionView::Helpers::OutputSafetyHelper
78
-
79
- def self.icon_join(icon, text, reverse_order = false)
80
- return icon if text.blank?
81
- elements = [icon, ERB::Util.html_escape(text)]
82
- elements.reverse! if reverse_order
83
- safe_join(elements, ' ')
84
- end
85
-
86
- def self.icon_names(names = [])
87
- array_value(names).map { |n| "fa-#{n}" }
88
- end
89
-
90
- def self.array_value(value = [])
91
- value.is_a?(Array) ? value : value.to_s.split(/\s+/)
92
- end
93
- end
94
- end