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 +4 -4
- data/README.md +4 -0
- data/app/assets/stylesheets/material-icons.css +14 -7
- data/lib/material_icons-rails/icon_helper.rb +107 -3
- data/lib/version.rb +1 -1
- data/spec/dummy/log/test.log +6 -0
- data/spec/lib/material_icons-rails/icon_helper_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c0c2e915283b52a968114fb2a37e1c5bea4df76
|
4
|
+
data.tar.gz: 6da84ae7e0d7d792df14874b936945cf694bc247
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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(
|
5
|
-
|
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
data/spec/dummy/log/test.log
CHANGED
@@ -36,3 +36,9 @@
|
|
36
36
|
[1m[35m (0.1ms)[0m rollback transaction
|
37
37
|
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
38
38
|
[1m[35m (0.0ms)[0m rollback transaction
|
39
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
40
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
41
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
42
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
43
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
44
|
+
[1m[35m (0.1ms)[0m 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
|
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-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|