Permalink
Browse files

spec coverage and documentation. fist face is all grown'ed up.

  • Loading branch information...
1 parent 10b7f6b commit 01c72e2ec2d07214de5d5421c90a8127cd8cedde @croaky croaky committed Jan 12, 2011
View
7 .rvmrc
@@ -1,7 +0,0 @@
-export RUBY_HEAP_MIN_SLOTS=500000
-export RUBY_HEAP_SLOTS_INCREMENT=250000
-export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
-export RUBY_GC_MALLOC_LIMIT=50000000
-export RUBY_HEAP_FREE_MIN=100000
-
-rvm use ree
View
10 Gemfile
@@ -1,3 +1,9 @@
-source :gemcutter
+source "http://rubygems.org"
-gem 'sinatra'
+gem "sinatra", "~> 1.1"
+
+group :test do
+ gem "rspec", "~> 2.4"
+ gem "rack-test", "~> 0.5"
+ gem "timecop", "~> 0.3"
+end
View
@@ -1,17 +1,29 @@
GEM
remote: http://rubygems.org/
specs:
+ diff-lcs (1.1.2)
rack (1.2.1)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rspec (2.4.0)
+ rspec-core (~> 2.4.0)
+ rspec-expectations (~> 2.4.0)
+ rspec-mocks (~> 2.4.0)
+ rspec-core (2.4.0)
+ rspec-expectations (2.4.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.4.0)
sinatra (1.1.0)
rack (~> 1.1)
tilt (~> 1.1)
tilt (1.1)
+ timecop (0.3.5)
PLATFORMS
ruby
DEPENDENCIES
- sinatra
-
-METADATA
- version: 1.0.6
+ rack-test (~> 0.5)
+ rspec (~> 2.4)
+ sinatra (~> 1.1)
+ timecop (~> 0.3)
View
@@ -1,19 +1,81 @@
-Setup
+Fist Face
+=========
+
+Fist Face is a Do It Yourself @font-face web service.
+
+Usage
-----
-Comes with an .rvmrc set up for Ruby Enterprise Edition.
+In your web app:
+
+ <link href='http://replace-me.com/font-name.css' rel='stylesheet' type='text/css'>
- gem install bundler shotgun thin && bundle install
+Replace the href with the URL of your @font-face web service.
-Development
------------
+Features
+--------
- shotgun config.ru S3_URL=https://thoughtbot-fonts.s3.amazonaws.com
+* Fixes the Access-Control-Allow-Origin problem in Firefox and other browsers
+* HTTP caches fonts so they are downloaded only once by the same browser
+* Content-Type always correct for .ttf, .otf, .woff, .eot, and .svg fonts
+
+Setup
+-----
-Production
-----------
+Get the Sinatra app:
- heroku config:add S3_URL=https://thoughtbot-fonts.s3.amazonaws.com
+ git clone git@github.com:thoughtbot/fistface.git
+
+Create the production environment:
+
+ heroku create
+ heroku config:add S3_URL=https://your-bucket.s3.amazonaws.com
-Where S3_URL is the place you put your .otf, .ttf, .woff, and .eot files.
Do not include a trailing slash.
+
+S3_URL is the URL of the asset host which stores your @font-face definitions in CSS files.
+
+For each font you want to serve, upload a CSS file to your asset host like:
+
+ @font-face {
+ font-family: 'Chunk';
+ font-weight: normal;
+ font-style: normal;
+ src: local('☺'), url('http://replace-me.com/chunk/chunk.ttf') format('truetype');
+ }
+
+Fist Face uses a directory-and-file convention like this:
+
+ font-name.css
+ font-name/
+ font-name.eot
+ font-name.otf
+ font-name.svg
+ font-name.tff
+ font-name.woff
+
+It is up to you to determine how many formats you need to include in your CSS file.
+
+Upload each font file using that convention.
+
+Deploy your @font-face web service:
+
+ git push heroku master
+
+Start serving fonts!
+
+Patches
+-------
+
+Please use Github Issues and Pull Requests for any patches.
+
+To run the Sinatra app locally:
+
+ gem install bundler
+ bundle install
+ S3_URL=https://your-bucket.s3.amazonaws.com rackup
+
+To run the specs:
+
+ rspec spec/app_spec.rb
+
View
@@ -1,2 +1,4 @@
+$: << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
+
require 'app'
run App
View
@@ -1,6 +1,7 @@
require 'rubygems'
-require 'bundler'
require 'open-uri'
+require 'bundler'
+
Bundler.require
class App < Sinatra::Base
View
@@ -0,0 +1,101 @@
+require 'spec_helper'
+
+describe App do
+ include Rack::Test::Methods
+
+ def app
+ App
+ end
+
+ context "when I GET a font stylesheet by convention of font-name.css" do
+ before do
+ Timecop.freeze(Date.parse("January 1, 2011"))
+
+ get "chunk.css"
+ end
+
+ it "responds with HTTP status OK" do
+ last_response.should be_ok
+ end
+
+ it "has the @font-face declaration in the CSS body" do
+ last_response.body.should == File.read('spec/fixtures/chunk.css')
+ end
+
+ it "is in the CSS Content-Type" do
+ last_response.content_type.should == 'text/css'
+ end
+
+ it "wildcards the Access-Control-Allow-Origin header so Firefox can access the file" do
+ last_response.headers['Access-Control-Allow-Origin'].should == '*'
+ end
+
+ it "HTTP caches the file for a year in Varnish" do
+ last_response.headers['Cache-Control'].should == 'public, max-age=31536000'
+ end
+
+ it "HTTP caches the file for a year in the user's browser" do
+ last_response.headers['Expires'].should == (Time.now + 31536000).httpdate
+ end
+ end
+
+ context "when I GET a font file by convention of font-name/font-name.ttf" do
+ before do
+ Timecop.freeze(Date.parse("January 1, 2011"))
+
+ get "chunk/chunk.ttf"
+ end
+
+ it "responds with HTTP status OK" do
+ last_response.should be_ok
+ end
+
+ it "is in the truetype Content-Type" do
+ last_response.content_type.should == 'font/truetype'
+ end
+
+ it "wildcards the Access-Control-Allow-Origin header so Firefox can access the file" do
+ last_response.headers['Access-Control-Allow-Origin'].should == '*'
+ end
+
+ it "HTTP caches the file for a year in Varnish" do
+ last_response.headers['Cache-Control'].should == 'public, max-age=31536000'
+ end
+
+ it "HTTP caches the file for a year in the user's browser" do
+ last_response.headers['Expires'].should == (Time.now + 31536000).httpdate
+ end
+ end
+
+ context "when I GET an opentype font" do
+ before { get "chunk/chunk.otf" }
+
+ it "is in the opentype Content-Type" do
+ last_response.content_type.should == 'font/opentype'
+ end
+ end
+
+ context "when I GET a web open font format font" do
+ before { get "league-gothic/league-gothic.woff" }
+
+ it "is in the web open font format Content-Type" do
+ last_response.content_type.should == 'font/woff'
+ end
+ end
+
+ context "when I GET an embedded opentype font" do
+ before { get "league-gothic/league-gothic.eot" }
+
+ it "is in the embedded opentype Content-Type" do
+ last_response.content_type.should == 'application/vnd.ms-fontobject'
+ end
+ end
+
+ context "when I GET an svg font" do
+ before { get "league-gothic/league-gothic.svg" }
+
+ it "is in the svg Content-Type" do
+ last_response.content_type.should == 'image/svg+xml'
+ end
+ end
+end
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,7 @@
+@font-face {
+ font-family: 'Chunk';
+ font-weight: normal;
+ font-style: normal;
+ src: url('chunk/chunk.otf');
+ src: local(''), url('chunk/chunk.ttf') format('truetype');
+}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 01c72e2

Please sign in to comment.