fontello_rails_converter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/fontello_rails_converter.gemspec +26 -0
- data/lib/fontello_rails_converter/colorized_output.rb +23 -0
- data/lib/fontello_rails_converter/railtie.rb +7 -0
- data/lib/fontello_rails_converter/version.rb +3 -0
- data/lib/fontello_rails_converter.rb +7 -0
- data/lib/tasks/fontello_rails_converter.rake +87 -0
- metadata +124 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jakob Hilden
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
## fontello-rails-converter
|
2
|
+
|
3
|
+
Rake task to be run on .zip file downloaded from fontello.com. It will copy all the assets to the appropiate places in your Rails app and convert them where necessary.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
1. Add the gem to your Gemfile `gem 'fontello_rails_converter'` and run `bundle install`
|
8
|
+
|
9
|
+
1. Download `.zip` file from [http://fontello.com](http://fontello.com) and copy it to your app directory, e.g. into `myapp/tmp/`
|
10
|
+
|
11
|
+
1. Run the rake task `rake import_fontello["tmp/fontello-b9661c9f.zip"]`
|
12
|
+
|
13
|
+
It will copy all the assets from the fontello .zip file into the appropiate places in your app's `vendor/assets/` directory.
|
14
|
+
|
15
|
+
To use them in your app you will need to `@import` the main stylesheet `vendor/assets/stylesheets/fontname.css.scss` in your `application.css.sass` using `@import 'fontname'`. For special cases you might also want `@import` some of the other stylesheets (`fontname-ie7-codes.css.scss`, `fontname-embedded.css.scss`, `animation.css.scss`, `fontname-ie7.css.scss`, `fontname-codes.css.scss`).
|
16
|
+
|
17
|
+
In order for the fonts in `vendor/assets/fonts/` to be served up through the Rails asset pipeline, you will need tell it about font directories, by adding this to your `application.rb`:
|
18
|
+
|
19
|
+
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
|
20
|
+
|
21
|
+
You can check if the icon font is working correctly by visiting [http://localhost:3000/demo.html](http://localhost:3000/demo.html).
|
22
|
+
|
23
|
+
## Updating your font
|
24
|
+
|
25
|
+
When you want to add new icons to your fontello font, just grab the `config.json` from `vendor/assets/fonts/` upload it to fontello, select new icons, download the .zip file and start at step 1.
|
26
|
+
|
27
|
+
## TODO
|
28
|
+
|
29
|
+
Fontello recently added an API ([https://github.com/fontello/fontello#developers-api](https://github.com/fontello/fontello#developers-api)), which would save us all the .zip file downloading hassle.
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fontello_rails_converter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fontello_rails_converter"
|
8
|
+
spec.version = FontelloRailsConverter::VERSION
|
9
|
+
spec.authors = ["Jakob Hilden"]
|
10
|
+
spec.email = ["jakobhilden@gmail.com"]
|
11
|
+
spec.description = %q{Rake task to be run on .zip file downloaded from fontello.com. It will copy all the assets to the appropiate places in your Rails app and convert them where necessary.}
|
12
|
+
spec.summary = %q{Convert/import icon font .zip files downloaded from fontello.com into your Rails app}
|
13
|
+
spec.homepage = "https://github.com/railslove/fontello_rails_converter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rails", ">= 3.1"
|
22
|
+
spec.add_runtime_dependency "rubyzip"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FontelloRailsConverter
|
2
|
+
# for colorized output in the rake task
|
3
|
+
module ColorizedOutput
|
4
|
+
def colorize(text, color_code)
|
5
|
+
"\033[#{color_code}m#{text}\033[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
{
|
9
|
+
:black => 30,
|
10
|
+
:red => 31,
|
11
|
+
:green => 32,
|
12
|
+
:yellow => 33,
|
13
|
+
:blue => 34,
|
14
|
+
:magenta => 35,
|
15
|
+
:cyan => 36,
|
16
|
+
:white => 37
|
17
|
+
}.each do |key, color_code|
|
18
|
+
define_method key do |text|
|
19
|
+
colorize(text, color_code)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
desc "import new zipfile from fontello"
|
2
|
+
task :import_fontello, [:zipfile] => :environment do |t, args|
|
3
|
+
include FontelloRailsConverter::ColorizedOutput
|
4
|
+
require 'zip/zip'
|
5
|
+
|
6
|
+
fontello_zipfile = args[:zipfile]
|
7
|
+
|
8
|
+
if fontello_zipfile.blank?
|
9
|
+
puts red("you need to specify the path to your fontello .zip file as an argument\ne.g. `rake import_fontello[\"tmp/fontelo-12345678.zip\"]`")
|
10
|
+
next
|
11
|
+
elsif !File.exist? fontello_zipfile
|
12
|
+
puts red("file #{fontello_zipfile} could not be found")
|
13
|
+
next
|
14
|
+
end
|
15
|
+
|
16
|
+
# target directories
|
17
|
+
target_assets_dir = File.join Rails.root, "vendor", "assets"
|
18
|
+
target_stylesheets_dir = File.join target_assets_dir, "stylesheets"
|
19
|
+
target_fonts_dir = File.join target_assets_dir, "fonts"
|
20
|
+
mkdir_p target_stylesheets_dir
|
21
|
+
mkdir_p target_fonts_dir
|
22
|
+
|
23
|
+
def convert_main_stylesheet(content)
|
24
|
+
# asset URLs
|
25
|
+
content.gsub! /\.\.\/font\//, ""
|
26
|
+
content.gsub!(/url\(([^\(]+)\)/) { |m| "url(font-path(#{$1}))" }
|
27
|
+
|
28
|
+
# turn icon base class into placeholder selector
|
29
|
+
content.gsub! /\[class\^="icon-[^\{]+{/m, "%icon-base {"
|
30
|
+
|
31
|
+
# get icons
|
32
|
+
icons = content.scan(/\.(icon-\S+):before/).map(&:first)
|
33
|
+
|
34
|
+
# convert icon classes to placeholder selectors
|
35
|
+
content.gsub!(/^\.(icon-\S+:before) { (.+)$/) { |m| "%#{$1} { @extend %icon-base; #{$2}" }
|
36
|
+
|
37
|
+
# recreate icon classes using the mixins
|
38
|
+
if icons.any?
|
39
|
+
content += "\n\n"
|
40
|
+
icons.each do |icon|
|
41
|
+
content += ".#{icon} { @extend %#{icon}; }\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return content
|
46
|
+
end
|
47
|
+
|
48
|
+
def convert_demo_html(content)
|
49
|
+
content.gsub! /css\//, "/assets/"
|
50
|
+
end
|
51
|
+
|
52
|
+
Zip::ZipFile.open(args[:zipfile]) do |zipfile|
|
53
|
+
zipfile.each do |file|
|
54
|
+
filename = file.to_s.split("/").last
|
55
|
+
|
56
|
+
# stylesheets
|
57
|
+
if filename.end_with? '.css'
|
58
|
+
# extract stylesheet to target location
|
59
|
+
target_file = File.join target_stylesheets_dir, "#{filename}.scss"
|
60
|
+
zipfile.extract(file, target_file) { true }
|
61
|
+
puts green("copied #{target_file}")
|
62
|
+
|
63
|
+
if !filename.end_with? "animation.css", "-ie7.css", "-codes.css", "-ie7-codes.css", "-embedded.css"
|
64
|
+
converted_css = convert_main_stylesheet File.read(target_file)
|
65
|
+
File.open(target_file, 'w') { |f| f.write(converted_css) }
|
66
|
+
puts green("converted #{target_file} for Sass & asset pipeline")
|
67
|
+
end
|
68
|
+
|
69
|
+
# font files
|
70
|
+
elsif filename.end_with? ".eot", ".woff", ".ttf", ".svg", "config.json"
|
71
|
+
target_file = File.join target_fonts_dir, filename
|
72
|
+
zipfile.extract(file, target_file) { true }
|
73
|
+
puts green("copied #{target_file}")
|
74
|
+
|
75
|
+
# demo.html
|
76
|
+
elsif filename == 'demo.html'
|
77
|
+
target_file = File.join Rails.root, "public", filename
|
78
|
+
zipfile.extract(file, target_file) { true }
|
79
|
+
puts green("copied #{target_file}")
|
80
|
+
|
81
|
+
converted_html = convert_demo_html File.read(target_file)
|
82
|
+
File.open(target_file, 'w') { |f| f.write(converted_html) }
|
83
|
+
puts green("converted #{filename}'s HTML for asset pipeline")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fontello_rails_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jakob Hilden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubyzip
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Rake task to be run on .zip file downloaded from fontello.com. It will
|
79
|
+
copy all the assets to the appropiate places in your Rails app and convert them
|
80
|
+
where necessary.
|
81
|
+
email:
|
82
|
+
- jakobhilden@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- fontello_rails_converter.gemspec
|
93
|
+
- lib/fontello_rails_converter.rb
|
94
|
+
- lib/fontello_rails_converter/colorized_output.rb
|
95
|
+
- lib/fontello_rails_converter/railtie.rb
|
96
|
+
- lib/fontello_rails_converter/version.rb
|
97
|
+
- lib/tasks/fontello_rails_converter.rake
|
98
|
+
homepage: https://github.com/railslove/fontello_rails_converter
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.25
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Convert/import icon font .zip files downloaded from fontello.com into your
|
123
|
+
Rails app
|
124
|
+
test_files: []
|