material_icons-rails 0.0.1 → 0.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: 812cc47a3fbed6dead7aaa00a2989f88e4f9b35d
4
- data.tar.gz: c9e3013dbd101da95bb211ef37308f2d20476338
3
+ metadata.gz: 2c0c2e915283b52a968114fb2a37e1c5bea4df76
4
+ data.tar.gz: 6da84ae7e0d7d792df14874b936945cf694bc247
5
5
  SHA512:
6
- metadata.gz: 5c7c3e6351eadb877c8e0072a1a0fd2efc0d58f91ca19b4a3b92a082701030f2417b36f8eb00ad89be12e09db177c5f791acbc5a39390ca6cd2b89c25d692c33
7
- data.tar.gz: aaac31f465f718284d6d70a19a2c6ee990aec7c0e03ed21e22cfd8bc1488816d3826a2176f96115f88308903b1b47a80228ac81fae30ab447eb082febf577bfe
6
+ metadata.gz: 97250c280567d66f3bed03c3c785de4eb0956c60cde89ac501070332d6dfd9d29edd690a656ffa6a300dbb3e8e0a43f2958bb854124186babc24f2549b3276f8
7
+ data.tar.gz: 95bca3c40baa95ee1e5ddc6f7ea7c956684395d451e4c7670845cf397f5b36a007fd112a1d64d613266bba6126983db1473263e0c8040c891fe04a6ccb9ccb3c
data/README.md CHANGED
@@ -19,3 +19,7 @@ use a form helper in a view
19
19
  material_icon(:face)
20
20
  material_icon(:face, class: 'one-in-your-own-css and-another')
21
21
  material_icon(:face, class: 'red', tag: 'span')
22
+
23
+ valid options
24
+
25
+ `:size` a string for `font-size`, an integer for `px`, `1x` - `4x` for pre-defined sizes
@@ -14,7 +14,7 @@
14
14
  font-family: 'Material Icons';
15
15
  font-weight: normal;
16
16
  font-style: normal;
17
- font-size: 24px; /* Preferred icon size */
17
+ font-size: 18px;
18
18
  display: inline-block;
19
19
  width: 1em;
20
20
  height: 1em;
@@ -25,14 +25,21 @@
25
25
  white-space: nowrap;
26
26
  direction: ltr;
27
27
 
28
- /* Support for all WebKit browsers. */
29
28
  -webkit-font-smoothing: antialiased;
30
- /* Support for Safari and Chrome. */
31
29
  text-rendering: optimizeLegibility;
32
-
33
- /* Support for Firefox. */
34
30
  -moz-osx-font-smoothing: grayscale;
35
-
36
- /* Support for IE. */
37
31
  font-feature-settings: 'liga';
38
32
  }
33
+
34
+ .material-icons-stack {
35
+ position: relative;
36
+ }
37
+
38
+ .material-icons-stack .material-icons {
39
+ position: absolute;
40
+ left: 0;
41
+ }
42
+
43
+ .material-icons-stack .material-icons:first-child {
44
+ position: relative;
45
+ }
@@ -1,10 +1,114 @@
1
1
  module MaterialIcons
2
2
  module Rails
3
3
  module IconHelper
4
- def material_icon(names, options = {})
5
- options = { tag: 'i' }.merge(options.symbolize_keys)
6
- content_tag(options[:tag], names, { class: Array(options[:class]).concat(['material-icons']).join(' ') })
4
+ def material_icon(icon, options = {})
5
+ build_icon_content_tag(icon, options)
7
6
  end
