material_icons-rails 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cd5c5528091a8f16e585041aa505a3d1ac9d149
4
- data.tar.gz: 362452d6d8c6f2787e51a781da9c87c9734d86dd
3
+ metadata.gz: 0e2532c41d26aca45e0978cc5d9c2c2cb43e5dec
4
+ data.tar.gz: 33c17ad102c472adc506c06e7ed7d9455e604929
5
5
  SHA512:
6
- metadata.gz: a76c4cf8c6315d856961ceceae91d0afa6dd2f728faf29b22036b71d81671821cc40e402910ee06a5949306a4c2fd4716a2e6cc19c0181f9b2d764fb7c91d6cc
7
- data.tar.gz: 1e23e437984c966c2fbec3c4cdb50849b26cb5b1552d5b9379b91790be55380640f254722d741cd484ac6edb87bb6b29ceca6a5c07105255bba8130e917442b4
6
+ metadata.gz: 4d9553732dab37be9a9c2289d4bba4c12ff07dfc2f0864946e8cdb332c796caf4ba448a51fbb1d7f0578d5c5f98533270631f37ba2feef61f73c3084c5259d00
7
+ data.tar.gz: bcc19bb764fbcc0153d0caa06bf5b9ecc942aabeaaeb0b21eb248ef0d9de08faa0591e360afdc56447040f056221f33d47bcb45f8a7a4c8db8feebd7ac9577af
@@ -14,7 +14,7 @@
14
14
  font-family: 'Material Icons';
15
15
  font-weight: normal;
16
16
  font-style: normal;
17
- font-size: 18px;
17
+ font-size: 1em;
18
18
  display: inline-block;
19
19
  width: 1em;
20
20
  height: 1em;
@@ -2,7 +2,7 @@ module MaterialIcons
2
2
  module Rails
3
3
  module IconHelper
4
4
  def material_icon(icon, options = {})
5
- build_icon_content_tag(icon, options)
5
+ MaterialIcon.new(icon, options).to_html
6
6
  end
7
7
 
8
8
  # TO-DO:
@@ -16,100 +16,9 @@ module MaterialIcons
16
16
  # http://codepen.io/joereza/pen/ufswb
17
17
 
18
18
  def material_icon_stack(icons, stack_options = {})
19
- build_icon_container_content_tag(normalize_stack_icons(icons), stack_options)
20
- end
21
-
22
- # def material_icon_with_badge(icon, options = {})
23
- # options = options.with_indifferent_access
24
- # count = options.delete(:count)
25
- # content_tag(:span, fa_icon(icon, options), :'data-count' => count)
26
- # end
27
-
28
- # def material_icon_stack_with_badge(icon, options = {})
29
- # options = options.with_indifferent_access
30
- # count = options.delete(:count)
31
- # content_tag(:span, fa_stacked_icon(icon, options), :'data-count' => count)
32
- # end
33
-
34
- private
35
-
36
- def normalize_stack_icons(icons)
37
- case icons
38
- when String, Symbol
39
- [icons]
40
- when Array
41
- icons.zip(icons.length.times.collect{ {} })
42
- when Hash
43
- icons
44
- else
45
- # add error message here
46
- raise ArgumentError
47
- end
48
- end
49
-
50
- def merge_default_icon_options(options)
51
- {
52
- tag: 'i',
53
- size: '18px',
54
- text: '',
55
- }.merge(options.symbolize_keys)
56
- end
57
-
58
- def normalize_icon_options(options)
59
- options[:size] = {'1x' => '18px', '2x' => '24px', '3x' => '36px', '4x' => '48px'}[options[:size]] if options[:size].match(/^[1-4]x$/)
60
- options[:size] = "#{options[:size]}px" if options[:size].to_i.to_s == options[:size]
61
- options[:class] = Array(options[:class]).concat(['material-icons']).join(' ')
62
- options
63
- end
64
-
65
- def prep_icon_options(options)
66
- normalize_icon_options(merge_default_icon_options(options))
67
- end
68
-
69
- def build_icon_content_tag(icon, options)
70
- options = prep_icon_options(options)
71
-
72
- content_tag(options[:tag], icon, {
73
- class: options[:class],
74
- style: "font-size: #{options[:size]};",
75
- }) + options[:text]
76
- end
77
-
78
-
79
- def merge_default_icon_container_options(options)
80
- {
81
- tag: 'span',
82
- text: '',
83
- }.merge(options.symbolize_keys)
84
- end
85
-
86
- def normalize_icon_container_options(options)
87
- options[:class] = Array(options[:class]).concat(['material-icons-stack']).join(' ')
88
- options
89
- end
90
-
91
- def prep_icon_container_options(options)
92
- normalize_icon_container_options(merge_default_icon_container_options(options))
93
- end
94
-
95
- def build_icon_container_content_tag(icons, options)
96
- options = prep_icon_container_options(options)
97
-
98
- content_tag(
99
- options[:tag],
100
- icons.collect do |icon, options|
101
- # add error message here
102
- raise ArgumentError unless options.is_a?(Hash)
103
- # ignore text per icon on a stack
104
- build_icon_content_tag(icon, options.except(:text))
105
- end.join.html_safe + options[:text],
106
- {
107
- class: options[:class],
108
- style: "font-size: #{options[:size]};",
109
- }
110
- )
19
+ MaterialIconStack.new(icons, stack_options).to_html
111
20
  end
