google_font_extractor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The GoogleFontExtractor Gem will crawl the Google Webfonts directory on your command and return an array of Struct instances with details of fonts available in the Google Fonts directory.
4
4
 
5
- PLEASE Note: this does NOT download the font files themselves.
5
+ PLEASE Note: this does NOT download the font files themselves, although it does return the download url if you wanted to automate obtaining the .ttf file for each font.
6
6
 
7
7
  Let's get started.
8
8
 
@@ -12,11 +12,12 @@ Let's get started.
12
12
  ## 2. Bundle Install
13
13
 
14
14
  ## 3. rails console example
15
- ruby-1.9.2> fonts = GoogleFontExtractor.extract
15
+ ruby-1.9.2> fonts = GoogleFontExtractor.fonts
16
16
  ruby-1.9.2> fonts.first
17
- => #<struct designer="Steve Matteson", name="Droid Serif", charsets=["latin"], weights_count="4", weights=["regular", "italic", "bold", "bolditalic"], families_count=nil, category="serif">
17
+ => #<struct designer="Steve Matteson", name="Droid Serif", charsets=["latin"], weights_count="4", weights=["regular", "italic", "bold", "bolditalic"], families_count=nil, category="serif", download_url="http://www.google.com/webfonts/download?kit=JHlfjS1nNpVY2eojiON_TqCzlCNBPNJyfLyExqzYYTM">
18
18
  ruby-1.9.2>
19
19
 
20
20
 
21
21
  # Additional notes
22
- If you want to do anything real with this, you should save the results of the extract method to a YAML file or database table.
22
+ If you want to do anything real with this, you should save the results of the extract method to a YAML file or database table.
23
+
@@ -13,7 +13,17 @@ module GoogleFontExtractor
13
13
  end
14
14
  end
15
15
 
16
- result :weights
16
+ # Find the Download url in the download tab. Note that there are 2 formats for this
17
+ # tab, one where it shows a "buy form" with a sublink to "download the font directly",
18
+ # and another where it provides the download link first as "click here to download {font name}".
19
+ # The latter includes a full url, whereas the the first includes a relative url. Also fix that.
20
+ process("#_download a[href*='download']", :download_url => "@href") do |el|
21
+ if @download_url !~ /google/ then
22
+ @download_url = "http://www.google.com#{@download_url}"
23
+ end
24
+ end
25
+
26
+ result :weights, :download_url
17
27
  end
18
28
 
19
29
  # Element within list of fonts
@@ -22,6 +32,7 @@ module GoogleFontExtractor
22
32
  array :charsets
23
33
 
24
34
  attr_accessor :category # for storing serif, sans-serif, etc
35
+ attr_accessor :download_url
25
36
 
26
37
  # Font Name
27
38
  process "div.preview span", :name => :text
@@ -54,7 +65,7 @@ module GoogleFontExtractor
54
65
  end
55
66
  end
56
67
 
57
- result :designer, :name, :charsets, :weights_count, :weights, :families_count, :category
68
+ result :designer, :name, :charsets, :weights_count, :weights, :families_count, :category, :download_url
58
69
  end
59
70
 
60
71
 
@@ -41,9 +41,9 @@ module GoogleFontExtractor
41
41
  # Further enhance final list of fonts with additional information from the individual font pages
42
42
  # so we can provide information about the font weights (bold, etc) that are available.
43
43
  final_font_list.each_with_index do |font, idx|
44
- if font.weights_count then
45
- font.weights = Extract::FontPage.scrape(URI.parse("http://www.google.com/webfonts/family?family=#{URI.encode(font.name)}"))
46
- end
44
+ font_page = Extract::FontPage.scrape(URI.parse("http://www.google.com/webfonts/family?family=#{URI.encode(font.name)}"))
45
+ font[:weights] = font_page.weights
46
+ font[:download_url] = font_page.download_url
47
47
  end
48
48
  end
49
49
 
@@ -1,3 +1,3 @@
1
1
  module GoogleFontExtractor
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jason Lambert
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-18 00:00:00 +00:00
17
+ date: 2011-03-23 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency