Skip to content
Provides a helper for using Google Webfonts in a Rails application.
Ruby Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib updated to version 0.3.2 May 22, 2018
test fixed usage of private method; fixes #11 May 22, 2018
.gitignore refactored from google-webfonts to google/webfonts Apr 25, 2018
.travis.yml only going to support Ruby 2.3 and above May 22, 2018
Gemfile refactored from google-webfonts to google/webfonts Apr 25, 2018
Gemfile.lock updated to version 0.3.2 May 22, 2018
LICENSE refactored from google-webfonts to google/webfonts Apr 25, 2018
README.md added coveralls Apr 25, 2018
Rakefile refactored from google-webfonts to google/webfonts Apr 25, 2018
google-webfonts.gemspec added coveralls Apr 25, 2018

README.md

Google::Webfonts

Build Status Coverage Status

Provides a helper for using Google Webfonts with the Ruby programming language.

Installation

Add this line to your application's Gemfile:

gem 'google-webfonts'

And then execute:

$ bundle

Or install it yourself as:

$ gem install google-webfonts

Usage

include Google::Webfonts::Helper

google_webfonts_link_tag font_name: [weights]

Examples

Basic usage:

google_webfonts_link_tag droid_sans: [400, 700], yanone_kaffeesatz: [300, 400]

The weights are optional, and do not have to be in an Array if you are only including one. For example:

# Generate a tag for Droid+Sans without specifying the font weight.
google_webfonts_link_tag :droid_sans

# Generate a tag for Droid+Sans with 400 weight.
google_webfonts_link_tag :droid_sans => 400

# Generate a tag for Droid+Sans with 400 and 700 weights.
google_webfonts_link_tag :droid_sans => [400, 700]

In certain cases it will be necessary to use Strings instead of Symbols for the font names. The helper method titleizes the symbols when converting it to a Google Webfonts compatible name. This does not work for every font name. For example:

# If a Symbol was provided here, the "T" would be lower-case, which would 
# result in an invalid link.
google_webfonts_link_tag 'PT Sans'

Using in Rails

Require the gem like this in your Gemfile when using with Rails:

gem 'google-webfonts', require: 'google/webfonts/rails'

The google_webfonts_link_tag helper method will automatically be available to your views. If you need to use it outside of the views, include this module:

include Google::Webfonts::Helper

Using in Sinatra

Here is a simple "Hello World" example for using Google::Webfonts in a Sinatra app:

# app.rb
require 'rubygems'
require 'sinatra'

# This must be required after requiring sinatra.
require 'google/webfonts/sinatra'

get '/' do
  erb :index
end

# views/index.erb
<html>
  <head>
    <%= google_webfonts_link_tag "Droid Sans" %>
  </head>
  <body>
    <p style="font-family: 'Droid+Sans', sans-serif;">
      Hello World!
    </p>
  </body>
</html>

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hi5dev/google-webfonts.

You can’t perform that action at this time.