fontsquirrel-download 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51d037a270b55df2a81138ce3bfd72fee4974c73
4
- data.tar.gz: 2cd3f7db5705f3cd375266eb0215650cc3e08843
3
+ metadata.gz: e9f088283e17cc0941631baf6a415ddf60bfc317
4
+ data.tar.gz: d807825661cb2d784803231bf1f2b5c3615c24ab
5
5
  SHA512:
6
- metadata.gz: 312d11cdaf3ce8a7b27538a6050b3a2d79af04ba4c6d3556b3b82b3b0165d62e4994861657c7d417db7a7404c2889450e5787b611cc051d96417b0f119704602
7
- data.tar.gz: 0e65f09d37c73d0fee541d67253fe3fd479a4b399b5a3a129b5ac3b9b693b3ee270a28bfb0f52bba00f8f03e703c4c950178e49a7649527f8f3c251a0539a527
6
+ metadata.gz: 2e928c62f5797b742e5c4da87a7f1b5cf4cf180cc19ca5a01ae38e18dd7728e5bc85e781726e2da9f7f54bcfdd471d0dfb81850ece45dc4278896cae3fbd799e
7
+ data.tar.gz: 538288b460dadedbac435cf0a8a778f5a98482f45673330e47758b418b937eee120924dc7ff3d61ecdd5cf0ca0bbf50a7e086b70b973d221e75b3afad164ede4
data/README.md CHANGED
@@ -18,7 +18,7 @@ Add to your application.css/application.css.scss:
18
18
  //= require fonts
19
19
  ```
20
20
 
21
- Because the download will append the necessary changes to ``app/assets/stylesheets/_fonts.css.sass``.
21
+ Because the download will append the necessary changes to ``app/assets/stylesheets/_fonts.scss``.
22
22
 
23
23
  ## Usage
24
24
 
@@ -27,10 +27,10 @@ Because the download will append the necessary changes to ``app/assets/styleshee
27
27
  Use Rake task, specify the Font name as written in the URL from font-squirrel, e.g. the well-known LaTeX-Font:
28
28
 
29
29
  ```bash
30
- rake font:kit NAME=TeX-Gyre-Bonum
30
+ rake font:download NAME=TeX-Gyre-Bonum
31
31
  ```
32
32
 
33
- This will download the fonts to ``app/assets/fonts`` and append the style rules to ``app/assets/stylesheets/_fonts.css.sass``.
33
+ This will download the fonts to ``app/assets/fonts`` and append the style rules to ``app/assets/stylesheets/_fonts.scss``.
34
34
 
35
35
  After that, you can use that style definition in your css rules, like:
36
36
 
@@ -40,13 +40,19 @@ body {
40
40
  }
41
41
  ```
42
42
 
43
- The names always vary a little, just look them up in the \_fonts.css.sass
43
+ The names always vary a little, just look them up in the \_fonts.scss
44
44
 
45
45
 
46
+ ## Webfont-Kits
46
47
 
48
+ You can also create font-kits with Fontsquirrel's great Webfont-generator and extract+apply that zipfile and merge a meaningful scss-file with correct font weight and style:
47
49
 
48
- ## Potential ToDo
50
+ ```
51
+ rake font:install FILE=/tmp/webfontkit-123.zip
52
+ ```
53
+
54
+
55
+ ## Limitations
49
56
 
50
57
  * Until know, it will download the normal subset of the font.
51
58
  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...
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.license = 'MIT'
17
17
  gem.version = FontSquirrel::VERSION
18
18
 
19
- gem.add_dependency "rubyzip"
20
19
  gem.add_dependency "rails", ">= 3.1"
21
20
  gem.add_dependency "rubyzip", ">= 1.0"
22
21
  end
@@ -3,62 +3,95 @@ require "zip"
3
3
  module FontSquirrel
4
4
  class Download
5
5
  TEMPLATE = <<-DOC
6
- @font-face
7
- font-family: "{{name}}"
6
+ @font-face {
7
+ font-family: "{{name}}";
8
8
  {{src}}
9
- font-weight: {{weight}}
10
- font-style: {{style}}
9
+ font-weight: {{weight}};
10
+ font-style: {{style}};
11
+ }
11
12
  DOC
