google-webfonts 0.1.2 → 0.2.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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/README.md +3 -1
- data/Rakefile +8 -1
- data/google-webfonts.gemspec +27 -23
- data/lib/google-webfonts.rb +9 -3
- data/lib/google-webfonts/helper.rb +26 -82
- data/lib/google-webfonts/link_tag.rb +68 -0
- data/lib/google-webfonts/version.rb +1 -1
- data/test/lib/google-webfonts/helper_test.rb +21 -0
- data/test/lib/google-webfonts/link_tag_test.rb +52 -0
- data/test/lib/google-webfonts/sinatra_test.rb +25 -0
- data/test/lib/google-webfonts_test.rb +11 -0
- data/test/test_helper.rb +16 -0
- metadata +69 -35
- data/.rspec +0 -1
- data/spec/google-webfonts/helper_spec.rb +0 -126
- data/spec/google-webfonts/sinatra_spec.rb +0 -23
- data/spec/google-webfonts/version_spec.rb +0 -7
- data/spec/google-webfonts_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f25bcacd54d5215e32e042a398f6d509b8f12aaa
|
4
|
+
data.tar.gz: fdfdaf3395363ef350b76db9b011e7c15520f606
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd56576397bf306107d3d52fd73383d37df8bb739bb43bfce026f066487bd18c873bdeadbafd6b4bb0a9cdaaab6e5e5bde1464be588f1669eeaf265d47901626
|
7
|
+
data.tar.gz: b73db19e8b453ec28bcbd102495bcb56dda24627b1d56715489f0ab6fe53b482aea2f6317035da7096726ea40dc0b303eb6c3adcf7411e0f529d9acc46c19f46
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/google-webfonts.gemspec
CHANGED
@@ -1,26 +1,30 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google-webfonts/version'
|
3
5
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
gem.summary = %q{Provides a helper for using Google Webfonts in Rails or
|
10
|
-
Sinatra, although it can be used outside of those frameworks as well.}
|
11
|
-
|
12
|
-
gem.homepage = "https://github.com/travishaynes/Google-Webfonts-Helper"
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google-webfonts"
|
8
|
+
spec.version = Google::Webfonts::VERSION
|
9
|
+
spec.authors = ["Travis Haynes"]
|
10
|
+
spec.email = ["travis.j.haynes@gmail.com"]
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
spec.summary = "Provides a helper for using Google Webfonts in Rails or " +
|
13
|
+
"Sinatra, although it can be used outside of those " +
|
14
|
+
"frameworks as well."
|
15
|
+
|
16
|
+
spec.description = "Google Webfonts helper for Rails or Sinatra applications."
|
17
|
+
|
18
|
+
spec.homepage = "https://github.com/travishaynes/Google-Webfonts-Helper"
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^test/})
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'actionpack', '>= 3.0.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '>= 1.3.0', '< 2.0'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.3.3'
|
29
|
+
spec.add_development_dependency 'sinatra', '~> 1.3.2'
|
26
30
|
end
|
data/lib/google-webfonts.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'uri'
|
2
|
+
require 'action_view'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'action_dispatch/http/mime_type'
|
2
5
|
|
3
6
|
# Public: Module for Google helpers
|
4
7
|
module Google
|
5
8
|
# Public: Module for Google Webfonts helpers
|
6
9
|
module Webfonts
|
10
|
+
HOST = 'fonts.googleapis.com'
|
11
|
+
PATH = '/css'
|
7
12
|
end
|
8
13
|
end
|
9
14
|
|
10
|
-
require
|
11
|
-
require
|
15
|
+
require 'google-webfonts/version'
|
16
|
+
require 'google-webfonts/link_tag'
|
17
|
+
require 'google-webfonts/helper'
|
12
18
|
|
13
19
|
require 'google-webfonts/sinatra' if defined? Sinatra
|
14
20
|
|
@@ -1,100 +1,44 @@
|
|
1
1
|
module Google
|
2
2
|
module Webfonts
|
3
|
-
|
3
|
+
|
4
4
|
# Public: Helper module that includes the google_webfonts_link_tag method.
|
5
5
|
# This module is automatically included in your Rails view helpers.
|
6
6
|
module Helper
|
7
|
-
include ActionView::Helpers::TagHelper
|
8
|
-
|
9
7
|
# Public: Generates a Google Webfonts link tag
|
10
|
-
#
|
8
|
+
#
|
9
|
+
# If you need to specify a font size, use a Hash. Symbols will be
|
10
|
+
# titleized, so if the font you're using uses a specialized case
|
11
|
+
# (e.g: "PT Sans"), then you'll need to use a String.
|
12
|
+
#
|
13
|
+
# You can specify subsets by using the :subset option. Note that this must
|
14
|
+
# be a Symbol. "Subset" and "subset" would be turned into a font.
|
15
|
+
#
|
11
16
|
# options - The font options. This can be a String, Symbol, or Hash, or
|
12
|
-
# a combination of all three.
|
13
|
-
# size, use a Hash, otherwise a String or Symbol will work.
|
17
|
+
# a combination of all three.
|
14
18
|
#
|
15
19
|
# Examples
|
16
20
|
#
|
17
|
-
# google_webfonts_link_tag "
|
18
|
-
#
|
19
|
-
#
|
21
|
+
# google_webfonts_link_tag "PT Sans"
|
22
|
+
#
|
20
23
|
# google_webfonts_link_tag :droid_sans
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# # => '<link href="http://fonts.googleapis.com/css?family=Droid+Sans|Yanone+Kaffeesatz:400" rel="stylesheet" type="text/css" />'
|
24
|
+
#
|
25
|
+
# google_webfonts_link_tag droid_sans: [400, 700]
|
26
|
+
#
|
27
|
+
# google_webfonts_link_tag droid_sans: [400, 700],
|
28
|
+
# yanone_kaffeesatz: 700
|
29
|
+
#
|
30
|
+
# google_webfonts_link_tag :droid_sans,
|
31
|
+
# yanone_kaffeesatz: 400,
|
32
|
+
# "PT Sans" => [400, 700]
|
33
|
+
#
|
34
|
+
# google_webfonts_link_tag :droid_sans, subset: %w[latin cyrillic]
|
33
35
|
#
|
34
36
|
# Returns a <link> tag for the Google Webfonts stylesheet.
|
35
37
|
# Raises ArgumentError if no options are passed.
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
38
|
+
def google_webfonts_link_tag(*opts)
|
39
|
+
raise ArgumentError, 'expected at least one font', caller if opts.empty?
|
40
|
+
LinkTag.new(request, *opts).result
|
96
41
|
end
|
97
42
|
end
|
98
|
-
|
99
43
|
end
|
100
44
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Google
|
2
|
+
module Webfonts
|
3
|
+
class LinkTag
|
4
|
+
include ActionView::Helpers::TagHelper
|
5
|
+
|
6
|
+
attr_reader :result
|
7
|
+
|
8
|
+
alias_method :to_s, :result
|
9
|
+
|
10
|
+
def initialize(request, *opts)
|
11
|
+
@request = request
|
12
|
+
@subsets = []
|
13
|
+
@fonts = fonts_from_options(opts)
|
14
|
+
@result = tag(:link, link_options, false, false)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def fonts_from_options(opts)
|
20
|
+
opts.map {|option| parse_google_webfont_option(option) }.flatten
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_google_webfont_option(option)
|
24
|
+
case option
|
25
|
+
when Symbol, String then parse_google_webfont_name(option)
|
26
|
+
when Hash then parse_google_webfont_hash(option)
|
27
|
+
else ""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_google_webfont_hash(hash)
|
32
|
+
add_subsets(hash.delete(:subset))
|
33
|
+
|
34
|
+
hash.inject([]) do |result, (font_name, sizes)|
|
35
|
+
font_name = parse_google_webfont_name(font_name)
|
36
|
+
result << "#{font_name}:#{Array(sizes).join(",")}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_google_webfont_name(name)
|
41
|
+
name = name.to_s.titleize if name.is_a?(Symbol)
|
42
|
+
name.gsub("_", " ")
|
43
|
+
end
|
44
|
+
|
45
|
+
def link_options
|
46
|
+
{ rel: 'stylesheet',
|
47
|
+
type: Mime::CSS,
|
48
|
+
href: uri.to_s }
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_subsets(subsets)
|
52
|
+
@subsets += Array(subsets)
|
53
|
+
end
|
54
|
+
|
55
|
+
def uri
|
56
|
+
u = @request.ssl? ? URI::HTTPS : URI::HTTP
|
57
|
+
u.build(host: HOST, path: PATH, query: uri_query)
|
58
|
+
end
|
59
|
+
|
60
|
+
def uri_query
|
61
|
+
{}.tap {|q|
|
62
|
+
q['family'] = @fonts.join("|")
|
63
|
+
q['subset'] = @subsets.join(",") if @subsets.any?
|
64
|
+
}.to_query
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Google
|
4
|
+
module Webfonts
|
5
|
+
class HelperTest < Minitest::Test
|
6
|
+
include Helper
|
7
|
+
|
8
|
+
def test_google_webfonts_link_tag
|
9
|
+
options = { droid_sans: [400, 700] }
|
10
|
+
link_tag = LinkTag.new(request, options)
|
11
|
+
assert_equal link_tag.result, google_webfonts_link_tag(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def request
|
17
|
+
OpenStruct.new(:ssl? => false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Google
|
4
|
+
module Webfonts
|
5
|
+
class LinkTagTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@http_request = OpenStruct.new(:ssl? => false)
|
8
|
+
@https_request = OpenStruct.new(:ssl? => true)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_subsets
|
12
|
+
tag = LinkTag.new(@http_request, droid_sans: [400, 700],
|
13
|
+
subset: %w[latin cyrillic]).result
|
14
|
+
assert_tag tag, 'link',
|
15
|
+
href: 'http://fonts.googleapis.com/css?family=Droid+Sans%3A400%2C700&subset=latin%2Ccyrillic'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_uri_protocol
|
19
|
+
tag = LinkTag.new(@http_request, droid_sans: [400, 700]).result
|
20
|
+
assert_tag tag, 'link',
|
21
|
+
href: 'http://fonts.googleapis.com/css?family=Droid+Sans%3A400%2C700'
|
22
|
+
|
23
|
+
tag = LinkTag.new(@https_request, droid_sans: [400, 700]).result
|
24
|
+
assert_tag tag, 'link',
|
25
|
+
href: 'https://fonts.googleapis.com/css?family=Droid+Sans%3A400%2C700'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_with_font_sizes
|
29
|
+
tag = LinkTag.new(@http_request, droid_sans: [400, 700]).result
|
30
|
+
assert_tag tag, 'link',
|
31
|
+
href: 'http://fonts.googleapis.com/css?family=Droid+Sans%3A400%2C700'
|
32
|
+
|
33
|
+
tag = LinkTag.new(@http_request, droid_sans: [400, 700],
|
34
|
+
'PT Sans' => [400, 700]).result
|
35
|
+
assert_tag tag, 'link',
|
36
|
+
href: 'http://fonts.googleapis.com/css?family=Droid+Sans%3A400%2C700%7CPT+Sans%3A400%2C700'
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_strings_are_not_titleized
|
40
|
+
tag = LinkTag.new(@http_request, 'PT Sans').result
|
41
|
+
assert_tag tag, 'link',
|
42
|
+
href: 'http://fonts.googleapis.com/css?family=PT+Sans'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_symbols_are_titleized
|
46
|
+
tag = LinkTag.new(@http_request, :droid_sans).result
|
47
|
+
assert_tag tag, 'link',
|
48
|
+
href: 'http://fonts.googleapis.com/css?family=Droid+Sans'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# create a Sinatra route for testing
|
4
|
+
get("/") { google_webfonts_link_tag droid_sans: [400, 700] }
|
5
|
+
|
6
|
+
class SinatraTest < Minitest::Test
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
def app
|
10
|
+
Sinatra::Application
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_google_webfonts_link_tag_helper_loaded_in_sinatra
|
14
|
+
get "/"
|
15
|
+
options = { droid_sans: [400, 700] }
|
16
|
+
link_tag = Google::Webfonts::LinkTag.new(request, options)
|
17
|
+
assert_equal link_tag.result, last_response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def request
|
23
|
+
OpenStruct.new(:ssl? => false)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Google::WebfontsTest < Minitest::Test
|
4
|
+
def test_helper_is_included_in_action_view_base
|
5
|
+
assert ActionView::Base.ancestors.include?(Google::Webfonts::Helper)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_helper_is_included_in_sinatra
|
9
|
+
assert Sinatra::Application.ancestors.include?(Google::Webfonts::Helper)
|
10
|
+
end
|
11
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'sinatra'
|
5
|
+
require 'google-webfonts'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/unit'
|
8
|
+
require 'rack/test'
|
9
|
+
|
10
|
+
class Minitest::Test
|
11
|
+
def assert_tag(el, tag, props={})
|
12
|
+
assert el =~ /<#{tag}.*\/>/ , "expected a #{tag} tag"
|
13
|
+
assert props.all? {|key, value| el.include?("#{key}=\"#{value}\"") },
|
14
|
+
"tag's properties do not match"
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,91 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-webfonts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Travis Haynes
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: actionpack
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
- - <
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2.0'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.3.0
|
44
|
+
- - <
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
31
52
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
53
|
+
version: '0'
|
33
54
|
type: :development
|
34
55
|
prerelease: false
|
35
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
36
61
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
39
|
-
none: false
|
62
|
+
name: minitest
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
40
64
|
requirements:
|
41
65
|
- - ~>
|
42
66
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
67
|
+
version: 5.3.3
|
44
68
|
type: :development
|
45
69
|
prerelease: false
|
46
|
-
version_requirements:
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 5.3.3
|
47
75
|
- !ruby/object:Gem::Dependency
|
48
76
|
name: sinatra
|
49
|
-
requirement:
|
50
|
-
none: false
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
51
78
|
requirements:
|
52
79
|
- - ~>
|
53
80
|
- !ruby/object:Gem::Version
|
54
81
|
version: 1.3.2
|
55
82
|
type: :development
|
56
83
|
prerelease: false
|
57
|
-
version_requirements:
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.3.2
|
58
89
|
description: Google Webfonts helper for Rails or Sinatra applications.
|
59
90
|
email:
|
60
91
|
- travis.j.haynes@gmail.com
|
@@ -63,7 +94,6 @@ extensions: []
|
|
63
94
|
extra_rdoc_files: []
|
64
95
|
files:
|
65
96
|
- .gitignore
|
66
|
-
- .rspec
|
67
97
|
- Gemfile
|
68
98
|
- LICENSE
|
69
99
|
- README.md
|
@@ -71,37 +101,41 @@ files:
|
|
71
101
|
- google-webfonts.gemspec
|
72
102
|
- lib/google-webfonts.rb
|
73
103
|
- lib/google-webfonts/helper.rb
|
104
|
+
- lib/google-webfonts/link_tag.rb
|
74
105
|
- lib/google-webfonts/sinatra.rb
|
75
106
|
- lib/google-webfonts/version.rb
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
107
|
+
- test/lib/google-webfonts/helper_test.rb
|
108
|
+
- test/lib/google-webfonts/link_tag_test.rb
|
109
|
+
- test/lib/google-webfonts/sinatra_test.rb
|
110
|
+
- test/lib/google-webfonts_test.rb
|
111
|
+
- test/test_helper.rb
|
81
112
|
homepage: https://github.com/travishaynes/Google-Webfonts-Helper
|
82
113
|
licenses: []
|
114
|
+
metadata: {}
|
83
115
|
post_install_message:
|
84
116
|
rdoc_options: []
|
85
117
|
require_paths:
|
86
118
|
- lib
|
87
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
120
|
requirements:
|
90
|
-
- -
|
121
|
+
- - '>='
|
91
122
|
- !ruby/object:Gem::Version
|
92
123
|
version: '0'
|
93
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
-
none: false
|
95
125
|
requirements:
|
96
|
-
- -
|
126
|
+
- - '>='
|
97
127
|
- !ruby/object:Gem::Version
|
98
128
|
version: '0'
|
99
129
|
requirements: []
|
100
130
|
rubyforge_project:
|
101
|
-
rubygems_version:
|
131
|
+
rubygems_version: 2.2.1
|
102
132
|
signing_key:
|
103
|
-
specification_version:
|
133
|
+
specification_version: 4
|
104
134
|
summary: Provides a helper for using Google Webfonts in Rails or Sinatra, although
|
105
135
|
it can be used outside of those frameworks as well.
|
106
|
-
test_files:
|
107
|
-
|
136
|
+
test_files:
|
137
|
+
- test/lib/google-webfonts/helper_test.rb
|
138
|
+
- test/lib/google-webfonts/link_tag_test.rb
|
139
|
+
- test/lib/google-webfonts/sinatra_test.rb
|
140
|
+
- test/lib/google-webfonts_test.rb
|
141
|
+
- test/test_helper.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|
@@ -1,126 +0,0 @@
|
|
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
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# set up a Sinatra route to test
|
2
|
-
get("/") { google_webfonts_link_tag "Droid Sans" }
|
3
|
-
|
4
|
-
describe "Sinatra" do
|
5
|
-
include Rack::Test::Methods
|
6
|
-
|
7
|
-
def app
|
8
|
-
Sinatra::Application
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should include Google::Webfonts::Helper in Sinatra::Application" do
|
12
|
-
Sinatra::Application.ancestors.should include Google::Webfonts::Helper
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should respond to google_webfonts_link_tag" do
|
16
|
-
tag = "<link href=\"http://fonts.googleapis.com/css?family=Droid+Sans\" rel=\"stylesheet\" type=\"text/css\" />"
|
17
|
-
|
18
|
-
get "/"
|
19
|
-
|
20
|
-
last_response.should be_ok
|
21
|
-
last_response.body.should eq tag
|
22
|
-
end
|
23
|
-
end
|
data/spec/spec_helper.rb
DELETED