icomoon2sass 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9c2c51780ca9aa2519680c498b3902f2479c08b
4
+ data.tar.gz: 95af4db26408dc589dc293375abe2b5e4d12e6c6
5
+ SHA512:
6
+ metadata.gz: ff4710638cd3c72b98f71062d522111b614a6f5f83522659a31b25fb1ffa8a1a3812b3826d98c533a406558e2046325d5e73b57f3edfc596c0d0419604fb78e9
7
+ data.tar.gz: 940d4eebf92396248ced4daf6ee771e20156c3ad0627e02053139754ec5ef1c98485070fcc3972b445fbc654df43c4d96f1150c756bae87503783b2b318d2a03
data/bin/icomoon2sass ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+ require 'run'
@@ -0,0 +1,14 @@
1
+ class Icomoon2Sass::Archive
2
+ attr_reader :files
3
+
4
+ EXTRACTABLE_PATTERN = /(fonts\/.*|selection\.js|style\.css)/
5
+
6
+ def font_files
7
+ @_font_files ||= @files.reject {|key| !key.match(/fonts/) }
8
+ end
9
+
10
+ def metadata_file
11
+ @_metadata_file ||= @files.reject {|key| !key.match(/\.json/) }.values.first
12
+ end
13
+ end
14
+
@@ -0,0 +1,56 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+ require 'icomoon2sass'
4
+
5
+ class Icomoon2Sass::CLI < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :icomoon
9
+
10
+ class_option :'font-path', type: :string, default: './', desc: 'Destination path for font files'
11
+ class_option :'sass-path', type: :string, default: './', desc: 'Destination path for Sass files'
12
+ class_option :scss, type: :boolean, default: false, desc: 'Use the SCSS syntax'
13
+ class_option :compatible, aliases: '-c', type: :boolean, default: false, desc: 'Generate code compatible with Sass 3.2'
14
+
15
+ def start
16
+
17
+ if icomoon.end_with? '.zip'
18
+ say_status('Reading zip file.', '', :green)
19
+
20
+ files = Icomoon2Sass::Zip.new icomoon
21
+
22
+ elsif Dir.exists? icomoon
23
+ say_status('Reading directory.', '', :blue)
24
+
25
+ files = Icomoon2Sass::Dir.new icomoon
26
+
27
+ else
28
+ return say_status('WTF?!', 'I have no idea what I\'m doing.', :red)
29
+
30
+ end
31
+
32
+ return say_status('You seem to be missing \'selection.json\'.', '', :red) unless files.files['selection.json']
33
+
34
+
35
+ font = Icomoon2Sass::Font.new files.metadata_file
36
+
37
+ syntax = options['scss'] ? 'scss' : 'sass'
38
+
39
+ compatible = options['compatible'] || false
40
+
41
+ sass = Icomoon2Sass::Sass.new font, syntax, compatible
42
+
43
+
44
+
45
+
46
+ # Save the Sass file
47
+ create_file "#{options['sass-path']}/_icons.#{sass.syntax}", sass.code
48
+
49
+ files.font_files.each do |filename, content|
50
+
51
+ create_file "#{options['font-path']}/#{filename.sub('fonts/', '')}", content
52
+ end
53
+
54
+ end
55
+ end
56
+
@@ -0,0 +1,21 @@
1
+ class Icomoon2Sass::Dir < Icomoon2Sass::Archive
2
+
3
+ def initialize(directory)
4
+ @files = {}
5
+
6
+ Dir.glob("#{directory}/**/*", File::FNM_DOTMATCH) do |file|
7
+ next if ['.','..','.DS_Store'].include? file
8
+
9
+ @files[file.sub("#{directory}/", '')] = File.read(file) if extractable? file
10
+ end
11
+
12
+ end
13
+
14
+ private
15
+
16
+ def extractable?(entry)
17
+ return EXTRACTABLE_PATTERN.match(entry) && File.file?(entry)
18
+ end
19
+
20
+ end
21
+
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+
3
+ class Icomoon2Sass::Font
4
+ attr_reader :icons, :font_family
5
+
6
+ def initialize(metadata)
7
+ @icons = {}
8
+
9
+ json = JSON.parse(metadata)
10
+
11
+ @font_family = json['preferences']['fontPref']['metadata']['fontFamily']
12
+
13
+ json['icons'].each do |icon|
14
+ @icons[icon['properties']['name']] = {
15
+ character: [icon['properties']['code']].pack('U'),
16
+ codepoint: '\%0x' % icon['properties']['code'].ord
17
+ }
18
+
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,42 @@
1
+ require 'erb'
2
+ require 'sass'
3
+
4
+ class Icomoon2Sass::Sass
5
+ attr_reader :code, :syntax
6
+
7
+ def initialize(font, syntax = 'sass', compatible = false)
8
+ @syntax = syntax
9
+
10
+ if compatible
11
+ @code = sass_convert 'sass', syntax, template('list', font)
12
+
13
+ else
14
+ @code = sass_convert 'sass', syntax, template('map', font)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def template(format, font)
21
+ icons = font.icons
22
+ font_family = font.font_family
23
+
24
+ tmpl = File.read("lib/icomoon2sass/templates/#{format}.sass.erb")
25
+
26
+ renderer = ERB.new(tmpl)
27
+ renderer.result(binding)
28
+ end
29
+
30
+
31
+ def sass_convert(from_syntax, to_syntax, sass)
32
+ return sass if from_syntax == to_syntax
33
+
34
+ begin
35
+ Sass::Engine.new(sass, {:from => from_syntax.to_sym, :to => to_syntax.to_sym, :syntax => from_syntax.to_sym}).to_tree.send("to_#{to_syntax}").chomp
36
+ rescue Sass::SyntaxError => e
37
+ sass
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,24 @@
1
+ <% icons.each do |icon, content|
2
+ %>$<%= "#{icon}-icon: \'#{content[:codepoint]}\'" %>
3
+ <% end %>
4
+
5
+ %icon-pseudo-content
6
+ font-family: '<%= font_family %>'
7
+ speak: none
8
+ font-style: normal
9
+ font-weight: normal
10
+ font-variant: normal
11
+ text-transform: none
12
+ line-height: 1
13
+
14
+ // Better Font Rendering
15
+ -webkit-font-smoothing: antialiased
16
+ -moz-osx-font-smoothing: grayscale
17
+
18
+ <% icons.each do |icon, content| %>
19
+ <%= "%#{icon}-icon" %>:before
20
+ @extend %icon-pseudo-content
21
+
22
+ content: <%= "$#{icon}-icon" %>
23
+ <% end %>
24
+
@@ -0,0 +1,48 @@
1
+ $icons: ( <%=
2
+ list = []
3
+ icons.each do |icon, contents|
4
+ list.push "#{icon}: '#{contents[:codepoint]}'"
5
+ end
6
+
7
+ list.join(", ")
8
+ %> )
9
+
10
+
11
+ ///**
12
+ // * Allows you to access an individual icon by name.
13
+ // *
14
+ // * @param {String} $name - name of icon
15
+ // *
16
+ // * @example scss
17
+ // * .foo {
18
+ // * content: icon(github);
19
+ // * }
20
+ // *
21
+ // * @return {String | Null}
22
+ // */
23
+ @function icon($name)
24
+ @return map-get($icons, $name)
25
+
26
+
27
+ %icon-pseudo-content
28
+ font-family: '<%= font_family %>'
29
+ speak: none
30
+ font-style: normal
31
+ font-weight: normal
32
+ font-variant: normal
33
+ text-transform: none
34
+ line-height: 1
35
+ vertical-align: middle
36
+
37
+ // Better Font Rendering
38
+ -webkit-font-smoothing: antialiased
39
+ -moz-osx-font-smoothing: grayscale
40
+
41
+
42
+ @each $placeholder, $content in $icons
43
+ %#{$placeholder}-icon:before
44
+ @extend %icon-pseudo-content
45
+
46
+ @each $value in $content
47
+ content: $value
48
+
@@ -0,0 +1,4 @@
1
+ module Icomoon2Sass
2
+ VERSION = "1.0.0"
3
+ end
4
+
@@ -0,0 +1,22 @@
1
+ require 'zip'
2
+
3
+ class Icomoon2Sass::Zip < Icomoon2Sass::Archive
4
+
5
+ def initialize(zip_file)
6
+ @files = {}
7
+
8
+ Zip::File.open(zip_file) do |z|
9
+ z.each do |entry|
10
+ @files[entry.name] = z.get_input_stream(entry).read if extractable? entry
11
+ end
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def extractable?(entry)
18
+ return EXTRACTABLE_PATTERN.match(entry.name) && entry.ftype == :file
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,11 @@
1
+ require 'icomoon2sass/version'
2
+ require 'icomoon2sass/archive'
3
+ require 'icomoon2sass/zip'
4
+ require 'icomoon2sass/dir'
5
+ require 'icomoon2sass/font'
6
+ require 'icomoon2sass/sass'
7
+
8
+ module Icomoon2Sass
9
+ # Your code goes here...
10
+ end
11
+
data/lib/run.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'icomoon2sass/cli'
2
+
3
+
4
+ ARGV << '--help' if ARGV.empty?
5
+
6
+
7
+ help_message = <<-EOT
8
+ Usage: icomoon2sass path/to/icomoon(.zip) [OPTIONS]
9
+
10
+ OPTIONS
11
+ --font-path PATH Destination path for font files, defaults to current directory
12
+ --sass-path PATH Destination path for Sass files, defaults to current directory
13
+ --scss Use the SCSS syntax
14
+ -c, --compatible Generate code compatible with Sass 3.2
15
+
16
+
17
+ OUTPUT
18
+ By default icomoon2sass generates Sass code in the indented Sass syntax. Further,
19
+ the default generated code is only compaitble with Sass 3.3+.
20
+
21
+ $icons: (
22
+ github: \'\\28\',
23
+ twitter: \'\\29\',
24
+ gear: \'\\e002\',
25
+ ...
26
+ )
27
+
28
+ @each $placeholder, $content in $icons
29
+ %\#{$placeholder}-icon
30
+ @each $value in $content
31
+ content: $value
32
+
33
+ Sass 3.2 doesn't support hash-like maps, so if you're still using 3.2, you'll need
34
+ to set the '-c' flag, which will generate code like this:
35
+
36
+ $github-icon: \'\\28\'
37
+ $twitter-icon: \'\\29\'
38
+ $gear-icon: \'\\e002\'
39
+
40
+ ...
41
+
42
+ %github-icon
43
+ content: $github-icon
44
+
45
+ %twitter-icon
46
+ content: $twitter-icon
47
+
48
+ %gear-icon
49
+ content: $gear-icon
50
+ EOT
51
+
52
+ command = ARGV[0]
53
+
54
+ if !(command.nil? || command == '--help')
55
+ Icomoon2Sass::CLI.start
56
+
57
+
58
+ elsif command == '--help'
59
+ puts help_message
60
+
61
+ else
62
+ puts "Error: Command '#{command}' not recognized"
63
+ if %x{rake #{command} --dry-run 2>&1 } && $?.success?
64
+ puts "Did you mean: `$ rake #{command}` ?\n\n"
65
+ end
66
+ puts help_message
67
+ exit(1)
68
+ end
69
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: icomoon2sass
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jed Foster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sass
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: Utility for using Icomoon icon sets in Sass projects
56
+ email:
57
+ - jed@jedfoster.com
58
+ executables:
59
+ - icomoon2sass
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - bin/icomoon2sass
64
+ - lib/icomoon2sass.rb
65
+ - lib/icomoon2sass/archive.rb
66
+ - lib/icomoon2sass/cli.rb
67
+ - lib/icomoon2sass/dir.rb
68
+ - lib/icomoon2sass/font.rb
69
+ - lib/icomoon2sass/sass.rb
70
+ - lib/icomoon2sass/templates/list.sass.erb
71
+ - lib/icomoon2sass/templates/map.sass.erb
72
+ - lib/icomoon2sass/version.rb
73
+ - lib/icomoon2sass/zip.rb
74
+ - lib/run.rb
75
+ homepage: https://github.com/jedfoster/icomoon2sass
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Command line utility that extracts fonts and codepoints from an Icomoon .zip
99
+ file and generates a Sass file with variables and placholders.
100
+ test_files: []