12
13
 
13
14
  # Provide Font-Name as written in URL of font-squirrel,
14
15
  # like TeX-Gyre-Bonum
15
- def initialize(name,options={})
16
- @options=options
16
+ def initialize(name, options={})
17
+ @options = options
17
18
  @name = name
18
- download(name)
19
19
  FileUtils.mkdir_p @options[:font_dir]
20
+ unless File.exists? @options[:font_file]
21
+ FileUtils.touch @options[:font_file]
22
+ end
23
+ end
24
+
25
+ def download!
26
+ download(@name)
27
+ end
28
+
29
+ def extract_and_apply!
20
30
  zipfile = nil
21
31
  quietly do
22
32
  zipfile = Zip::File.open(@options[:tmp_name])
23
33
  end
24
34
  zipfile.each do |entry|
25
35
  case entry.name
26
- when %r{/stylesheet.css$}
36
+ when %r{/stylesheet.css$}, "stylesheet.css"
27
37
  append_stylesheet(entry)
28
38
  when /ttf|woff|eot|svg/
29
39
  extract_font(entry)
40
+ else
41
+ puts " skipping #{entry.name}"
30
42
  end
31
43
  end
32
44
 
33
- FileUtils.rm @options[:tmp_name].to_s
34
45
  ensure
35
46
  zipfile.close if zipfile.present?
36
47
  end
37
48
 
49
+ def remove_download_file
50
+ FileUtils.rm @options[:tmp_name].to_s
51
+ end
52
+
38
53
  private
39
54
 
40
55
  def name; @name; end
41
56
 
42
57
  def append_stylesheet(entry)
43
58
  content = entry.get_input_stream.read
44
- text = Sass::Engine.new(content, syntax: :scss).to_tree.to_sass
59
+ if content.blank?
60
+ puts " error: the stylesheets seems to be empty. Check if the font-kit on fontsquirrel has errors, too, and use the ttf-download + Webfont-generator to make a working zip-file"
61
+ return
62
+ end
63
+
64
+ existing = File.read(@options[:font_file].to_s)
65
+ text = Sass::Engine.new(content, syntax: :scss).to_tree.to_scss
66
+ binding.pry
45
67
  text.gsub!(/url\(([^\)]+)\)/, "asset-url(\\1, font)")
46
- headline = text.lines.grep(/font-family/).first
47
- weight = 'normal'
48
- style = 'normal'
49
- if headline[ /italic/ ]
50
- style = 'italic'
68
+ parts = text.split("@font-face")
69
+ out_file = ""
70
+ font_name = text.scan(/font-family: '(.*)'/).flatten.inject{|l,s| l=l.chop while l!=s[0...l.length];l}
71
+ parts.each do |part|
72
+ headline = part.lines.grep(/font-family/).first
73
+ next if !headline
74
+ weight = 'normal'
75
+ style = 'normal'
76
+ if headline[ /italic/ ]
77
+ style = 'italic'
78
+ end
79
+ if headline[ /bold/ ]
80
+ weight = 'bold'
81
+ end
82
+ template = TEMPLATE.
83
+ gsub('{{name}}', font_name).
84
+ gsub('{{weight}}', weight).
85
+ gsub('{{style}}', style).
86
+ gsub('{{src}}', part.lines.grep(/src:/).join.strip)
87
+ if !existing.include?(template)
88
+ out_file += template + "\n"
89
+ end
51
90
  end
52
- if headline[ /bold/ ]
53
- weight = 'bold'
91
+ if out_file.present?
92
+ log "Writing new font-definitions to #{@options[:font_file].to_s} (Font-Family: #{font_name})"
93
+ File.open(@options[:font_file].to_s, "a") {|f| f.write out_file }
54
94
  end
55
- template = TEMPLATE.
56
- gsub('{{name}}', @name).
57
- gsub('{{weight}}', weight).
58
- gsub('{{style}}', style).
59
- gsub('{{src}}', text.lines.grep(/src:/).join.strip)
60
- log "Writing new font-definitions to #{@options[:font_file].to_s} ( Font-Family: #{@name}, #{style}, #{weight})"
61
- File.open(@options[:font_file].to_s, "a") {|f| f.write template }
62
95
  end
