bigcartel-theme-fonts 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2d4a27d10d95da63b2247e199d3d151667ad0a6
4
+ data.tar.gz: 669ec98425b58aacba6b9f349d65ef764d0d2056
5
+ SHA512:
6
+ metadata.gz: ddb5f4bb8392ae56333fffec5b914d173dbcaa54b1c5bdd571e201f7c840c76c9b517383009b886647030fbaa2ae8b11efc5eb342a08cfe825a44bbd639f42fe
7
+ data.tar.gz: 8ff47bf8f93085b689e2370db0c12db4ecdfac90f78cd0293261c7cc8f9d9f996c00924ee524e4b83bfe16c96a96a8fc4e8c34d67d7d56970a22558173162d68
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ - 1.9.3
5
+ - 2.0
6
+ notifications:
7
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Big Cartel, LLC
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,36 @@
1
+ # Big Cartel Theme Fonts [![Build Status](https://travis-ci.org/bigcartel/bigcartel-theme-fonts.png?branch=master)](https://travis-ci.org/bigcartel/bigcartel-theme-fonts) [![Gem Version](https://badge.fury.io/rb/bigcartel-theme-fonts.png)](http://badge.fury.io/rb/bigcartel-theme-fonts)
2
+
3
+ A simple class for working with Big Cartel's supported theme fonts. Used internally by [Big Cartel](http://bigcartel.com) and [Dugway](https://github.com/bigcartel/dugway).
4
+
5
+ ## Install
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bigcartel-theme-fonts'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```ruby
16
+ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```ruby
22
+ gem install bigcartel-theme-fonts
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ georgia = ThemeFont.find_by_name('Georgia')
29
+ georgia.name #=> 'Georgia'
30
+ georgia.family #=> 'Georgia, "Times New Roman", Times, serif'
31
+ georgia.collection #=> 'default'
32
+ ```
33
+
34
+ ```ruby
35
+ ThemeFont.google_font_url_for_all_fonts #=> "//fonts.googleapis.com/css?family=One|Two"
36
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Run all examples'
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = %w[--color]
8
+ end
9
+
10
+ task :default => [:spec]
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bigcartel-theme-fonts'
7
+ spec.version = '1.0.0'
8
+ spec.authors = ['Big Cartel']
9
+ spec.email = ['dev@bigcartel.com']
10
+ spec.description = %q{A simple class for working with Big Cartel's supported theme fonts.}
11
+ spec.summary = %q{A simple class for working with Big Cartel's supported theme fonts.}
12
+ spec.homepage = 'https://github.com/bigcartel/bigcartel-theme-fonts'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'rr'
24
+ end
@@ -0,0 +1 @@
1
+ require 'bigcartel/theme/fonts/theme_font'
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+
3
+ class ThemeFont < Struct.new(:name, :family, :collection)
4
+ class << self
5
+ def all
6
+ @@all ||= Array.new.tap { |fonts|
7
+ source.each_pair { |collection, collection_fonts|
8
+ collection_fonts.values.each { |font|
9
+ fonts << ThemeFont.new(font['name'], font['family'], collection)
10
+ }
11
+ }
12
+ }.sort_by { |font| font.name }
13
+ end
14
+
15
+ def options
16
+ @@options ||= all.map(&:name)
17
+ end
18
+
19
+ def find_by_name(name)
20
+ all.find { |font|
21
+ name.downcase == font.name.downcase
22
+ }
23
+ end
24
+
25
+ def find_family_by_name(name)
26
+ if font = find_by_name(name)
27
+ font.family
28
+ else
29
+ name
30
+ end
31
+ end
32
+
33
+ def google_font_names
34
+ @@google_font_names ||= all.select { |font|
35
+ font.collection == 'google'
36
+ }.map(&:name)
37
+ end
38
+
39
+ def google_font_url_for_fonts(fonts)
40
+ "//fonts.googleapis.com/css?family=#{ fonts.map { |font| font.gsub(' ', '+') }.join('|') }"
41
+ end
42
+
43
+ def google_font_url_for_all_fonts
44
+ google_font_url_for_fonts(google_font_names)
45
+ end
46
+
47
+ def google_font_url_for_theme(fonts, settings)
48
+ google_fonts = fonts.keys.map { |key| settings[key] }.select { |font_name| google_font_names.include? font_name }.sort
49
+ google_fonts.empty? ? nil : google_font_url_for_fonts(google_fonts)
50
+ end
51
+
52
+ private
53
+
54
+ def source
55
+ @@source ||= YAML.load(File.read(File.join(File.dirname(__FILE__), 'theme_fonts.yml')))
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,151 @@
1
+ # Default browser fonts
2
+
3
+ default:
4
+ arial:
5
+ name: Arial
6
+ family: 'Arial, Helvetica, sans-serif'
7
+
8
+ arial_black:
9
+ name: Arial Black
10
+ family: 'Arial Black, Gadget, sans-serif'
11
+
12
+ courier_new:
13
+ name: Courier New
14
+ family: '"Courier New", Courier, monospace'
15
+
16
+ georgia:
17
+ name: Georgia
18
+ family: 'Georgia, "Times New Roman", Times, serif'
19
+
20
+ helvetica:
21
+ name: Helvetica
22
+ family: '"Helvetica Neue", Helvetica, Arial, sans-serif'
23
+
24
+ impact:
25
+ name: Impact
26
+ family: 'Impact, Charcoal, sans-serif'
27
+
28
+ lucida_grande:
29
+ name: Lucida Grande
30
+ family: '"Lucida Grande", Lucida, Verdana, sans-serif'
31
+
32
+ palatino_linotype:
33
+ name: Palatino Linotype
34
+ family: '"Palatino Linotype", "Book Antiqua", Palatino, serif'
35
+
36
+ tahoma:
37
+ name: Tahoma
38
+ family: 'Tahoma, Geneva, sans-serif'
39
+
40
+ times_new_roman:
41
+ name: Times New Roman
42
+ family: '"Times New Roman", Times, serif'
43
+
44
+ trebuchet_ms:
45
+ name: Trebuchet MS
46
+ family: '"Trebuchet MS", Arial, sans-serif'
47
+
48
+ verdana:
49
+ name: Verdana
50
+ family: 'Verdana, Arial, Helvetica, sans-serif'
51
+
52
+
53
+ # Google web fonts
54
+
55
+ google:
56
+ amaranth:
57
+ name: Amaranth
58
+ family: '"Amaranth", serif'
59
+
60
+ arvo:
61
+ name: Arvo
62
+ family: '"Arvo", serif'
63
+
64
+ asap:
65
+ name: Asap
66
+ family: '"Asap", sans-serif'
67
+
68
+ copse:
69
+ name: Copse
70
+ family: '"Copse", serif'
71
+
72
+ cutive_mono:
73
+ name: Cutive Mono
74
+ family: '"Cutive Mono", serif'
75
+
76
+ delius:
77
+ name: Delius
78
+ family: '"Delius", cursive'
79
+
80
+ dosis:
81
+ name: Dosis
82
+ family: '"Dosis", sans-serif'
83
+
84
+ enriqueta:
85
+ name: Enriqueta
86
+ family: '"Enriqueta", serif'
87
+
88
+ gentium_book_basic:
89
+ name: Gentium Book Basic
90
+ family: '"Gentium Book Basic", serif'
91
+
92
+ glegoo:
93
+ name: Glegoo
94
+ family: '"Glegoo", serif'
95
+
96
+ inconsolata:
97
+ name: Inconsolata
98
+ family: '"Inconsolata", sans-serif'
99
+
100
+ lekton:
101
+ name: Lekton
102
+ family: '"Lekton", sans-serif'
103
+
104
+ lobster_two:
105
+ name: Lobster Two
106
+ family: '"Lobster Two", cursive'
107
+
108
+ merriweather:
109
+ name: Merriweather
110
+ family: '"Merriweather", serif'
111
+
112
+ open_sans:
113
+ name: Open Sans
114
+ family: '"Open Sans", sans-serif'
115
+
116
+ overlock:
117
+ name: Overlock
118
+ family: '"Overlock", cursive'
119
+
120
+ noticia_text:
121
+ name: Noticia Text
122
+ family: '"Noticia Text", serif'
123
+
124
+ playfair_display:
125
+ name: Playfair Display
126
+ family: '"Playfair Display", serif'
127
+
128
+ raleway:
129
+ name: Raleway
130
+ family: '"Raleway", sans-serif'
131
+
132
+ rokkitt:
133
+ name: Rokkitt
134
+ family: '"Rokkitt", serif'
135
+
136
+ signika:
137
+ name: Signika
138
+ family: '"Signika", sans-serif'
139
+
140
+ source_sans_pro:
141
+ name: Source Sans Pro
142
+ family: '"Source Sans Pro", sans-serif'
143
+
144
+ titillium_web:
145
+ name: Titillium Web
146
+ family: '"Titillium Web", sans-serif'
147
+
148
+ varela_round:
149
+ name: Varela Round
150
+ family: '"Varela Round", sans-serif'
151
+
@@ -0,0 +1,2 @@
1
+ require 'rr'
2
+ require 'bigcartel/theme/fonts'
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThemeFont do
4
+ before(:each) do
5
+ # Start fresh each time, so stubs work
6
+ ThemeFont.send(:remove_class_variable, :@@source) rescue nil
7
+ ThemeFont.send(:remove_class_variable, :@@all) rescue nil
8
+ ThemeFont.send(:remove_class_variable, :@@options) rescue nil
9
+ ThemeFont.send(:remove_class_variable, :@@google_font_names) rescue nil
10
+ end
11
+
12
+ describe ".all" do
13
+ it "should return all theme fonts" do
14
+ ThemeFont.all.should_not be_nil
15
+ end
16
+
17
+ it "should be in alphabetical order" do
18
+ ThemeFont.all.first.name.should == 'Amaranth'
19
+ ThemeFont.all.last.name.should == 'Verdana'
20
+ end
21
+ end
22
+
23
+ describe ".options" do
24
+ before(:each) do
25
+ stub(ThemeFont).all {[
26
+ ThemeFont.new('One'),
27
+ ThemeFont.new('Two'),
28
+ ThemeFont.new('Three')
29
+ ]}
30
+ end
31
+
32
+ it "should return an array of all font names" do
33
+ ThemeFont.options.should == ['One', 'Two', 'Three']
34
+ end
35
+ end
36
+
37
+ describe ".find_by_name" do
38
+ it "should return a font by its name" do
39
+ georgia = ThemeFont.find_by_name('Georgia')
40
+ georgia.name.should == 'Georgia'
41
+ georgia.family.should == 'Georgia, "Times New Roman", Times, serif'
42
+ georgia.collection.should == 'default'
43
+ end
44
+
45
+ it "should return nil if the font doesn't exist" do
46
+ ThemeFont.find_by_name('Blah').should be_nil
47
+ end
48
+ end
49
+
50
+ describe ".find_family_by_name" do
51
+ it "should return the font family by its name" do
52
+ ThemeFont.find_family_by_name('Georgia').should == 'Georgia, "Times New Roman", Times, serif'
53
+ end
54
+
55
+ it "should return the font name if no font is found" do
56
+ ThemeFont.find_family_by_name('Blah').should == 'Blah'
57
+ end
58
+ end
59
+
60
+ describe ".google_font_names" do
61
+ before(:each) do
62
+ stub(ThemeFont).all {[
63
+ ThemeFont.new('One Font', 'One Family', 'google'),
64
+ ThemeFont.new('Two', 'Two Family', 'default'),
65
+ ThemeFont.new('Three', 'Three Family', 'google')
66
+ ]}
67
+ end
68
+
69
+ it "returns a sorted array of font names in the google collection" do
70
+ ThemeFont.google_font_names.should == ['One Font', 'Three']
71
+ end
72
+ end
73
+
74
+ describe ".google_font_url_for_fonts" do
75
+ it "should return a url for a given array of font names" do
76
+ ThemeFont.google_font_url_for_fonts(['Bro Hey', 'Dude', 'Yeah']).should == "//fonts.googleapis.com/css?family=Bro+Hey|Dude|Yeah"
77
+ end
78
+
79
+ it "should return a url for a singular font in an array" do
80
+ ThemeFont.google_font_url_for_fonts(['Bro Hey']).should == "//fonts.googleapis.com/css?family=Bro+Hey"
81
+ end
82
+ end
83
+
84
+ describe ".google_font_url_for_all_fonts" do
85
+ before(:each) do
86
+ stub(ThemeFont).all {[
87
+ ThemeFont.new('One Font', 'One Family', 'google'),
88
+ ThemeFont.new('Two', 'Two Family', 'default'),
89
+ ThemeFont.new('Three', 'Three Family', 'google')
90
+ ]}
91
+ end
92
+
93
+ it "should return a URL for all Google fonts" do
94
+ ThemeFont.google_font_url_for_all_fonts.should == "//fonts.googleapis.com/css?family=One+Font|Three"
95
+ end
96
+ end
97
+
98
+ describe ".google_font_url_for_theme" do
99
+ let(:fonts) {{ :header_font => {}, :body_font => {}, :paragraph_font => {} }}
100
+
101
+ before(:each) do
102
+ stub(ThemeFont).all {[
103
+ ThemeFont.new('One Font', 'One Family', 'google'),
104
+ ThemeFont.new('Two', 'Two Family', 'default'),
105
+ ThemeFont.new('Three', 'Three Family', 'google')
106
+ ]}
107
+ end
108
+
109
+ it "should return a URL if a theme has multiple" do
110
+ settings = { :header_font => 'One Font', :body_font => 'Two', :paragraph_font => 'Three' }
111
+ ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font|Three"
112
+ end
113
+
114
+ it "should return single font name if a theme has one" do
115
+ settings = { :header_font => 'One Font', :body_font => 'Two' }
116
+ ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font"
117
+ end
118
+
119
+ it "should return nil if a theme has none" do
120
+ settings = { :body_font => 'Two' }
121
+ ThemeFont.google_font_url_for_theme(fonts, settings).should be_nil
122
+ end
123
+ end
124
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigcartel-theme-fonts
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Big Cartel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A simple class for working with Big Cartel's supported theme fonts.
70
+ email:
71
+ - dev@bigcartel.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bigcartel-theme-fonts.gemspec
83
+ - lib/bigcartel/theme/fonts.rb
84
+ - lib/bigcartel/theme/fonts/theme_font.rb
85
+ - lib/bigcartel/theme/fonts/theme_fonts.yml
86
+ - spec/spec_helper.rb
87
+ - spec/theme_font_spec.rb
88
+ homepage: https://github.com/bigcartel/bigcartel-theme-fonts
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.0
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A simple class for working with Big Cartel's supported theme fonts.
112
+ test_files:
113
+ - spec/spec_helper.rb
114
+ - spec/theme_font_spec.rb