7
+
8
+ # TO-DO:
9
+ # - stacking
10
+ # - badge
11
+ # - dark, light, color, inactive
12
+ # - rotate: static/animated
13
+
14
+ # http://codepen.io/johnstuif/pen/pvLgYp
15
+ # http://codepen.io/joereza/pen/ufswb
16
+
17
+ def material_icon_stack(icons, stack_options = {})
18
+ build_icon_container_content_tag(normalize_stack_icons(icons), stack_options)
19
+ end
20
+
21
+ # def material_icon_with_badge(icon, options = {})
22
+ # options = options.with_indifferent_access
23
+ # count = options.delete(:count)
24
+ # content_tag(:span, fa_icon(icon, options), :'data-count' => count)
25
+ # end
26
+
27
+ # def material_icon_stack_with_badge(icon, options = {})
28
+ # options = options.with_indifferent_access
29
+ # count = options.delete(:count)
30
+ # content_tag(:span, fa_stacked_icon(icon, options), :'data-count' => count)
31
+ # end
32
+
33
+ private
34
+
35
+ def normalize_stack_icons(icons)
36
+ case icons
37
+ when String, Symbol
38
+ [icons]
39
+ when Array
40
+ icons.zip(icons.length.times.collect{ {} })
41
+ when Hash
42
+ icons
43
+ else
44
+ # add error message here
45
+ raise ArgumentError
46
+ end
47
+ end
48
+
49
+ def merge_default_icon_options(options)
50
+ {
51
+ tag: 'i',
52
+ size: '18px',
53
+ text: '',
54
+ }.merge(options.symbolize_keys)
55
+ end
56
+
57
+ def normalize_icon_options(options)
58
+ options[:size] = {'1x' => '18px', '2x' => '24px', '3x' => '36px', '4x' => '48px'}[options[:size]] if options[:size].match(/^[1-4]x$/)
59
+ options[:size] = "#{options[:size]}px" if options[:size].to_i.to_s == options[:size]
60
+ options[:class] = Array(options[:class]).concat(['material-icons']).join(' ')
61
+ options
62
+ end
63
+
64
+ def prep_icon_options(options)
65
+ normalize_icon_options(merge_default_icon_options(options))
66
+ end
67
+
68
+ def build_icon_content_tag(icon, options)
69
+ options = prep_icon_options(options)
70
+
71
+ content_tag(options[:tag], icon, {
72
+ class: options[:class],
73
+ style: "font-size: #{options[:size]};",
74
+ }) + options[:text]
75
+ end
76
+
77
+
78
+ def merge_default_icon_container_options(options)
79
+ {
80
+ tag: 'span',
81
+ text: '',
82
+ }.merge(options.symbolize_keys)
83
+ end
84
+
85
+ def normalize_icon_container_options(options)
86
+ options[:class] = Array(options[:class]).concat(['material-icons-stack']).join(' ')
87
+ options
88
+ end
89
+
90
+ def prep_icon_container_options(options)
91
+ normalize_icon_container_options(merge_default_icon_container_options(options))
92
+ end
93
+
94
+ def build_icon_container_content_tag(icons, options)
95
+ options = prep_icon_container_options(options)
96
+
97
+ content_tag(
98
+ options[:tag],
99
+ icons.collect do |icon, options|
100
+ # add error message here
101
+ raise ArgumentError unless options.is_a?(Hash)
102
+ # ignore text per icon on a stack
103
+ build_icon_content_tag(icon, options.except(:text))
104
+ end.join.html_safe + options[:text],
105
+ {
106
+ class: options[:class],
107
+ style: "font-size: #{options[:size]};",
108
+ }
109
+ )
110
+ end
111
+
8
112
  end
9
113
  end
10
114
  end
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module MaterialIcons
2
2
  module Rails
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  FONT_VERSION = '2.2.0'
5
5
  end
6
6
  end
@@ -36,3 +36,9 @@
36
36
   (0.1ms) rollback transaction
37
37
   (0.2ms) begin transaction
38
38
   (0.0ms) rollback transaction
39
+  (0.2ms) begin transaction
40
+  (0.1ms) rollback transaction
41
+  (0.2ms) begin transaction
42
+  (0.0ms) rollback transaction
43
+  (0.3ms) begin transaction
44
+  (0.1ms) 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">face</i>')
6
+ expect(material_icon(:face)).to eq('<i class="material-icons" style="font-size: 18px;">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.0.1
4
+ version: 0.1.0
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-17 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails