google-webfonts 0.1.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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google-webfonts.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Travis Haynes
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,45 @@
1
+ # Google::Webfonts
2
+
3
+ Provides a helper for using Google Webfonts in a Rails application.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'google-webfonts'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install google-webfonts
19
+
20
+
21
+ ## Usage
22
+
23
+ webfonts_link_tag :font => [sizes], ...
24
+
25
+ ### Examples
26
+
27
+ # generate a tag for Dosis and Revalia fonts
28
+ # without a specified font weights
29
+ webfonts_link_tag :dosis, :revalia
30
+
31
+ # generate a tag for Droid+Sans in weights 400 and 700
32
+ webfonts_link_tag :droid_sans => [400, 700]
33
+
34
+ # generate a tag for the above font and
35
+ # Yanone+Kaffeesatz in weights 300 and 400
36
+ webfonts_link_tag :droid_sans => [400, 700], :yanone_kaffeesatz => [300, 400]
37
+
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/google-webfonts/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Travis Haynes"]
6
+ gem.email = ["travis.j.haynes@gmail.com"]
7
+ gem.description = %q{Provides a helper for using Google Webfonts in a Rails application.}
8
+ gem.summary = %q{Provides a helper for using Google Webfonts in a Rails application.}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "google-webfonts"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Google::Webfonts::VERSION
17
+
18
+ gem.add_runtime_dependency 'actionpack', '>= 3.0.0'
19
+
20
+ gem.add_development_dependency 'rspec', '~> 2.8.0'
21
+ gem.add_development_dependency 'tomdoc', '~> 0.2.5'
22
+ end
@@ -0,0 +1,14 @@
1
+ require "action_view"
2
+
3
+ # Public: Module for Google helpers
4
+ module Google
5
+ # Public: Module for Google Webfonts helpers
6
+ module Webfonts
7
+ end
8
+ end
9
+
10
+ require "google-webfonts/version"
11
+ require "google-webfonts/helper"
12
+
13
+ # include the webfonts helper methods in the Rails view helpers
14
+ ActionView::Base.send :include, Google::Webfonts::Helper
@@ -0,0 +1,100 @@
1
+ module Google
2
+ module Webfonts
3
+
4
+ # Public: Helper module that includes the google_webfonts_link_tag method.
5
+ # This module is automatically included in your Rails view helpers.
6
+ module Helper
7
+ include ActionView::Helpers::TagHelper
8
+
9
+ # Public: Generates a Google Webfonts link tag
10
+ #
11
+ # options - The font options. This can be a String, Symbol, or Hash, or
12
+ # a combination of all three. If you need to specify a font
13
+ # size, use a Hash, otherwise a String or Symbol will work.
14
+ #
15
+ # Examples
16
+ #
17
+ # google_webfonts_link_tag "Droid Sans"
18
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css" />'
19
+ #
20
+ # google_webfonts_link_tag :droid_sans
21
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css" />'
22
+ #
23
+ # google_webfonts_link_tag :droid_sans => [400, 700]
24
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans:400,700" rel="stylesheet" type="text/css" />'
25
+ #
26
+ # google_webfonts_link_tag :droid_sans => [400, 700],
27
+ # :yanone_kaffeesatz => [300, 400]
28
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans:400,700|Yanone+Kaffeesatz:300,400" rel="stylesheet" type="text/css" />'
29
+ #
30
+ # google_webfonts_link_tag "Droid Sans",
31
+ # :yanone_kaffeesatz => 400
32
+ # # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans|Yanone+Kaffeesatz:400" rel="stylesheet" type="text/css" />'
33
+ #
34
+ # Returns a <link> tag for the Google Webfonts stylesheet.
35
+ # Raises ArgumentError if no options are passed.
36
+ # Raises ArgumentError if an option is not a Symbol, String, or Hash.
37
+ # Raises ArgumentError if a size is not a String or Fixnum.
38
+ def google_webfonts_link_tag(*options)
39
+ raise ArgumentError, "expected at least one font" if options.empty?
40
+
41
+ fonts = []
42
+
43
+ options.each do |option|
44
+ case option.class.to_s
45
+ when "Symbol", "String"
46
+ # titleize the font name
47
+ font_name = option.to_s.titleize
48
+
49
+ # replace any spaces with pluses
50
+ font_name = font_name.gsub(" ", "+")
51
+
52
+ # include the font
53
+ fonts << font_name
54
+ when "Hash"
55
+ fonts += option.inject([]) do |result, (font_name, sizes)|
56
+ # ensure sizes is an Array
57
+ sizes = Array(sizes)
58
+
59
+ sizes.all? do |size|
60
+ unless size.class == Fixnum || size.class == String
61
+ raise ArgumentError, "expected a Fixnum or String, got a #{size.class}"
62
+ end
63
+ end
64
+
65
+ # convert font name into a String
66
+ font_name = font_name.to_s
67
+
68
+ # replace underscores with spaces
69
+ # and titleize the font name
70
+ font_name = font_name.gsub("_", " ")
71
+ font_name = font_name.titleize
72
+
73
+ # convert the spaces into pluses
74
+ font_name = font_name.gsub(" ", "+")
75
+
76
+ # return font_name:sizes where
77
+ # sizes is a comma separated list
78
+ result << "#{font_name}:#{sizes.join(",")}"
79
+ end
80
+ else
81
+ raise ArgumentError, "expected a String, Symbol, or a Hash, got a #{option.class}"
82
+ end
83
+ end
84
+
85
+ # the fonts are separated by pipes
86
+ family = fonts.join("|")
87
+
88
+ # return the link tag
89
+ tag 'link', {
90
+ :rel => :stylesheet,
91
+ :type => Mime::CSS,
92
+ :href => "http://fonts.googleapis.com/css?family=#{family}"
93
+ },
94
+ false,
95
+ false
96
+ end
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,6 @@
1
+ module Google
2
+ module Webfonts
3
+ # Public: Current version of the gem
4
+ VERSION = "0.1.1"
5
+ end
6
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe Google::Webfonts::Helper do
4
+ include Google::Webfonts::Helper
5
+
6
+ def validate(tag, family)
7
+ # should be a link tag
8
+ tag.should =~ /<link.*\/>/
9
+
10
+ # should include an href to the google webfonts api
11
+ tag.should =~ /href="http:\/\/fonts.googleapis.com\/css\?family=/
12
+
13
+ # should be a stylesheet
14
+ tag.should =~ /rel="stylesheet"/
15
+
16
+ # should be text/css
17
+ tag.should =~ /type="text\/css"/
18
+
19
+ # should include the expected font-family
20
+ tag.should =~ /#{family}/
21
+ end
22
+
23
+ describe "#google_webfonts_link_tag" do
24
+
25
+ context "with no arguments" do
26
+ it "should raise ArgumentError" do
27
+ expect { google_webfonts_link_tag }.to raise_error ArgumentError
28
+ end
29
+ end
30
+
31
+ context "with something other than a String, Symbol, or Hash" do
32
+ it "should raise ArgumentError" do
33
+ expect { google_webfonts_link_tag(1) }.to raise_error ArgumentError
34
+ end
35
+ end
36
+
37
+ context "when a size is something other than a String, or Fixnum" do
38
+ it "should raise ArgumentError" do
39
+ expect { google_webfonts_link_tag(:font => [:symbol]) }.to raise_error ArgumentError
40
+ end
41
+ end
42
+
43
+ specify "with 1 font as a String" do
44
+ validate google_webfonts_link_tag("hello"), "Hello"
45
+ end
46
+
47
+ specify "with 1 font as a Symbol" do
48
+ validate google_webfonts_link_tag(:hello), "Hello"
49
+ end
50
+
51
+ specify "with multiple fonts as Strings" do
52
+ validate google_webfonts_link_tag("hello", "world"), "Hello|World"
53
+ end
54
+
55
+ specify "with multiple fonts as a combination of Strings and Symbols" do
56
+ validate google_webfonts_link_tag("hello", :world), "Hello|World"
57
+ end
58
+
59
+ context "with a Hash and 1 font name" do
60
+ context "with a Symbol as the key" do
61
+ specify "with 1 font size" do
62
+ validate google_webfonts_link_tag(:hello => 100), "Hello:100"
63
+ end
64
+
65
+ specify "with 2 font sizes" do
66
+ validate google_webfonts_link_tag(:hello => [100, 200]), "Hello:100,200"
67
+ end
68
+ end
69
+
70
+ context "with a String as the key" do
71
+ specify "with 1 font size" do
72
+ validate google_webfonts_link_tag("hello" => 100), "Hello:100"
73
+ end
74
+
75
+ specify "with 2 font sizes" do
76
+ validate google_webfonts_link_tag("hello" => [100, 200]), "Hello:100,200"
77
+ end
78
+ end
79
+ end
80
+
81
+ context "with a Hash and 2 font names" do
82
+ context "with a Symbol as the key" do
83
+ specify "with 1 font size" do
84
+ validate google_webfonts_link_tag(:hello => 100, :world => 200), "Hello:100|World:200"
85
+ end
86
+
87
+ specify "with 2 font sizes" do
88
+ validate google_webfonts_link_tag(:hello => [100, 200], :world => [300, 400]), "Hello:100,200|World:300,400"
89
+ end
90
+ end
91
+
92
+ context "with a String as the key" do
93
+ specify "with 1 font size" do
94
+ validate google_webfonts_link_tag("hello" => 100, "world" => 200), "Hello:100|World:200"
95
+ end
96
+
97
+ specify "with 2 font sizes" do
98
+ validate google_webfonts_link_tag("hello" => [100, 200], "world" => [300, 400]), "Hello:100,200|World:300,400"
99
+ end
100
+ end
101
+ end
102
+
103
+ context "when the font name includes an underscore" do
104
+ it "should convert the underscore to a +" do
105
+ validate google_webfonts_link_tag(:droid_sans => [400, 700]), 'Droid\+Sans:400,700'
106
+ end
107
+ end
108
+
109
+ context "when the font name includes a space" do
110
+ it "should conver the space to a +" do
111
+ validate google_webfonts_link_tag("Droid Sans" => [400, 700]), 'Droid\+Sans:400,700'
112
+ end
113
+ end
114
+
115
+ context "with a combination of all acceptable values" do
116
+ it "should validate" do
117
+ validate google_webfonts_link_tag(
118
+ :font1, "font2", :font_3, "Font 4",
119
+ :font_5 => 100,
120
+ "font_6" => [200, 300]
121
+ ), 'Font1|Font2|Font\+3|Font\+4|Font\+5:100|Font\+6:200,300'
122
+ end
123
+ end
124
+ end
125
+
126
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Google::Webfonts::VERSION do
4
+ it "should be version 0.1.1" do
5
+ Google::Webfonts::VERSION.should eq "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Google::Webfonts do
4
+ it "should include Helper in ActionView" do
5
+ ActionView::Base.ancestors.should include Google::Webfonts::Helper
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require "google-webfonts"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-webfonts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Travis Haynes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: &19610360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19610360
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &19609060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *19609060
36
+ - !ruby/object:Gem::Dependency
37
+ name: tomdoc
38
+ requirement: &19608400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.5
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *19608400
47
+ description: Provides a helper for using Google Webfonts in a Rails application.
48
+ email:
49
+ - travis.j.haynes@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - google-webfonts.gemspec
61
+ - lib/google-webfonts.rb
62
+ - lib/google-webfonts/helper.rb
63
+ - lib/google-webfonts/version.rb
64
+ - spec/google-webfonts/helper_spec.rb
65
+ - spec/google-webfonts/version_spec.rb
66
+ - spec/google-webfonts_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: ''
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Provides a helper for using Google Webfonts in a Rails application.
92
+ test_files: []