• Stars
    star
    306
  • Rank 136,456 (Top 3 %)
  • Language
    CSS
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Sass mixin to allow easy, efficient usage of Google Web Fonts.

Sass Web Fonts

A Sass mixin to allow easy, efficient usage of Google Web Fonts.

You can clone this repo and include _web-fonts.scss in your project manually, or you can install the sass-web-fonts package from npm or Bower.

Upgrading from a previous version of Sass Web Fonts

Sass Web Fonts 2.x introduces breaking changes from 1.x. If you're upgrading from Sass Web Fonts 1.x, read the upgrading guide. It's very easy. :)

Usage

First, import Sass Web Fonts like this:

@import "web-fonts";

Installing with npm and using a node-based task-runner

  1. Add Sass-Web-Fonts as a dependency:

    npm install --save sass-web-fonts
  2. You’ll need to add Sass-Web-Fonts to your node-sass includePaths option. Commonly in this way: require("sass-web-fonts").includePaths. But specifically you have to refer to the framework you are using.

With Grunt

const sass = require( "node-sass" );

module.exports = function( grunt ) {
	require( "load-grunt-tasks" )( grunt );

	grunt.initConfig( {
		sass: {
			options: {
				implementation: sass,
				sourceMap: false,
				outputStyle: "compressed",
				sourceComments: false,

				includePaths: [
					//require( "module-one" ).includePaths,
					//require( "module-two" ).includePaths,
					require( "sass-web-fonts" ).includePaths
				]
			},
			public: {
				files: {
					"master.css": "master.scss"
				}
			}
		}
  } );
};

With Gulp

var gulp = require( "gulp" );
var sass = require( "gulp-sass" );

gulp.task( "sass", function () {
  gulp.src( "input.scss" )
    .pipe( sass( {
      includePaths: require( "sass-web-fonts" ).includePaths
    } ) )
    .pipe( gulp.dest( "output.css" ) );
} );

Using with libsass

If you are using libsass, you can't pass the result of web-fonts-url() directly into @import url(). You have to store it in a variable first. This is due to the compiler not supporting importing urls from functions.

// This won't work with libsass
@import url(web-fonts-url("Open Sans"));

// This will work with libsass
$url: web-fonts-url("Open Sans");
@import url($url);

Importing a single font

@import url(web-fonts-url("Open Sans"));

Specifying font variant

@import url(web-fonts-url(("Open Sans": "bold")));

Multiple variants

@import url(web-fonts-url(("Open Sans": ("500", "600 italic"))));

Multiple fonts

@import url(web-fonts-url("Open Sans", ("Ubuntu": ("400", "italic"))));

Protocols

By default, the web-fonts mixin will attempt to load fonts with the same protocol that was used to access the stylesheet it was called in. However, in some circumstances, most notably when the stylesheet was loaded as a local file (using a file:// url), this will not work. In this situation, it is possible to override the automatic protocol detection by setting the $web-fonts-protocol variable prior to calling the mixin.

Example

$web-fonts-protocol: "https"; // fonts will be loaded over HTTPS from here on.
@import url(web-fonts-url("Open Sans"); // uses HTTPS);

Extra parameters

To add additional parameters to the web fonts URL, you can override the $web-fonts-params variable with a map containing the extra URL params. For example, you can use it to specify character subsets:

$web-fonts-params: (subset: "latin,latin-ext");
@import url(web-fonts-url("Open Sans"));
/* Generated CSS */
@import url("//fonts.googleapis.com/css?subset=latin%2Clatin-ext&family=Open%20Sans");

A list of available parameters can be found in the Google Web Fonts documentation.

Testing

Development of this mixin uses SassUnit for unit tests. To run the tests after making a change to the mixin, do this:

$ bundle install
$ bundle exec sassunit

Codeship Status for alyssais/Sass-Web-Fonts

Troubleshooting

If you get a Sass::SyntaxError when using the library, you probably need to update Sass. See issue #7 for more information.


Requires Sass 3.3 or later version. Pull requests welcome.

More Repositories

1

memsocket

An asynchronous in-memory socket-like interface for Rust
Rust
35
star
2

SassUnit

A tiny Sass unit testing library.
Ruby
27
star
3

dotfiles

Everything in my home directory I want synced between machines. License:
Shell
24
star
4

secure-pbcopy

pbcopy(1) replacement that marks data as confidential
Makefile
21
star
5

humans

Automatically update a GitHub repository with a list of contributors.
Shell
20
star
6

font

A command-line font manager
Ruby
16
star
7

fluid

An opinionated MVC web framework for Node.js. Unmaintained.
JavaScript
11
star
8

hyper-stub

hyper clients that don't touch the network
Rust
10
star
9

twilio-color

It's a web page. You can change its color via text message or email.
JavaScript
10
star
10

SwiftAsync

Async control flow handling in Swift
Swift
8
star
11

kakwiki

Vimwiki compatible personal wiki for Kakoune.
6
star
12

video-mute

Remove the audio track from a video using JavaScript
JavaScript
5
star
13

auto-ebooks

Automatic Twitter ebooks bots.
Ruby
4
star
14

pebble-browse

A basic web browser for the Pebble smartwatch. WIP.
C
4
star
15

1password-backup

Shell
4
star
16

forks_ahead

Find forks of a GitHub repository that are ahead of it.
Ruby
4
star
17

browser-soundtrack-client

JavaScript
3
star
18

media_type

A library for parsing and generating Internet Media (MIME) Types
Ruby
2
star
19

numbers

An automatic numbers station for OS X.
Objective-C
2
star
20

table

turn tab-delemited input into tables, correctly aligned even if coloured
Ruby
2
star
21

cascading-attribute-sheets

Compile HTML using CSS-like selectors to apply attributes.
CoffeeScript
2
star
22

Poster

A (very buggy) Mac menu bar app for performing preconfigured HTTP requests with a single click
Objective-C
2
star
23

bingnews

A Node library for getting news data from Bing
JavaScript
1
star
24

email-autoconfirmer

Ruby
1
star
25

bus-tracker

Ruby
1
star
26

twilio_bot

Ruby
1
star
27

this-american-life-feed

CoffeeScript
1
star
28

omnifocus_to_due

Ruby
1
star
29

debugging-ruby-fibers

A high-level talk about tracking down a bug in Ruby itself.
Nix
1
star
30

.github

1
star