fontsquirrel-download 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c356c2c0a752b8ec5291a889a4841b2e4ce4da22
4
+ data.tar.gz: 9cdd7fa686bc80679739afe16981b04ec1e1efa7
5
+ SHA512:
6
+ metadata.gz: 74338ddcca78d04bfbdfadd0fd833a61f5545e0362c1487db9f1d182381a7d5de067c679817d6e4a6bc4932fb17356a1efc63c9e19ff516a24d75691cfe9133f
7
+ data.tar.gz: 739eae9bb096beee3c94fbea47c3d0502a8048cccf3b9bdcffd928e1747f7ca6b3a31eaae382abd4d7a5947cc9012f2222ef5b545ccb80ea366a14eb4941f632
@@ -2,6 +2,14 @@ require "open-uri"
2
2
  require "zip/zip"
3
3
  module FontSquirrel
4
4
  class Download
5
+ TEMPLATE = <<-DOC
6
+ @font-face
7
+ font-family: "{{name}}"
8
+ {{src}}
9
+ font-weight: {{weight}}
10
+ font-style: {{style}}
11
+ DOC
12
+
5
13
  # Provide Font-Name as written in URL of font-squirrel,
6
14
  # like TeX-Gyre-Bonum
7
15
  def initialize(name,options={})
@@ -9,34 +17,52 @@ module FontSquirrel
9
17
  @name = name
10
18
  download(name)
11
19
  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
+ zipfile = nil
21
+ quietly do
22
+ zipfile = Zip::ZipFile.open(@options[:tmp_name])
23
+ end
24
+ zipfile.each do |entry|
25
+ case entry.name
26
+ when %r{/stylesheet.css$}
27
+ append_stylesheet(entry)
28
+ when /ttf|woff|eot|svg/
29
+ extract_font(entry)
20
30
  end
21
31
  end
22
- FileUtils.rm @options[:tmp_name].to_s
23
32
 
33
+ FileUtils.rm @options[:tmp_name].to_s
34
+ ensure
35
+ zipfile.close
24
36
  end
25
37
 
26
-
27
-
28
38
  private
39
+
29
40
  def name; @name; end
41
+
30
42
  def append_stylesheet(entry)
31
43
  content = entry.get_input_stream.read
32
44
  text = Sass::Engine.new(content, syntax: :scss).to_tree.to_sass
33
45
  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 }
46
+ headline = text.lines.grep(/font-family/).first
47
+ weight = 'normal'
48
+ style = 'normal'
49
+ if headline[ /italic/ ]
50
+ style = 'italic'
51
+ end
52
+ if headline[ /bold/ ]
53
+ weight = 'bold'
54
+ 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 }
36
62
  end
37
63
 
38
64
  def extract_font(entry)
39
- target = @options[:font_dir].join(entry.name).to_s
65
+ target = @options[:font_dir].join(File.basename entry.to_s).to_s
40
66
  FileUtils.copy_stream entry.get_input_stream, File.open(target, "wb+")
41
67
  log "Extracting #{target}"
42
68
  end
@@ -53,3 +79,5 @@ module FontSquirrel
53
79
 
54
80
  end
55
81
  end
82
+
83
+ __END__
@@ -1,3 +1,3 @@
1
1
  module FontSquirrel
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -9,9 +9,9 @@ namespace :font do
9
9
  end
10
10
  require "fontsquirrel-download/download"
11
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")
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
15
 
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,39 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontsquirrel-download
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stefan Wienert
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-13 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rubyzip
16
- requirement: &78163800 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *78163800
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rails
27
- requirement: &78163540 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '3.1'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *78163540
36
- description: ! ' Download and extract font-kits from fontsquirrel easily with a rake
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ description: ' Download and extract font-kits from fontsquirrel easily with a rake
37
42
  tasks.'
38
43
  email:
39
44
  - stefan.wienert@pludoni.de
@@ -54,32 +59,25 @@ files:
54
59
  - lib/tasks/fontsquirrel-download.rake
55
60
  homepage: https://github.com/zealot128/fontsquirrel-download
56
61
  licenses: []
62
+ metadata: {}
57
63
  post_install_message:
58
64
  rdoc_options: []
59
65
  require_paths:
60
66
  - lib
61
67
  required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
68
  requirements:
64
- - - ! '>='
69
+ - - '>='
65
70
  - !ruby/object:Gem::Version
66
71
  version: '0'
67
- segments:
68
- - 0
69
- hash: 542117729
70
72
  required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
73
  requirements:
73
- - - ! '>='
74
+ - - '>='
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
- segments:
77
- - 0
78
- hash: 542117729
79
77
  requirements: []
80
78
  rubyforge_project:
81
- rubygems_version: 1.8.15
79
+ rubygems_version: 2.0.3
82
80
  signing_key:
83
- specification_version: 3
81
+ specification_version: 4
84
82
  summary: Download and extract font-kits from fontsquirrel easily with a rake tasks.
85
83
  test_files: []