material_icons 0.0.6 → 1.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module MaterialIcons
2
+ #
3
+ # Helper of material icons. This method return a singleton MaterialIcon class
4
+ # to get icons in the UI.
5
+ #
6
+ module MaterialIconHelper
7
+ # Singleton
8
+ @@material_icon = MaterialIcon.new
9
+
10
+ #
11
+ # Reset the previous values of the MaterialIcon class and return
12
+ # the object to render a new icon.
13
+ #
14
+ # == Returns:
15
+ # MaterialIcon instance
16
+ #
17
+ def material_icon
18
+ @@material_icon.reset
19
+ end
20
+
21
+ # Typeless alias method
22
+ alias_method :mi, :material_icon
23
+ end
24
+ end
@@ -0,0 +1,119 @@
1
+ #
2
+ # This class help the creation of material icons in the UI.
3
+ #
4
+ class MaterialIcon
5
+ # To use content_tag
6
+ include ActionView::Helpers::TagHelper
7
+
8
+ # Undefined method will ref to the icon.
9
+ def method_missing(name)
10
+ @icon = name
11
+ self
12
+ end
13
+
14
+ #
15
+ # Reset will set all variables to nil
16
+ #
17
+ def reset
18
+ @icon, @rotation, @size, @html, @style = [nil] * 5
19
+ self
20
+ end
21
+
22
+ #
23
+ # Define rotate methods
24
+ #
25
+ %w(r90 r180 r270 flip_horizontal flip_vertical).each do |rotation|
26
+ define_method(rotation) do
27
+ @rotation = rotation.gsub('_', '-')
28
+ self
29
+ end
30
+ end
31
+
32
+ #
33
+ # Define size methods
34
+ #
35
+ %w(md_18 md_24 md_36 md_48).each do |size|
36
+ define_method(size) do
37
+ @size = size.gsub('_', '-')
38
+ self
39
+ end
40
+ end
41
+
42
+ #
43
+ # Add a CSS class to :i tag
44
+ #
45
+ # == Paremeters:
46
+ # css_class::
47
+ # String with CSS classes
48
+ #
49
+ # == Returns:
50
+ # MaterialIcon instance
51
+ #
52
+ def css_class(css_class = '')
53
+ @css_class = css_class
54
+ self
55
+ end
56
+
57
+ #
58
+ # Add CSS properties to :i tag
59
+ #
60
+ # == Paremeters:
61
+ # style::
62
+ # String with CSS rules
63
+ #
64
+ # == Returns:
65
+ # MaterialIcon instance
66
+ #
67
+ def style(style = '')
68
+ @style = style
69
+ self
70
+ end
71
+
72
+ #
73
+ # Add HTML options to :i tag.
74
+ #
75
+ # == Paremeters:
76
+ # html::
77
+ # Hash with options to add to :i tag. For example:
78
+ # { data: { id: 1 } }
79
+ #
80
+ # == Returns:
81
+ # MaterialIcon instance
82
+ #
83
+ def html(html = {})
84
+ @html = html
85
+ self
86
+ end
87
+
88
+ #
89
+ # Check based on rails config if the selected mode is unicode
90
+ #
91
+ def unicode?
92
+ MaterialIcons.unicode
93
+ end
94
+
95
+ #
96
+ # Create the HTML code for the icon. This method check if selected mode is
97
+ # unicode or ligatures.
98
+ #
99
+ # == Returns:
100
+ # Safe string
101
+ #
102
+ def to_s
103
+ # Sanitize html
104
+ @html = @html.nil? || !@html.is_a?(Hash) ? {} : @html
105
+
106
+ # Create the icon
107
+ if unicode?
108
+ content_tag(:i, '',
109
+ @html.merge(
110
+ style: @style,
111
+ class: "mi #{@size} #{@rotation} #{@icon} #{@css_class}"))
112
+ else
113
+ content_tag(:i, "#{@icon}",
114
+ @html.merge(
115
+ style: @style,
116
+ class: "mi #{@size} #{@rotation} #{@css_class}"))
117
+ end
118
+ end
119
+ end
@@ -1,3 +1,17 @@
1
1
  require 'material_icons/version'
2
2
  # Only require if rails is available
3
3
  require 'material_icons/engine' if defined?(::Rails)
4
+
5
+ #
6
+ # Base module. This module defines the configuration of the gem.
7
+ #
8
+ module MaterialIcons
9
+ # Use unicode icons
10
+ mattr_accessor :unicode
11
+ @unicode = false
12
+
13
+ # Use the config from an initializer
14
+ def self.setup
15
+ yield self
16
+ end
17
+ end
@@ -1,7 +1,8 @@
1
+ #
2
+ # Engine to add to main rails app
3
+ #
1
4
  module MaterialIcons
2
- module Rails
3
- # Set the base engine to connect with rails
4
- class Engine < ::Rails::Engine
5
- end
5
+ # Set the base engine to connect with rails
6
+ class Engine < ::Rails::Engine
6
7
  end
7
8
  end
@@ -1,7 +1,8 @@
1
+ #
2
+ # Define the versions of the gem and Google material icons.
3
+ #
1
4
  module MaterialIcons
2
- module Rails
3
- # Version for the library and the gem
4
- MATERIAL_ICONS_VERSION = '2.0.0'
5
- VERSION = '0.0.6'
6
- end
5
+ # Version for the library and the gem
6
+ MATERIAL_ICONS_VERSION = '2.0.0'
7
+ VERSION = '1.0.0rc1'
7
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material_icons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel M Miguel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Add Google Material Icons in your Rails projects easily. It is a library
14
14
  with +750 icons ;)
@@ -27,6 +27,8 @@ files:
27
27
  - app/assets/fonts/MaterialIcons-Regular.woff2
28
28
  - app/assets/stylesheets/material_icons.css.erb
29
29
  - app/assets/stylesheets/material_icons_unicode.css.erb
30
+ - app/helpers/material_icons/material_icon_helper.rb
31
+ - app/models/material_icon.rb
30
32
  - lib/material_icons.rb
31
33
  - lib/material_icons/engine.rb
32
34
  - lib/material_icons/version.rb
@@ -46,9 +48,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
48
  version: '0'
47
49
  required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  requirements:
49
- - - ">="
51
+ - - ">"
50
52
  - !ruby/object:Gem::Version
51
- version: '0'
53
+ version: 1.3.1
52
54
  requirements: []
53
55
  rubyforge_project:
54
56
  rubygems_version: 2.4.6