fontastic2sass 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: eb468deae4baf15a019bc0233f3646c65a908679
4
+ data.tar.gz: c05b43d68f048a571d6533f24ab97197a24abd98
5
+ SHA512:
6
+ metadata.gz: 1576aedf8ee7c5fd0910917e4a72bcbe99c04f6290fef5194bf601afb7a0269414d7145bbe50360d7e7310ac65f9b67f7b0f470edf080be72e9e436c21ce3a1a
7
+ data.tar.gz: 2b0b731e45ee4dc741f00912949756c8e4ecf6e959ecdf7ccb76516984e3befe962ce3c896c4c8c28cb0f172fca546fa3fc2601562027f8daa6d3d32e320bab0
@@ -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,23 @@
1
+ class Fontastic2Sass::Archive
2
+ attr_reader :files
3
+
4
+ EXTRACTABLE_PATTERN = /(fonts\/.*|styles\.css|icons-reference\.html)/
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(/styles.css/) }.values.first
12
+ end
13
+
14
+ def demo_files
15
+ @_demo_files ||= begin
16
+ demo_files = @files.reject {|key| !key.match(/(\.html|\.css)/) }
17
+ demo_files['demo-files/style.css'] = demo_files.delete('styles.css')
18
+ demo_files
19
+ end
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,31 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+ require 'fontastic2sass'
4
+
5
+ class Fontastic2Sass::CLI < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :source
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
+ class_option :oocss, type: :boolean, default: false, desc: 'Generate OOCSS-style classes'
15
+ class_option :'demo-path', type: :string, default: false, desc: 'Destination path for demo.html'
16
+
17
+ def start
18
+
19
+ begin
20
+ Fontastic2Sass.run! source, options['font-path'], options['sass-path'], options
21
+
22
+ rescue Exception => e
23
+ say_status(e, '', :red)
24
+
25
+ end
26
+
27
+ return
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,21 @@
1
+ class Fontastic2Sass::Dir < Fontastic2Sass::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,24 @@
1
+ class Fontastic2Sass::Font
2
+ attr_reader :font_family
3
+
4
+ def initialize(file)
5
+ @font_family = file.scan(/font-family\: \"(.+)\"/).first.first
6
+
7
+ @raw_icons = file.scan(/\.icon-(.+)\:.+{\s+content\: \"(.+)\"/)
8
+ end
9
+
10
+ def icons
11
+ @icons ||= begin
12
+ icons = {}
13
+
14
+ @raw_icons.each do |icon|
15
+ icons[icon.first] = {
16
+ codepoint: icon.last
17
+ }
18
+ end
19
+
20
+ icons
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,42 @@
1
+ require 'erb'
2
+ require 'sass'
3
+
4
+ class Fontastic2Sass::Sass
5
+ attr_reader :code, :syntax
6
+
7
+ def initialize(font, syntax = 'sass', compatible = false)
8
+ @font = font
9
+ @syntax = syntax
10
+
11
+ @format = compatible ? 'list' : 'map'
12
+
13
+ @code = sass_convert 'sass', syntax, template(@format)
14
+ end
15
+
16
+ def oocss
17
+ sass_convert 'sass', syntax, template("oocss_#{@format}")
18
+ end
19
+
20
+ private
21
+
22
+ def template(tmpl)
23
+ icons = @font.icons
24
+ font_family = @font.font_family
25
+
26
+ renderer = ERB.new File.read("#{File.dirname(__FILE__)}/templates/#{tmpl}.sass.erb")
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,27 @@
1
+ // This file was generated with fontastic2sass. (https://github.com/jedfoster/fontastic2sass)
2
+ // You may lose edits if you run fontastic2sass again.
3
+
4
+ <% icons.each do |icon, content|
5
+ %>$<%= "#{icon}-icon: \'#{content[:codepoint]}\'" %>
6
+ <% end %>
7
+
8
+ %icon-pseudo-content
9
+ font-family: '<%= font_family %>'
10
+ speak: none
11
+ font-style: normal
12
+ font-weight: normal
13
+ font-variant: normal
14
+ text-transform: none
15
+ line-height: 1
16
+
17
+ // Better Font Rendering
18
+ -webkit-font-smoothing: antialiased
19
+ -moz-osx-font-smoothing: grayscale
20
+
21
+ <% icons.each do |icon, content| %>
22
+ <%= "%#{icon}-icon" %>
23
+ @extend %icon-pseudo-content
24
+
25
+ content: <%= "$#{icon}-icon" %>
26
+ <% end %>
27
+
@@ -0,0 +1,51 @@
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
+ // This file was generated with fontastic2sass. (https://github.com/jedfoster/fontastic2sass)
28
+ // You may lose edits if you run fontastic2sass again.
29
+
30
+ %icon-pseudo-content
31
+ font-family: '<%= font_family %>'
32
+ speak: none
33
+ font-style: normal
34
+ font-weight: normal
35
+ font-variant: normal
36
+ text-transform: none
37
+ line-height: 1
38
+ vertical-align: middle
39
+
40
+ // Better Font Rendering
41
+ -webkit-font-smoothing: antialiased
42
+ -moz-osx-font-smoothing: grayscale
43
+
44
+
45
+ @each $placeholder, $content in $icons
46
+ %#{$placeholder}-icon
47
+ @extend %icon-pseudo-content
48
+
49
+ @each $value in $content
50
+ content: $value
51
+
@@ -0,0 +1,7 @@
1
+ // This file was generated with fontastic2sass. (https://github.com/jedfoster/fontastic2sass)
2
+ // You may lose edits if you run fontastic2sass again.
3
+
4
+ <% icons.each do |icon, content| %>
5
+ <%= ".#{icon}-icon" %>:before
6
+ @extend %<%= "#{icon}-icon" %>
7
+ <% end %>
@@ -0,0 +1,6 @@
1
+ // This file was generated with fontastic2sass. (https://github.com/jedfoster/fontastic2sass)
2
+ // You may lose edits if you run fontastic2sass again.
3
+
4
+ @each $placeholder, $content in $icons
5
+ .#{$placeholder}-icon:before
6
+ @extend %#{$placeholder}-icon
@@ -0,0 +1,9 @@
1
+ require 'thor'
2
+
3
+ module Fontastic2Sass
4
+
5
+ class Utilities < Thor
6
+ include Thor::Actions
7
+ end
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ module Fontastic2Sass
2
+ VERSION = '1.0.0'
3
+ end
4
+
@@ -0,0 +1,22 @@
1
+ require 'zip'
2
+
3
+ class Fontastic2Sass::Zip < Fontastic2Sass::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,72 @@
1
+ require 'fontastic2sass/version'
2
+ require 'fontastic2sass/archive'
3
+ require 'fontastic2sass/zip'
4
+ require 'fontastic2sass/dir'
5
+ require 'fontastic2sass/font'
6
+ require 'fontastic2sass/sass'
7
+ require 'fontastic2sass/utilities'
8
+ require 'hash'
9
+
10
+
11
+ module Fontastic2Sass
12
+
13
+ def self.run!(source, font_path, sass_path, options = {})
14
+ defaults = {
15
+ scss: false,
16
+ compatible: false,
17
+ oocss: false,
18
+ demo_path: options[:"demo-path"]
19
+ }
20
+
21
+ options = defaults.merge options.symbolize_keys
22
+
23
+ utilities = Fontastic2Sass::Utilities.new
24
+
25
+ if source.end_with? '.zip'
26
+ files = Fontastic2Sass::Zip.new source
27
+
28
+ elsif ::Dir.exists? source
29
+ files = Fontastic2Sass::Dir.new source
30
+
31
+ else
32
+ raise 'Source must be either a directory or .zip file!'
33
+
34
+ end
35
+
36
+ # raise 'Source must contain \'selection.json\'.' unless files.files['selection.json']
37
+
38
+ font = Fontastic2Sass::Font.new files.metadata_file
39
+
40
+ syntax = options[:scss] ? 'scss' : 'sass'
41
+
42
+ compatible = options[:compatible] || false
43
+
44
+ sass = Fontastic2Sass::Sass.new font, syntax, compatible
45
+
46
+
47
+ # Save the Sass file
48
+ utilities.create_file "#{sass_path}/_icons.#{sass.syntax}", sass.code
49
+
50
+ if options[:oocss]
51
+ utilities.create_file "#{sass_path}/_oocss_icons.#{sass.syntax}", sass.oocss
52
+ end
53
+
54
+ files.font_files.each do |filename, content|
55
+ utilities.create_file "#{font_path}/#{filename.sub('fonts/', '')}", content
56
+ end
57
+
58
+ if options[:demo_path]
59
+ files.demo_files.each do |filename, content|
60
+ utilities.create_file "#{options[:demo_path]}/#{filename}", content
61
+ end
62
+
63
+ files.font_files.each do |filename, content|
64
+ utilities.create_file "#{options[:demo_path]}/demo-files/fonts/#{filename.sub('fonts/', '')}", content
65
+ end
66
+
67
+ utilities.gsub_file "#{options[:demo_path]}/icons-reference.html", /href="styles.css">/, 'href="demo-files/styles.css">'
68
+ end
69
+ end
70
+
71
+ end
72
+
data/lib/hash.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Hash
2
+ def transform_keys
3
+ result = {}
4
+ each_key do |key|
5
+ result[yield(key)] = self[key]
6
+ end
7
+ result
8
+ end
9
+
10
+ def transform_keys!
11
+ keys.each do |key|
12
+ self[yield(key)] = delete(key)
13
+ end
14
+ self
15
+ end
16
+
17
+ def symbolize_keys
18
+ transform_keys{ |key| key.to_sym rescue key }
19
+ end
20
+
21
+ def symbolize_keys!
22
+ transform_keys!{ |key| key.to_sym rescue key }
23
+ end
24
+
25
+ end
26
+
data/lib/run.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'fontastic2sass/cli'
2
+
3
+
4
+ ARGV << '--help' if ARGV.empty?
5
+
6
+
7
+ help_message = <<-EOT
8
+ Usage: fontastic2sass path/to/fontastic(.zip) [OPTIONS]
9
+
10
+ You can also pass the path to an unzipped directory.
11
+
12
+
13
+ OPTIONS
14
+ --font-path PATH Destination path for font files, defaults to current directory
15
+ --sass-path PATH Destination path for Sass files, defaults to current directory
16
+ --scss Use the SCSS syntax
17
+ -c, --compatible Generate code compatible with Sass 3.2
18
+ --oocss Generate OOCSS-style classes
19
+ --demo-path PATH Copy demo.html from SOURCE to PATH/demo.html
20
+ If omitted, the demo file will be ignored
21
+
22
+
23
+ OUTPUT
24
+ By default fontastic2sass generates Sass code in the indented Sass syntax. Further,
25
+ the default generated code is only compatible with Sass 3.3+.
26
+
27
+ $icons: (
28
+ github: \'\\28\',
29
+ twitter: \'\\29\',
30
+ gear: \'\\e002\',
31
+ ...
32
+ )
33
+
34
+ @each $placeholder, $content in $icons
35
+ %\#{$placeholder}-icon
36
+ @each $value in $content
37
+ content: $value
38
+
39
+ Sass 3.2 doesn't support hash-like maps, so if you're still using 3.2, you'll need
40
+ to set the '-c' flag, which will generate code like this:
41
+
42
+ $github-icon: \'\\28\'
43
+ $twitter-icon: \'\\29\'
44
+ $gear-icon: \'\\e002\'
45
+
46
+ ...
47
+
48
+ %github-icon
49
+ content: $github-icon
50
+
51
+ %twitter-icon
52
+ content: $twitter-icon
53
+
54
+ %gear-icon
55
+ content: $gear-icon
56
+
57
+ OOCSS
58
+
59
+ By default, fontastic2sass only generates Sass placeholder selectors. If you need
60
+ literal CSS classes pass the '--oocss' flag, and fontastic2sass will generate a
61
+ second Sass file, '_oocss_icons.sass', containing CSS classes for each icon.
62
+
63
+ @each $placeholder, $content in $icons
64
+ .\#{$placeholder}-icon:before
65
+ @extend %\#{$placeholder}-icon
66
+
67
+ Or, for Sass 3.2, something like this:
68
+
69
+ .github-icon:before
70
+ @extend %github-icon
71
+
72
+ .twitter-icon:before
73
+ @extend %twitter-icon
74
+
75
+ .gear-icon:before
76
+ @extend %gear-icon
77
+ EOT
78
+
79
+ command = ARGV[0]
80
+
81
+ if !(command.nil? || command == '--help')
82
+ Fontastic2Sass::CLI.start
83
+
84
+
85
+ elsif command == '--help'
86
+ puts help_message
87
+
88
+ else
89
+ puts "Error: Command '#{command}' not recognized"
90
+ if %x{rake #{command} --dry-run 2>&1 } && $?.success?
91
+ puts "Did you mean: `$ rake #{command}` ?\n\n"
92
+ end
93
+ puts help_message
94
+ exit(1)
95
+ end
96
+
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fontastic2sass
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: 2015-02-09 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 Fontastic.me icon sets in Sass projects
56
+ email:
57
+ - jed@jedfoster.com
58
+ executables:
59
+ - fontastic2sass
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/fontastic2sass/archive.rb
64
+ - lib/fontastic2sass/cli.rb
65
+ - lib/fontastic2sass/dir.rb
66
+ - lib/fontastic2sass/font.rb
67
+ - lib/fontastic2sass/sass.rb
68
+ - lib/fontastic2sass/templates/list.sass.erb
69
+ - lib/fontastic2sass/templates/map.sass.erb
70
+ - lib/fontastic2sass/templates/oocss_list.sass.erb
71
+ - lib/fontastic2sass/templates/oocss_map.sass.erb
72
+ - lib/fontastic2sass/utilities.rb
73
+ - lib/fontastic2sass/version.rb
74
+ - lib/fontastic2sass/zip.rb
75
+ - lib/fontastic2sass.rb
76
+ - lib/hash.rb
77
+ - lib/run.rb
78
+ - bin/fontastic2sass
79
+ homepage: https://github.com/jedfoster/fontastic2sass
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.14
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Command line utility that extracts fonts and codepoints from an Fontastic
103
+ .zip file and generates a Sass file with variables and placholders.
104
+ test_files: []