112
21
 
113
22
  end
114
23
  end
115
- end
24
+ end
@@ -1,5 +1,7 @@
1
1
  module MaterialIcons
2
2
  module Rails
3
- require_relative 'material_icons-rails/engine'
3
+ require_relative 'material_icons/rails/engine'
4
+ require_relative 'material_icons/rails/material_icon'
5
+ require_relative 'material_icons/rails/material_icon_stack'
4
6
  end
5
7
  end
@@ -0,0 +1,51 @@
1
+ module MaterialIcons
2
+ module Rails
3
+ class MaterialIcon < OpenStruct
4
+
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ cattr_accessor(:style_options_attributes) { [:class, :style] }
8
+
9
+ def initialize(icon, options = {})
10
+ super(options.merge({icon: icon.to_sym}))
11
+ fill_defaults
12
+ normalize
13
+ end
14
+
15
+ def to_html
16
+ content_tag(self[:tag], self[:icon], style_options_attributes.collect{ |a| [a, self[a] || self.send(a)] }.to_h) + self[:text]
17
+ end
18
+
19
+ def style
20
+ {
21
+ 'font-size': size,
22
+ }.collect{ |k, v| "#{k}: #{v}"}.join('; ')
23
+ end
24
+
25
+ private
26
+
27
+ def fill_defaults
28
+ {
29
+ tag: 'i',
30
+ text: '',
31
+ size: '1em',
32
+ }.each{ |k, v| self[k] = v unless self[k].present? }
33
+ end
34
+
35
+ def normalize
36
+ self[:size] = case self[:size]
37
+ when /^\d+x$/ then "#{size.to_i}em"
38
+ when self[:size].to_i.to_s then "#{size}px"
39
+ else self[:size]
40
+ end
41
+
42
+ self[:class] = case self[:class]
43
+ when Array then self[:class]
44
+ when String then self[:class].split(' ')
45
+ else []
46
+ end.concat(['material-icons'])
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,46 @@
1
+ module MaterialIcons
2
+ module Rails
3
+ class MaterialIconStack < OpenStruct
4
+
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ cattr_accessor(:style_options_attributes) { [:class, :style] }
8
+
9
+ def initialize(icons, options = {})
10
+ material_icons = icons.collect{ |icon, options| MaterialIcon.new(icon, options.except(:text)) }
11
+ super(options.merge({icons: material_icons}))
12
+ fill_defaults
13
+ normalize
14
+ end
15
+
16
+ def to_html
17
+ content_tag(self[:tag], self[:icons].collect(&:to_html).join.html_safe + self[:text], style_options_attributes.collect{ |a| [a, self[a] || self.send(a)] }.to_h)
18
+ end
19
+
20
+ private
21
+
22
+ def fill_defaults
23
+ {
24
+ tag: 'span',
25
+ text: '',
26
+ size: '1em',
27
+ }.each{ |k, v| self[k] = v unless self[k].present? }
28
+ end
29
+
30
+ def normalize
31
+ self[:size] = case self[:size]
32
+ when /^\d+x$/ then "#{size.to_i}em"
33
+ when self[:size].to_i.to_s then "#{size}px"
34
+ else self[:size]
35
+ end
36
+
37
+ self[:class] = case self[:class]
38
+ when Array then self[:class]
39
+ when String then self[:class].split(' ')
40
+ else []
41
+ end.concat(['material-icons-stack'])
42
+ end
43
+
44
+ end
45
+ end
46
+ end
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module MaterialIcons
2
2
  module Rails
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  FONT_VERSION = '2.2.0'
5
5
  end
6
6
  end
@@ -44,3 +44,83 @@
44
44
   (0.1ms) rollback transaction
45
45
   (0.2ms) begin transaction
