g_web_font 0.0.1

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.
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 g_web_font.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dakota Dux
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,29 @@
1
+ # GWebFont
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'g_web_font'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install g_web_font
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # #!/usr/bin/env rake
2
+ # require "bundler/gem_tasks"
3
+
4
+
5
+ #!/usr/bin/env rake
6
+ begin
7
+ require 'bundler/setup'
8
+ rescue LoadError
9
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
10
+ end
11
+ begin
12
+ require 'rdoc/task'
13
+ rescue LoadError
14
+ require 'rdoc/rdoc'
15
+ require 'rake/rdoctask'
16
+ RDoc::Task = Rake::RDocTask
17
+ end
18
+
19
+ RDoc::Task.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'GWebFont'
22
+ # rdoc.options << '--line-numbers'
23
+ # rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/g_web_font/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dakota Dux"]
6
+ gem.email = ["dakota.dux@gmail.com"]
7
+ gem.description = %q{ Easy access to Google's Web Fonts }
8
+ gem.summary = %q{ Access a list of Google's webfonts through their API and provide rails views helpers }
9
+ gem.homepage = ""
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 = "g_web_font"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = GWebFont::VERSION
17
+
18
+ gem.add_development_dependency "rake"
19
+ # gem.add_development_dependency "rspec"
20
+ gem.add_dependency 'httparty'
21
+ gem.add_dependency 'oj'
22
+ gem.add_dependency 'hashie'
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'g_web_font/view_helpers'
2
+
3
+ module GWebFont
4
+ class Railtie < Rails::Railtie
5
+ initializer "g_web_font.view_helpers" do |app|
6
+ ActionView::Base.send :include, Helper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module GWebFont #:nodoc:
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ module GWebFonts
2
+
3
+ # Public: Helper module that includes the google_webfonts_link_tag method.
4
+ # This module is automatically included in your Rails view helpers.
5
+ module Helper
6
+
7
+ end
8
+ end
@@ -0,0 +1,109 @@
1
+ require 'g_web_font/view_helpers/tag_helper'
2
+
3
+ module GWebFont
4
+ module Helper
5
+ include ActionView::Helpers::TagHelper
6
+ BASE_URL = "fonts.googleapis.com/css?family=".freeze
7
+
8
+ # Generates the options for select for the Google Web Fonts
9
+ def web_font_options_for_select
10
+ options_for_select([''] | GWebFont::WebFont.list_fonts)
11
+ end
12
+
13
+ # From Google Webfonts Helper
14
+ # https://github.com/travishaynes/Google-Webfonts-Helper
15
+
16
+ # Public: Generates a Google Webfonts link tag
17
+ #
18
+ # options - The font options. This can be a String, Symbol, or Hash, or
19
+ # a combination of all three. If you need to specify a font
20
+ # size, use a Hash, otherwise a String or Symbol will work.
21
+ #
22
+ # Examples
23
+ #
24
+ # google_webfonts_link_tag "Droid Sans"
25
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css" />'
26
+ #
27
+ # google_webfonts_link_tag :droid_sans
28
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css" />'
29
+ #
30
+ # google_webfonts_link_tag :droid_sans => [400, 700]
31
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans:400,700" rel="stylesheet" type="text/css" />'
32
+ #
33
+ # google_webfonts_link_tag :droid_sans => [400, 700],
34
+ # :yanone_kaffeesatz => [300, 400]
35
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans:400,700|Yanone+Kaffeesatz:300,400" rel="stylesheet" type="text/css" />'
36
+ #
37
+ # google_webfonts_link_tag "Droid Sans",
38
+ # :yanone_kaffeesatz => 400
39
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans|Yanone+Kaffeesatz:400" rel="stylesheet" type="text/css" />'
40
+ #
41
+ # Returns a <link> tag for the Google Webfonts stylesheet.
42
+ # Raises ArgumentError if no options are passed.
43
+ # Raises ArgumentError if an option is not a Symbol, String, or Hash.
44
+ # Raises ArgumentError if a size is not a String or Fixnum.
45
+ def google_webfonts_link_tag(*options)
46
+ raise ArgumentError, "expected at least one font" if options.empty?
47
+
48
+ fonts = []
49
+
50
+ options.each do |option|
51
+ case option.class.to_s
52
+ when "Symbol", "String"
53
+ # titleize the font name
54
+ font_name = option.to_s.titleize
55
+
56
+ # replace any spaces with pluses
57
+ font_name = font_name.gsub(" ", "+")
58
+
59
+ # include the font
60
+ fonts << font_name
61
+ when "Hash"
62
+ fonts += option.inject([]) do |result, (font_name, sizes)|
63
+ # ensure sizes is an Array
64
+ sizes = Array(sizes)
65
+
66
+ sizes.all? do |size|
67
+ unless size.class == Fixnum || size.class == String
68
+ raise ArgumentError, "expected a Fixnum or String, got a #{ size.class }"
69
+ end
70
+ end
71
+
72
+ # convert font name into a String
73
+ font_name = font_name.to_s
74
+
75
+ # replace underscores with spaces
76
+ # and titleize the font name
77
+ font_name = font_name.gsub("_", " ")
78
+ font_name = font_name.titleize
79
+
80
+ # convert the spaces into pluses
81
+ font_name = font_name.gsub(" ", "+")
82
+
83
+ # return font_name:sizes where
84
+ # sizes is a comma separated list
85
+ result << "#{ font_name }:#{ sizes.join(",") }"
86
+ end
87
+ else
88
+ raise ArgumentError, "expected a String, Symbol, or a Hash, got a #{ option.class }"
89
+ end
90
+ end
91
+
92
+ # the fonts are separated by pipes
93
+ family = fonts.join("|")
94
+
95
+ # generate https links if we are an https site
96
+ request.ssl? ? request_method = "https" : request_method = "http"
97
+
98
+ # return the link tag
99
+ tag 'link', {
100
+ :rel => :stylesheet,
101
+ :type => Mime::CSS,
102
+ :href => "http://#{ BASE_URL }#{ family }",
103
+ :href => "#{ request_method }://#{ BASE_URL }#{ family }"
104
+ },
105
+ false,
106
+ false
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,23 @@
1
+ module GWebFont
2
+ BASE_URL = 'https://www.googleapis.com/webfonts/v1/webfonts'.freeze
3
+
4
+ class WebFont
5
+ class << self
6
+ def list_fonts
7
+ load_font_items.map{ |font| font['family'] }
8
+ end
9
+
10
+ def load_font_items
11
+ response = HTTParty.get(BASE_URL, :query => { :key => GWebFont.api_key })
12
+ font_items = Oj.load(response.body)['items']
13
+
14
+ font_items
15
+ end
16
+ end
17
+ end
18
+
19
+ class << self
20
+ attr_accessor :api_key
21
+ end
22
+
23
+ end
data/lib/g_web_font.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+ require 'oj'
3
+
4
+ require "g_web_font/version"
5
+ require 'g_Web_font/web_font'
6
+
7
+ require 'g_web_font/railtie' if defined? Rails
8
+
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'g_web_font'
3
+
4
+ class GWebFontTest < Test::Unit::TestCase
5
+ def api_key
6
+ # Enter your API Key here
7
+ end
8
+
9
+ def test_version
10
+ assert_equal GWebFont::VERSION, '0.0.1'
11
+ end
12
+
13
+ def test_set_api_key
14
+ GWebFont.api_key = api_key
15
+ assert_equal GWebFont.api_key, api_key
16
+ end
17
+
18
+ def test_load_font_items
19
+ GWebFont.api_key = api_key
20
+ font_items = GWebFont::WebFont.load_font_items
21
+ assert !font_items.nil?
22
+ end
23
+
24
+ def test_list_fonts
25
+ GWebFont.api_key = api_key
26
+ fonts = GWebFont::WebFont.list_fonts
27
+ assert fonts.is_a?(Array)
28
+ assert !fonts.empty?
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: g_web_font
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dakota Dux
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: oj
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: hashie
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! ' Easy access to Google''s Web Fonts '
79
+ email:
80
+ - dakota.dux@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - g_web_font.gemspec
91
+ - lib/g_web_font.rb
92
+ - lib/g_web_font/railtie.rb
93
+ - lib/g_web_font/version.rb
94
+ - lib/g_web_font/view_helpers.rb
95
+ - lib/g_web_font/view_helpers/tag_helper.rb
96
+ - lib/g_web_font/web_font.rb
97
+ - test/g_web_font_test.rb
98
+ homepage: ''
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.24
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Access a list of Google's webfonts through their API and provide rails views
122
+ helpers
123
+ test_files:
124
+ - test/g_web_font_test.rb