icosmith-rails 0.1.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: ace1c7064be2cb160af04110d6e12959cd46cc18
4
+ data.tar.gz: 1d182775959fba97be5e287e93a6f0d2613de22b
5
+ SHA512:
6
+ metadata.gz: 43e86bcec1d982c0265a48e0dc30e696a87afff04e3763b9fc8763ee1e64a651fc14998767b2922e35ce180ccf06b75cd1d8221f55feb0495a5d213c43776937
7
+ data.tar.gz: 26ee4680f0690f9aa919035e2b8b4ee36db5fcdfec12129f26edae98b32972cccbee6d872855f0d26cb8bc526c03575bae3a34cc323048a1ba40e3ddabff73bf
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ icosmith-rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in icosmith-rails.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ icosmith-rails (0.1.0)
5
+ rest-client
6
+ rubyzip
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ columnize (0.3.6)
12
+ debugger (1.6.0)
13
+ columnize (>= 0.3.1)
14
+ debugger-linecache (~> 1.2.0)
15
+ debugger-ruby_core_source (~> 1.2.1)
16
+ debugger-linecache (1.2.0)
17
+ debugger-ruby_core_source (1.2.3)
18
+ diff-lcs (1.2.4)
19
+ mime-types (1.25)
20
+ rest-client (1.6.7)
21
+ mime-types (>= 1.16)
22
+ rspec (2.13.0)
23
+ rspec-core (~> 2.13.0)
24
+ rspec-expectations (~> 2.13.0)
25
+ rspec-mocks (~> 2.13.0)
26
+ rspec-core (2.13.1)
27
+ rspec-expectations (2.13.0)
28
+ diff-lcs (>= 1.1.3, < 2.0)
29
+ rspec-mocks (2.13.1)
30
+ rubyzip (1.0.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ debugger
37
+ icosmith-rails!
38
+ rspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Túlio Ornelas <ornelas.tulio@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Icosmith Rails
2
+
3
+ Rails integration with an icosmith server.
4
+ Creates a rake task to generate a new font from svg files using [icosmith server](https://github.com/tulios/icosmith)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'icosmith-rails'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install icosmith-rails
19
+
20
+ If you are using Rails, use the setup generator
21
+
22
+ $ rails g icosmith:setup
23
+
24
+ Otherwise create a `config/icosmith` directory and copy `icosmith.yml` and
25
+ `manifest.json` from [lib/generators/icosmith/setup/templates](lib/generators/icosmith/setup/templates)
26
+
27
+ ## Configuration
28
+
29
+ `manifest.json`:
30
+ It should contain the font configurations, like the example on [lib/generators/icosmith/setup/templates/manifest.json](lib/generators/icosmith/setup/templates/manifest.json)
31
+
32
+ `icosmith.yml`:
33
+ Change the parameters according to your project. Take a look at [lib/generators/icosmith/setup/templates/icosmith.yml](lib/generators/icosmith/setup/templates/icosmith.yml). `generate_fonts_url` is Icosmith's post URL.
34
+
35
+ You can also configure each parameter individually. Just call `Icosmith.configure` with a block:
36
+
37
+ ```ruby
38
+ Icosmith.configure do |config|
39
+ config.generate_fonts_url = "http://new-url.com/generate_font"
40
+ end
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ rake icosmith:generate
46
+
47
+ If you want to use the example page provided by icosmith, use:
48
+
49
+ rake icosmith:download_and_extract
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ load "lib/tasks/icosmith.rake"
4
+
5
+ require "rspec/core/rake_task"
6
+ desc "Run all examples"
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'icosmith-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "icosmith-rails"
8
+ gem.version = Icosmith::VERSION
9
+ gem.authors = ["tulios", "ggarnier"]
10
+ gem.email = ["ornelas.tulio@gmail.com", "guilherme.garnier@gmail.com"]
11
+ gem.summary = "Rails integration with an icosmith server"
12
+ gem.description = "Creates a rake task to generate a new font from svg files using icosmith server"
13
+ gem.homepage = "https://github.com/tulios/icosmith-rails"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency "rest-client", "~> 1.6.7"
22
+ gem.add_dependency "rubyzip", "~> 1.0.0"
23
+ gem.add_dependency "thor", "~> 0.18.1"
24
+
25
+ gem.add_development_dependency "rspec"
26
+ gem.add_development_dependency "byebug"
27
+ end
@@ -0,0 +1,16 @@
1
+ module Icosmith::Generators
2
+
3
+ class SetupGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), "templates"))
5
+ desc "Creates Icosmith configuration files at config/icosmith"
6
+
7
+ def create_config_files
8
+ config_dir = "config/icosmith"
9
+ FileUtils.mkdir_p config_dir
10
+ copy_file('icosmith.yml', "#{config_dir}/icosmith.yml")
11
+ copy_file('manifest.json', "#{config_dir}/manifest.json")
12
+ readme "README"
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,8 @@
1
+
2
+ How to use:
3
+
4
+ Generates font files with an icosmith server from svg files and organizes in the project
5
+ rake icosmith:generate
6
+
7
+ Generates font files with an icosmith server from svg files and stores the package at tmp/icosmith
8
+ rake icosmith:download_and_extract
@@ -0,0 +1,6 @@
1
+ use_sass: true
2
+ svg_dir: app/assets/svgs
3
+ font_dir: app/assets/fonts
4
+ css_dir: app/assets/stylesheets
5
+ manifest_dir: config/icosmith
6
+ generate_fonts_url: http://icosmith.com/generate_font
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "my_font",
3
+ "family": "my_font",
4
+ "weight": "Regular",
5
+ "ascent": 800,
6
+ "descent": 200,
7
+ "version": "1.0",
8
+ "glyphs": [
9
+ ]
10
+ }
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Icosmith
4
+ CONFIG_FILENAME = "icosmith.yml"
5
+ MANIFEST_FILENAME = "manifest.json"
6
+
7
+ class Config
8
+ KEYS = [:svg_dir, :font_dir, :css_dir, :manifest_dir, :generate_fonts_url, :use_sass]
9
+
10
+ KEYS.each do |key|
11
+ attr_accessor key
12
+ end
13
+
14
+ def self.load(path)
15
+ settings = YAML.load(File.read(path))
16
+
17
+ KEYS.each do |key|
18
+ Icosmith.config.send("#{key}=", settings[key.to_s]) if settings.has_key?(key.to_s)
19
+ end
20
+
21
+ Icosmith.config
22
+ end
23
+ end
24
+
25
+ def self.config
26
+ @@config ||= Config.new
27
+ end
28
+
29
+ def self.logger
30
+ @@logger ||= Logger.new(STDOUT).tap do |log|
31
+ log.formatter = lambda {|severity, datetime, progname, msg| " - #{msg}\n"}
32
+ end
33
+ end
34
+
35
+ def self.configure
36
+ yield self.config
37
+ end
38
+ end
@@ -0,0 +1,122 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Icosmith
4
+ class Generator
5
+ SVG_ZIPFILENAME = "svg.zip"
6
+ FONTS_ZIPFILENAME = "fonts.zip"
7
+
8
+ def initialize
9
+ load_config
10
+ setup_parameters
11
+ create_directories
12
+ end
13
+
14
+ def create_svg_zipfile
15
+ FileUtils.rm_f(@svg_zipfile)
16
+
17
+ Icosmith.logger.info "Compressing SVGs"
18
+ Zip::File.open(@svg_zipfile, Zip::File::CREATE) do |zipfile|
19
+ Dir.glob("#{@src_dir}#{File::SEPARATOR}*.svg").each do |filename|
20
+ zipfile.add(filename.split(File::SEPARATOR).last, filename)
21
+ end
22
+
23
+ zipfile.add(Icosmith::MANIFEST_FILENAME, @manifest_full_path) if File.exists?(@manifest_full_path)
24
+ end
25
+ end
26
+
27
+ def generate_font
28
+ Icosmith.logger.info "Sending files to #{@config.generate_fonts_url}"
29
+ fontfile_contents = RestClient.post(@config.generate_fonts_url, file: File.new(@svg_zipfile))
30
+ filename = fontfile_contents.headers[:content_disposition].scan(/filename="([^"]+)"/).flatten.first
31
+ filename ||= FONTS_ZIPFILENAME
32
+
33
+ @fonts_zipfile = File.join(@temp_dir, filename)
34
+
35
+ Icosmith.logger.info "Writing #{filename}"
36
+ File.open(@fonts_zipfile, "w:binary") do |f|
37
+ f.write(fontfile_contents)
38
+ end
39
+
40
+ FileUtils.rm_f(@svg_zipfile)
41
+ end
42
+
43
+ def extract_font
44
+ Icosmith.logger.info "Replacing files"
45
+ temp_font_path = @fonts_zipfile.gsub(/\.zip$/, '')
46
+ FileUtils.rm_f(temp_font_path)
47
+ FileUtils.mkdir(temp_font_path)
48
+ FileUtils.mkdir_p(@font_dir)
49
+ FileUtils.mkdir_p(@css_dir)
50
+
51
+ unzip @fonts_zipfile, temp_font_path
52
+ copy_css temp_font_path
53
+
54
+ Dir.glob("#{temp_font_path}#{File::SEPARATOR}fonts#{File::SEPARATOR}*.{ttf,woff,svg,eot,afm}").each do |file|
55
+ FileUtils.mv(file, @font_dir)
56
+ end
57
+
58
+ FileUtils.mv(File.join(temp_font_path, Icosmith::MANIFEST_FILENAME), @manifest_full_path)
59
+ FileUtils.remove_dir(@temp_dir)
60
+ end
61
+
62
+ private
63
+ def copy_css temp_font_path
64
+ css_path = Dir.glob("#{temp_font_path}#{File::SEPARATOR}*.css").first
65
+
66
+ if @config.use_sass
67
+ scss_path = generate_scss(css_path)
68
+ FileUtils.mv(scss_path, @css_dir)
69
+ else
70
+ FileUtils.mv(css_path, @css_dir)
71
+ end
72
+ end
73
+
74
+ def generate_scss path
75
+ scss_path = "#{path}.scss"
76
+ Icosmith.logger.info "Generating #{scss_path}"
77
+
78
+ css_content = File.read path
79
+ css_content.gsub!(/url\('fonts\//, "font-url('")
80
+ File.open(scss_path, 'w') {|out| out << css_content}
81
+ scss_path
82
+ end
83
+
84
+ def unzip path, target
85
+ Zip::File.open(path) do |zip_file|
86
+ zip_file.each do |file|
87
+ zip_file.extract(file, File.join(target, file.name))
88
+ end
89
+ end
90
+ end
91
+
92
+ def load_config
93
+ config_filename = File.join(Rails.root, "config", "icosmith", Icosmith::CONFIG_FILENAME)
94
+ begin
95
+ @config = Icosmith::Config.load(config_filename)
96
+ rescue Exception => e
97
+ puts "Error trying to load icosmith configuration file: #{e.message}"
98
+ exit 1
99
+ end
100
+
101
+ @manifest_full_path = File.join(Rails.root, @config.manifest_dir, Icosmith::MANIFEST_FILENAME)
102
+ unless File.readable?(@manifest_full_path)
103
+ puts "Error trying to load manifest file at #{@manifest_full_path}"
104
+ exit 1
105
+ end
106
+ end
107
+
108
+ def setup_parameters
109
+ @src_dir = File.join(Rails.root, @config.svg_dir)
110
+ @temp_dir = File.join(Rails.root, "tmp", "icosmith")
111
+ @svg_zipfile = File.join(@temp_dir, SVG_ZIPFILENAME)
112
+ @css_dir = File.join(Rails.root, @config.css_dir)
113
+ @font_dir = File.join(Rails.root, @config.font_dir)
114
+ end
115
+
116
+ def create_directories
117
+ FileUtils.mkdir_p(@temp_dir)
118
+ FileUtils.mkdir_p(@css_dir)
119
+ FileUtils.mkdir_p(@font_dir)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "icosmith-rails"
3
+ require "rails"
4
+
5
+ module Icosmith
6
+ class Railtie < Rails::Railtie
7
+ railtie_name :icosmith
8
+
9
+ rake_tasks do
10
+ load "tasks/icosmith.rake"
11
+ end
12
+
13
+ initializer "icosmith.load-config" do |app|
14
+ config_file = Rails.root.join("config", "icosmith", Icosmith::CONFIG_FILENAME)
15
+ begin
16
+ Icosmith::Config.load(config_file)
17
+ rescue StandardError => e
18
+ handle_configuration_error(e)
19
+ end
20
+ end
21
+
22
+ def handle_configuration_error(e)
23
+ puts "Icosmith is not configured, you need a #{Icosmith::CONFIG_FILENAME} and a #{Icosmith::MANIFEST_FILENAME}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Icosmith
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "zip"
4
+ require "rest_client"
5
+ require "json"
6
+ require "logger"
7
+ require "byebug" if ENV["RACK_ENV"] == "test"
8
+
9
+ module Icosmith
10
+ extend self
11
+
12
+ def logger
13
+ Config.logger
14
+ end
15
+ end
16
+
17
+ require "icosmith-rails/version"
18
+ require "icosmith-rails/config"
19
+ require "icosmith-rails/generator"
20
+ require "icosmith-rails/railtie" if defined?(Rails)
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "icosmith-rails"
3
+
4
+ namespace :icosmith do
5
+ desc "Generates font files with an icosmith server from svg files and organizes in the project"
6
+ task generate: [:create_svg_zipfile, :download_and_extract] do
7
+ icosmith_generator.extract_font
8
+ end
9
+
10
+ desc "Generates font files with an icosmith server from svg files and stores the package at tmp/icosmith"
11
+ task download_and_extract: [:create_svg_zipfile] do
12
+ icosmith_generator.generate_font
13
+ end
14
+
15
+ task :create_svg_zipfile do
16
+ icosmith_generator.create_svg_zipfile
17
+ end
18
+
19
+ def icosmith_generator
20
+ @generator ||= Icosmith::Generator.new
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+
5
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
+
7
+ require 'rspec'
8
+ require 'icosmith-rails'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ config.order = 'random'
15
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: icosmith-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tulios
8
+ - ggarnier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 1.6.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: rubyzip
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: thor
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 0.18.1
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 0.18.1
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: byebug
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Creates a rake task to generate a new font from svg files using icosmith
85
+ server
86
+ email:
87
+ - ornelas.tulio@gmail.com
88
+ - guilherme.garnier@gmail.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - .ruby-gemset
94
+ - .ruby-version
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - MIT-LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - icosmith-rails.gemspec
101
+ - lib/generators/icosmith/setup/setup_generator.rb
102
+ - lib/generators/icosmith/setup/templates/README
103
+ - lib/generators/icosmith/setup/templates/icosmith.yml
104
+ - lib/generators/icosmith/setup/templates/manifest.json
105
+ - lib/icosmith-rails.rb
106
+ - lib/icosmith-rails/config.rb
107
+ - lib/icosmith-rails/generator.rb
108
+ - lib/icosmith-rails/railtie.rb
109
+ - lib/icosmith-rails/version.rb
110
+ - lib/tasks/icosmith.rake
111
+ - spec/spec_helper.rb
112
+ homepage: https://github.com/tulios/icosmith-rails
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.0.3
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Rails integration with an icosmith server
136
+ test_files:
137
+ - spec/spec_helper.rb