46
46
   (0.1ms) rollback transaction
47
+  (0.2ms) begin transaction
48
+  (0.1ms) rollback transaction
49
+  (0.3ms) begin transaction
50
+  (0.1ms) rollback transaction
51
+  (0.2ms) begin transaction
52
+  (0.0ms) rollback transaction
53
+  (0.2ms) begin transaction
54
+  (0.0ms) rollback transaction
55
+  (0.2ms) begin transaction
56
+  (0.0ms) rollback transaction
57
+  (0.2ms) begin transaction
58
+  (0.1ms) rollback transaction
59
+  (0.2ms) begin transaction
60
+  (0.0ms) rollback transaction
61
+  (0.2ms) begin transaction
62
+  (0.1ms) rollback transaction
63
+  (0.2ms) begin transaction
64
+  (0.1ms) rollback transaction
65
+  (0.2ms) begin transaction
66
+  (0.1ms) rollback transaction
67
+  (0.2ms) begin transaction
68
+  (0.0ms) rollback transaction
69
+  (0.2ms) begin transaction
70
+  (0.1ms) rollback transaction
71
+  (0.2ms) begin transaction
72
+  (0.0ms) rollback transaction
73
+  (0.3ms) begin transaction
74
+  (0.1ms) rollback transaction
75
+  (0.2ms) begin transaction
76
+  (0.0ms) rollback transaction
77
+  (0.3ms) begin transaction
78
+  (0.1ms) rollback transaction
79
+  (0.2ms) begin transaction
80
+  (0.1ms) rollback transaction
81
+  (0.2ms) begin transaction
82
+  (0.1ms) rollback transaction
83
+  (0.2ms) begin transaction
84
+  (0.1ms) rollback transaction
85
+  (0.2ms) begin transaction
86
+  (0.1ms) rollback transaction
87
+  (0.2ms) begin transaction
88
+  (0.1ms) rollback transaction
89
+  (0.2ms) begin transaction
90
+  (0.1ms) rollback transaction
91
+  (0.2ms) begin transaction
92
+  (0.1ms) rollback transaction
93
+  (0.2ms) begin transaction
94
+  (0.1ms) rollback transaction
95
+  (0.2ms) begin transaction
96
+  (0.1ms) rollback transaction
97
+  (0.2ms) begin transaction
98
+  (0.0ms) rollback transaction
99
+  (0.2ms) begin transaction
100
+  (0.0ms) rollback transaction
101
+  (0.2ms) begin transaction
102
+  (0.1ms) rollback transaction
103
+  (0.2ms) begin transaction
104
+  (0.1ms) rollback transaction
105
+  (0.2ms) begin transaction
106
+  (0.0ms) rollback transaction
107
+  (0.2ms) begin transaction
108
+  (0.1ms) rollback transaction
109
+  (0.2ms) begin transaction
110
+  (0.1ms) rollback transaction
111
+  (0.2ms) begin transaction
112
+  (0.1ms) rollback transaction
113
+  (0.2ms) begin transaction
114
+  (0.0ms) rollback transaction
115
+  (0.2ms) begin transaction
116
+  (0.0ms) rollback transaction
117
+  (0.2ms) begin transaction
118
+  (0.0ms) rollback transaction
119
+  (0.2ms) begin transaction
120
+  (0.0ms) rollback transaction
121
+  (0.2ms) begin transaction
122
+  (0.1ms) rollback transaction
123
+  (0.2ms) begin transaction
124
+  (0.3ms) rollback transaction
125
+  (0.2ms) begin transaction
126
+  (0.0ms) rollback transaction
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  RSpec.describe MaterialIcons::Rails::IconHelper, type: :helper do
4
4
  describe 'material_icon' do
5
5
  it 'builds icon tag' do
6
- expect(material_icon(:face)).to eq('<i class="material-icons" style="font-size: 18px;">face</i>')
6
+ expect(material_icon(:face)).to eq('<i class="material-icons" style="font-size: 1em">face</i>')
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material_icons-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - chaunce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -83,7 +83,9 @@ files:
83
83
  - app/assets/stylesheets/material-icons.css
84
84
  - app/helpers/material_icons/rails/icon_helper.rb
85
85
  - lib/material_icons-rails.rb
86
- - lib/material_icons-rails/engine.rb
86
+ - lib/material_icons/rails/engine.rb
87
+ - lib/material_icons/rails/material_icon.rb
88
+ - lib/material_icons/rails/material_icon_stack.rb
87
89
  - lib/version.rb
88
90
  - spec/Rakefile
89
91
  - spec/dummy/Rakefile