63
96
 
64
97
  def extract_font(entry)
@@ -68,7 +101,7 @@ DOC
68
101
  end
69
102
 
70
103
  def download(name)
71
- url = "http://www.fontsquirrel.com/fontfacekit/#{name}"
104
+ url = "https://www.fontsquirrel.com/fontfacekit/#{name}"
72
105
  log "Downloading #{url}..."
73
106
  File.open(@options[:tmp_name], "wb+") { |f| f.write open(url).read }
74
107
  end
@@ -1,3 +1,3 @@
1
1
  module FontSquirrel
2
- VERSION = "1.1.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,17 +1,37 @@
1
1
 
2
2
  namespace :font do
3
+ FONT_FILE = 'app/assets/stylesheets/_fonts.scss'
3
4
  desc "Download and extract font-squirrel kit. Give Repos with NAME=TeX-Gyre-Bonum"
4
- task :kit do
5
+ task :download do
5
6
  name = ENV["NAME"]
6
7
  if name.blank?
7
8
  puts "give name to font with rake font:kit NAME=TeX-Gyre-Bonum"
8
9
  exit 1
9
10
  end
10
11
  require "fontsquirrel-download/download"
11
- FontSquirrel::Download.new name,
12
+ runner = FontSquirrel::Download.new name,
12
13
  tmp_name: Rails.root.join("tmp/fontsquirrel.zip").to_s,
13
- font_file: Rails.root.join("app/assets/stylesheets/_fonts.css.sass"),
14
+ font_file: Rails.root.join(FONT_FILE),
14
15
  font_dir: Rails.root.join("app/assets/fonts")
16
+ runner.download!
17
+ runner.extract_and_apply!
18
+ runner.remove_download_file
15
19
 
16
20
  end
21
+
22
+ desc "Extract font-squirrel web-fontkit. Takes path to zip-file FILE=/tmp/webfontkit-123.zip"
23
+ task :install do
24
+ name = ENV["FILE"]
25
+ if name.blank?
26
+ puts "provide the path to the font with rake font:install FILE=/tmp/webfontkit-123.zip"
27
+ exit 1
28
+ end
29
+ path = File.expand_path(name)
30
+ require "fontsquirrel-download/download"
31
+ runner = FontSquirrel::Download.new 'webfontkit',
32
+ tmp_name: path,
33
+ font_file: Rails.root.join(FONT_FILE),
34
+ font_dir: Rails.root.join("app/assets/fonts")
35
+ runner.extract_and_apply!
36
+ end
17
37
  end
metadata CHANGED
@@ -1,66 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontsquirrel-download
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Wienert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rubyzip
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rails
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - '>='
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '3.1'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - '>='
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '3.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rubyzip
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '1.0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '1.0'
55
- description: ' Download and extract font-kits from fontsquirrel easily with a rake
56
- tasks.'
41
+ description: " Download and extract font-kits from fontsquirrel easily with a rake
42
+ tasks."
57
43
  email:
58
44
  - stefan.wienert@pludoni.de
59
45
  executables: []
60
46
  extensions: []
61
47
  extra_rdoc_files: []
62
48
  files:
63
- - .gitignore
49
+ - ".gitignore"
64
50
  - Gemfile
65
51
  - LICENSE
66
52
  - README.md
@@ -81,19 +67,18 @@ require_paths:
81
67
  - lib
82
68
  required_ruby_version: !ruby/object:Gem::Requirement
83
69
  requirements:
84
- - - '>='
70
+ - - ">="
85
71
  - !ruby/object:Gem::Version
86
72
  version: '0'
87
73
  required_rubygems_version: !ruby/object:Gem::Requirement
88
74
  requirements:
89
- - - '>='
75
+ - - ">="
90
76
  - !ruby/object:Gem::Version
91
77
  version: '0'
92
78
  requirements: []
93
79
  rubyforge_project:
94
- rubygems_version: 2.0.3
80
+ rubygems_version: 2.4.8
95
81
  signing_key:
96
82
  specification_version: 4
97
83
  summary: Download and extract font-kits from fontsquirrel easily with a rake tasks.
98
84
  test_files: []
99
- has_rdoc: