icosmith-rails 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +45 -0
- data/lib/icosmith-rails.rb +1 -0
- data/lib/icosmith-rails/config.rb +1 -1
- data/lib/icosmith-rails/font.rb +124 -0
- data/lib/icosmith-rails/generator.rb +8 -96
- data/lib/icosmith-rails/tasks/icosmith.rake +18 -8
- data/lib/icosmith-rails/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 809b309a7de9d2b3c862b8a93edd869d67f3c878
|
4
|
+
data.tar.gz: e47c92f1661ce66e35ce46cd12d28a02c52f0343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e68dd7f3c4ddd4df7ffefcb2b869762cac5a487b521205e2170486a921f5c684492fbaf29ba7bfbcfdecc24ba958f3bbb36aa40d64563e403773d934f852be5
|
7
|
+
data.tar.gz: 07ea9142fce61f11d1ccf1ead413183131da55ce734488b223556f190b07c725a3ae3225c31590048e6018297262efb8144479c2a0a0d9b56dfbd08ef68aae6c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -53,6 +53,51 @@ You can also configure each parameter individually. Just call `Icosmith.configur
|
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
|
+
### Multiple fonts
|
57
|
+
|
58
|
+
If you want to use multiple fonts, change the following configurations:
|
59
|
+
|
60
|
+
- Edit your `icosmith.yml` file and add a `fonts` parameter, with a list of font names:
|
61
|
+
|
62
|
+
```yml
|
63
|
+
use_sass: true
|
64
|
+
svg_dir: app/assets/svgs
|
65
|
+
font_dir: app/assets/fonts
|
66
|
+
css_dir: app/assets/stylesheets
|
67
|
+
manifest_dir: config/icosmith
|
68
|
+
generate_fonts_url: http://icosmith.com/generate_font
|
69
|
+
fonts:
|
70
|
+
- my-font1
|
71
|
+
- my-font2
|
72
|
+
```
|
73
|
+
|
74
|
+
- Create a `manifest.json` file for each font, inside a subdirectory with the font name:
|
75
|
+
|
76
|
+
```sh
|
77
|
+
config
|
78
|
+
└── icosmith
|
79
|
+
├── my-font1
|
80
|
+
│ └── manifest.json
|
81
|
+
├── my-font2
|
82
|
+
│ └── manifest.json
|
83
|
+
└── icosmith.yml
|
84
|
+
```
|
85
|
+
|
86
|
+
- Move each font`s SVG files to a subdirectory with the font name:
|
87
|
+
|
88
|
+
```sh
|
89
|
+
app/svgs/
|
90
|
+
├── my-font1
|
91
|
+
│ ├── icon1.svg
|
92
|
+
│ ├── icon2.svg
|
93
|
+
│ ├── icon3.svg
|
94
|
+
│ ├── icon4.svg
|
95
|
+
└── my-font2
|
96
|
+
├── icon5.svg
|
97
|
+
├── icon6.svg
|
98
|
+
└── icon7.svg
|
99
|
+
```
|
100
|
+
|
56
101
|
## Usage
|
57
102
|
|
58
103
|
rake icosmith:generate
|
data/lib/icosmith-rails.rb
CHANGED
@@ -5,7 +5,7 @@ module Icosmith
|
|
5
5
|
MANIFEST_FILENAME = "manifest.json"
|
6
6
|
|
7
7
|
class Config
|
8
|
-
KEYS = [:svg_dir, :font_dir, :css_dir, :manifest_dir, :generate_fonts_url, :use_sass]
|
8
|
+
KEYS = [:svg_dir, :font_dir, :fonts, :css_dir, :manifest_dir, :generate_fonts_url, :use_sass]
|
9
9
|
|
10
10
|
KEYS.each do |key|
|
11
11
|
attr_accessor key
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Icosmith
|
4
|
+
class Font
|
5
|
+
SVG_ZIPFILENAME = "svg.zip"
|
6
|
+
FONTS_ZIPFILENAME = "fonts.zip"
|
7
|
+
|
8
|
+
def initialize root_path, config, font_name = ""
|
9
|
+
@root_path = root_path
|
10
|
+
@config = config
|
11
|
+
@font_name = font_name
|
12
|
+
setup_parameters
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_svg_zipfile
|
16
|
+
create_directories
|
17
|
+
FileUtils.rm_f(@svg_zipfile)
|
18
|
+
|
19
|
+
log("Compressing SVGs")
|
20
|
+
Zip::ZipFile.open(@svg_zipfile, Zip::ZipFile::CREATE) do |zipfile|
|
21
|
+
Dir.glob("#{@src_dir}#{File::SEPARATOR}*.svg").each do |filename|
|
22
|
+
zipfile.add(filename.split(File::SEPARATOR).last, filename)
|
23
|
+
end
|
24
|
+
|
25
|
+
zipfile.add(Icosmith::MANIFEST_FILENAME, @manifest_full_path) if File.exists?(@manifest_full_path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_font
|
30
|
+
create_directories
|
31
|
+
|
32
|
+
log("Sending files to #{@config.generate_fonts_url}")
|
33
|
+
fontfile_contents = RestClient.post(@config.generate_fonts_url, file: File.new(@svg_zipfile))
|
34
|
+
filename = fontfile_contents.headers[:content_disposition].scan(/filename="([^"]+)"/).flatten.first
|
35
|
+
filename ||= FONTS_ZIPFILENAME
|
36
|
+
|
37
|
+
@fonts_zipfile = File.join(@temp_dir, filename)
|
38
|
+
|
39
|
+
log("Writing #{filename}")
|
40
|
+
File.open(@fonts_zipfile, "w:binary") do |f|
|
41
|
+
f.write(fontfile_contents)
|
42
|
+
end
|
43
|
+
|
44
|
+
FileUtils.rm_f(@svg_zipfile)
|
45
|
+
end
|
46
|
+
|
47
|
+
def extract_font
|
48
|
+
create_directories
|
49
|
+
|
50
|
+
log("Replacing files")
|
51
|
+
temp_font_path = @fonts_zipfile.gsub(/\.zip$/, '')
|
52
|
+
FileUtils.rm_f(temp_font_path)
|
53
|
+
FileUtils.mkdir(temp_font_path)
|
54
|
+
FileUtils.mkdir_p(@font_dir)
|
55
|
+
FileUtils.mkdir_p(@css_dir)
|
56
|
+
|
57
|
+
unzip @fonts_zipfile, temp_font_path
|
58
|
+
copy_css temp_font_path
|
59
|
+
|
60
|
+
Dir.glob("#{temp_font_path}#{File::SEPARATOR}fonts#{File::SEPARATOR}*.{ttf,woff,svg,eot,afm}").each do |file|
|
61
|
+
FileUtils.mv(file, @font_dir)
|
62
|
+
end
|
63
|
+
|
64
|
+
FileUtils.mv(File.join(temp_font_path, Icosmith::MANIFEST_FILENAME), @manifest_full_path)
|
65
|
+
FileUtils.remove_dir(@base_temp_dir)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def copy_css temp_font_path
|
70
|
+
css_path = Dir.glob("#{temp_font_path}#{File::SEPARATOR}*.css").first
|
71
|
+
|
72
|
+
if @config.use_sass
|
73
|
+
scss_path = generate_scss(css_path)
|
74
|
+
FileUtils.mv(scss_path, @css_dir)
|
75
|
+
else
|
76
|
+
FileUtils.mv(css_path, @css_dir)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate_scss path
|
81
|
+
scss_path = "#{path}.scss"
|
82
|
+
log("Generating #{scss_path}")
|
83
|
+
|
84
|
+
css_content = File.read path
|
85
|
+
css_content.gsub!(/url\('fonts\//, "font-url('")
|
86
|
+
File.open(scss_path, 'w') {|out| out << css_content}
|
87
|
+
scss_path
|
88
|
+
end
|
89
|
+
|
90
|
+
def unzip path, target
|
91
|
+
Zip::ZipFile.open(path) do |zip_file|
|
92
|
+
zip_file.each do |file|
|
93
|
+
zip_file.extract(file, File.join(target, file.name))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def setup_parameters
|
99
|
+
@manifest_full_path = File.join(@root_path, @config.manifest_dir, @font_name, Icosmith::MANIFEST_FILENAME)
|
100
|
+
unless File.readable?(@manifest_full_path)
|
101
|
+
puts "Error trying to load manifest file at #{@manifest_full_path}"
|
102
|
+
exit 1
|
103
|
+
end
|
104
|
+
|
105
|
+
@src_dir = File.join(@root_path, @config.svg_dir, @font_name)
|
106
|
+
@base_temp_dir = File.join(@root_path, "tmp", "icosmith")
|
107
|
+
@temp_dir = File.join(@base_temp_dir, @font_name)
|
108
|
+
@svg_zipfile = File.join(@temp_dir, SVG_ZIPFILENAME)
|
109
|
+
@css_dir = File.join(@root_path, @config.css_dir)
|
110
|
+
@font_dir = File.join(@root_path, @config.font_dir)
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_directories
|
114
|
+
FileUtils.mkdir_p(@temp_dir)
|
115
|
+
FileUtils.mkdir_p(@css_dir)
|
116
|
+
FileUtils.mkdir_p(@font_dir)
|
117
|
+
end
|
118
|
+
|
119
|
+
def log message, level = :info
|
120
|
+
message = "[#{@font_name}] #{message}" unless @font_name.empty?
|
121
|
+
Icosmith.logger.send(level, message)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -2,94 +2,26 @@
|
|
2
2
|
|
3
3
|
module Icosmith
|
4
4
|
class Generator
|
5
|
-
SVG_ZIPFILENAME = "svg.zip"
|
6
|
-
FONTS_ZIPFILENAME = "fonts.zip"
|
7
|
-
|
8
5
|
def initialize(root_path)
|
9
6
|
@root_path = root_path
|
10
7
|
load_config
|
11
|
-
setup_parameters
|
12
|
-
create_directories
|
13
8
|
end
|
14
9
|
|
15
|
-
def
|
16
|
-
|
10
|
+
def setup_fonts
|
11
|
+
fonts = []
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
zipfile.add(filename.split(File::SEPARATOR).last, filename)
|
13
|
+
if @config.fonts
|
14
|
+
@config.fonts.each do |font_name|
|
15
|
+
fonts << Icosmith::Font.new(@root_path, @config, font_name)
|
22
16
|
end
|
23
|
-
|
24
|
-
zipfile.add(Icosmith::MANIFEST_FILENAME, @manifest_full_path) if File.exists?(@manifest_full_path)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def generate_font
|
29
|
-
Icosmith.logger.info "Sending files to #{@config.generate_fonts_url}"
|
30
|
-
fontfile_contents = RestClient.post(@config.generate_fonts_url, file: File.new(@svg_zipfile))
|
31
|
-
filename = fontfile_contents.headers[:content_disposition].scan(/filename="([^"]+)"/).flatten.first
|
32
|
-
filename ||= FONTS_ZIPFILENAME
|
33
|
-
|
34
|
-
@fonts_zipfile = File.join(@temp_dir, filename)
|
35
|
-
|
36
|
-
Icosmith.logger.info "Writing #{filename}"
|
37
|
-
File.open(@fonts_zipfile, "w:binary") do |f|
|
38
|
-
f.write(fontfile_contents)
|
39
|
-
end
|
40
|
-
|
41
|
-
FileUtils.rm_f(@svg_zipfile)
|
42
|
-
end
|
43
|
-
|
44
|
-
def extract_font
|
45
|
-
Icosmith.logger.info "Replacing files"
|
46
|
-
temp_font_path = @fonts_zipfile.gsub(/\.zip$/, '')
|
47
|
-
FileUtils.rm_f(temp_font_path)
|
48
|
-
FileUtils.mkdir(temp_font_path)
|
49
|
-
FileUtils.mkdir_p(@font_dir)
|
50
|
-
FileUtils.mkdir_p(@css_dir)
|
51
|
-
|
52
|
-
unzip @fonts_zipfile, temp_font_path
|
53
|
-
copy_css temp_font_path
|
54
|
-
|
55
|
-
Dir.glob("#{temp_font_path}#{File::SEPARATOR}fonts#{File::SEPARATOR}*.{ttf,woff,svg,eot,afm}").each do |file|
|
56
|
-
FileUtils.mv(file, @font_dir)
|
57
|
-
end
|
58
|
-
|
59
|
-
FileUtils.mv(File.join(temp_font_path, Icosmith::MANIFEST_FILENAME), @manifest_full_path)
|
60
|
-
FileUtils.remove_dir(@temp_dir)
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
def copy_css temp_font_path
|
65
|
-
css_path = Dir.glob("#{temp_font_path}#{File::SEPARATOR}*.css").first
|
66
|
-
|
67
|
-
if @config.use_sass
|
68
|
-
scss_path = generate_scss(css_path)
|
69
|
-
FileUtils.mv(scss_path, @css_dir)
|
70
17
|
else
|
71
|
-
|
18
|
+
fonts << Icosmith::Font.new(@root_path, @config)
|
72
19
|
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def generate_scss path
|
76
|
-
scss_path = "#{path}.scss"
|
77
|
-
Icosmith.logger.info "Generating #{scss_path}"
|
78
20
|
|
79
|
-
|
80
|
-
css_content.gsub!(/url\('fonts\//, "font-url('")
|
81
|
-
File.open(scss_path, 'w') {|out| out << css_content}
|
82
|
-
scss_path
|
83
|
-
end
|
84
|
-
|
85
|
-
def unzip path, target
|
86
|
-
Zip::ZipFile.open(path) do |zip_file|
|
87
|
-
zip_file.each do |file|
|
88
|
-
zip_file.extract(file, File.join(target, file.name))
|
89
|
-
end
|
90
|
-
end
|
21
|
+
fonts
|
91
22
|
end
|
92
23
|
|
24
|
+
private
|
93
25
|
def load_config
|
94
26
|
config_filename = File.join(@root_path, "config", "icosmith", Icosmith::CONFIG_FILENAME)
|
95
27
|
begin
|
@@ -98,26 +30,6 @@ module Icosmith
|
|
98
30
|
puts "Error trying to load icosmith configuration file: #{e.message}"
|
99
31
|
exit 1
|
100
32
|
end
|
101
|
-
|
102
|
-
@manifest_full_path = File.join(@root_path, @config.manifest_dir, Icosmith::MANIFEST_FILENAME)
|
103
|
-
unless File.readable?(@manifest_full_path)
|
104
|
-
puts "Error trying to load manifest file at #{@manifest_full_path}"
|
105
|
-
exit 1
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def setup_parameters
|
110
|
-
@src_dir = File.join(@root_path, @config.svg_dir)
|
111
|
-
@temp_dir = File.join(@root_path, "tmp", "icosmith")
|
112
|
-
@svg_zipfile = File.join(@temp_dir, SVG_ZIPFILENAME)
|
113
|
-
@css_dir = File.join(@root_path, @config.css_dir)
|
114
|
-
@font_dir = File.join(@root_path, @config.font_dir)
|
115
|
-
end
|
116
|
-
|
117
|
-
def create_directories
|
118
|
-
FileUtils.mkdir_p(@temp_dir)
|
119
|
-
FileUtils.mkdir_p(@css_dir)
|
120
|
-
FileUtils.mkdir_p(@font_dir)
|
121
33
|
end
|
122
34
|
end
|
123
35
|
end
|
@@ -3,24 +3,34 @@ require "icosmith-rails"
|
|
3
3
|
|
4
4
|
namespace :icosmith do
|
5
5
|
desc "Generates font files with an icosmith server from svg files and organizes in the project"
|
6
|
-
task generate
|
7
|
-
|
6
|
+
task :generate do
|
7
|
+
icosmith_fonts.each do |font|
|
8
|
+
font.create_svg_zipfile
|
9
|
+
font.generate_font
|
10
|
+
font.extract_font
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
desc "Generates font files with an icosmith server from svg files and stores the package at tmp/icosmith"
|
11
|
-
task download_and_extract
|
12
|
-
|
15
|
+
task :download_and_extract do
|
16
|
+
icosmith_fonts.each do |font|
|
17
|
+
font.create_svg_zipfile
|
18
|
+
font.generate_font
|
19
|
+
end
|
13
20
|
end
|
14
21
|
|
22
|
+
desc "Creates a zip file with a manifest and svg files"
|
15
23
|
task :create_svg_zipfile do
|
16
|
-
|
24
|
+
icosmith_fonts.each do |font|
|
25
|
+
font.create_svg_zipfile
|
26
|
+
end
|
17
27
|
end
|
18
28
|
|
19
|
-
|
20
|
-
|
29
|
+
private
|
30
|
+
def icosmith_fonts
|
31
|
+
@fonts ||= Icosmith::Generator.new(root_path).setup_fonts
|
21
32
|
end
|
22
33
|
|
23
|
-
private
|
24
34
|
def root_path
|
25
35
|
defined?(Rails) ? Rails.root : Dir.getwd
|
26
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icosmith-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tulios
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/generators/icosmith/setup/templates/manifest.json
|
105
105
|
- lib/icosmith-rails.rb
|
106
106
|
- lib/icosmith-rails/config.rb
|
107
|
+
- lib/icosmith-rails/font.rb
|
107
108
|
- lib/icosmith-rails/generator.rb
|
108
109
|
- lib/icosmith-rails/railtie.rb
|
109
110
|
- lib/icosmith-rails/tasks/icosmith.rake
|
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
130
|
version: '0'
|
130
131
|
requirements: []
|
131
132
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.1.10
|
133
134
|
signing_key:
|
134
135
|
specification_version: 4
|
135
136
|
summary: Rails integration with an icosmith server
|