fontsquirrel-download 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fontsquirrel-download.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Stefan Wienert
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,52 @@
1
+ # Fontsquirrel::Download
2
+
3
+ Download and extract font-kits from [fontsquirrel](http://www.fontsquirrel.com/fontface) easily with a rake tasks.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fontsquirrel-download', group: "development"
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Add to your application.css/application.css.scss:
16
+
17
+ ```css
18
+ //= require fonts
19
+ ```
20
+
21
+ Because the download will append the necessary changes to ``app/assets/stylesheets/_fonts.css.sass``.
22
+
23
+ ## Usage
24
+
25
+
26
+
27
+ Use Rake task, specify the Font name as written in the URL from font-squirrel, e.g. the well-known LaTeX-Font:
28
+
29
+ ```bash
30
+ rake font:kit NAME=TeX-Gyre-Bonum
31
+ ```
32
+
33
+ This will download the fonts to ``app/assets/fonts`` and append the style rules to ``app/assets/stylesheets/_fonts.css.sass``.
34
+
35
+ After that, you can use that style definition in your css rules, like:
36
+
37
+ ```css
38
+ body {
39
+ font-family: "TeXGyreBonumRegular", serif;
40
+ }
41
+ ```
42
+
43
+ The names always vary a little, just look them up in the \_fonts.css.sass
44
+
45
+
46
+
47
+
48
+ ## Potential ToDo
49
+
50
+ * Until know, it will download the normal subset of the font.
51
+ Some fonts have no special chars (like German Umlauts) at all, some have them in a subset. Maybe specifying the subset comes in handy.
52
+ * Downloading not only font-kits but all the other fonts...
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/fontsquirrel-download/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Stefan Wienert"]
6
+ gem.email = ["stefan.wienert@pludoni.de"]
7
+ gem.description = %q{ Download and extract font-kits from fontsquirrel easily with a rake tasks.}
8
+ gem.summary = %q{ Download and extract font-kits from fontsquirrel easily with a rake tasks.}
9
+ gem.homepage = "https://github.com/zealot128/fontsquirrel-download"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fontsquirrel-download"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = FontSquirrel::VERSION
17
+
18
+ gem.add_dependency "rubyzip"
19
+ gem.add_dependency "rails", ">= 3.1"
20
+ end
@@ -0,0 +1,6 @@
1
+ require "fontsquirrel-download/version"
2
+ require "fontsquirrel-download/download"
3
+ require "fontsquirrel-download/railtie"
4
+
5
+ module FontSquirrel
6
+ end
@@ -0,0 +1,55 @@
1
+ require "open-uri"
2
+ require "zip/zip"
3
+ module FontSquirrel
4
+ class Download
5
+ # Provide Font-Name as written in URL of font-squirrel,
6
+ # like TeX-Gyre-Bonum
7
+ def initialize(name,options={})
8
+ @options=options
9
+ @name = name
10
+ download(name)
11
+ FileUtils.mkdir_p @options[:font_dir]
12
+ Zip::ZipFile.open(@options[:tmp_name]) do |zipfile|
13
+ zipfile.each do |entry|
14
+ case entry.name
15
+ when /stylesheet.css/
16
+ append_stylesheet(entry)
17
+ when /ttf|woff|eot|svg/
18
+ extract_font(entry)
19
+ end
20
+ end
21
+ end
22
+ FileUtils.rm @options[:tmp_name].to_s
23
+
24
+ end
25
+
26
+
27
+
28
+ private
29
+ def name; @name; end
30
+ def append_stylesheet(entry)
31
+ content = entry.get_input_stream.read
32
+ text = Sass::Engine.new(content, syntax: :scss).to_tree.to_sass
33
+ text.gsub!(/url\(([^\)]+)\)/, "asset-url(\\1, font)")
34
+ log "Writing new font-definitions to #{@options[:font_file].to_s}"
35
+ File.open(@options[:font_file].to_s, "a") {|f| f.write text }
36
+ end
37
+
38
+ def extract_font(entry)
39
+ target = @options[:font_dir].join(entry.name).to_s
40
+ FileUtils.copy_stream entry.get_input_stream, File.open(target, "wb+")
41
+ log "Extracting #{target}"
42
+ end
43
+
44
+ def download(name)
45
+ url = "http://www.fontsquirrel.com/fontfacekit/#{name}"
46
+ log "Downloading #{url}..."
47
+ File.open(@options[:tmp_name], "wb+") { |f| f.write open(url).read }
48
+ end
49
+
50
+ def log(msg)
51
+ $stdout.puts msg
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ module FontSquirrel
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks { load "tasks/fontsquirrel-download.rake" }
4
+ initializer 'fontsquirrel.add_fonts_dir' do |app|
5
+ app.config.assets[:paths] << Rails.root.join("app","assets","fonts").to_s
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module FontSquirrel
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+
2
+ namespace :font do
3
+ desc "Download and extract font-squirrel kit. Give Repos with NAME=TeX-Gyre-Bonum"
4
+ task :kit do
5
+ name = ENV["NAME"]
6
+ if name.blank?
7
+ puts "give name to font with rake font:kit NAME=TeX-Gyre-Bonum"
8
+ exit 1
9
+ end
10
+ require "fontsquirrel-download/download"
11
+ FontSquirrel::Download.new name,
12
+ tmp_name: Rails.root.join("tmp/fontsquirrel.zip").to_s,
13
+ font_file: Rails.root.join("app/assets/stylesheets/_fonts.css.sass"),
14
+ font_dir: Rails.root.join("app/assets/fonts")
15
+
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fontsquirrel-download
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stefan Wienert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubyzip
16
+ requirement: &78163800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *78163800
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &78163540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *78163540
36
+ description: ! ' Download and extract font-kits from fontsquirrel easily with a rake
37
+ tasks.'
38
+ email:
39
+ - stefan.wienert@pludoni.de
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - fontsquirrel-download.gemspec
50
+ - lib/fontsquirrel-download.rb
51
+ - lib/fontsquirrel-download/download.rb
52
+ - lib/fontsquirrel-download/railtie.rb
53
+ - lib/fontsquirrel-download/version.rb
54
+ - lib/tasks/fontsquirrel-download.rake
55
+ homepage: https://github.com/zealot128/fontsquirrel-download
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: 542117729
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: 542117729
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.15
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Download and extract font-kits from fontsquirrel easily with a rake tasks.
85
+ test_files: []