Giter Club home page Giter Club logo

sass-web-fonts's Introduction

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.

sass-web-fonts's People

Contributors

alyssais avatar chrislopresto avatar cornelisonc avatar ctrlmaniac avatar hyl avatar prcaen avatar veniversum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sass-web-fonts's Issues

Sass compilation error

Hi.

I have imported the _web-fonts.scss (tag v1.1) into my project but when sass compile it I get this error :

    error sass/gpe.scss (Line 19 of sass/_web-fonts.scss: Invalid CSS after "          "!"": expected ")", was ": "%21",")

Sass::SyntaxError

Invalid CSS after " "!"": expected ")", was ": "%21","

I'm getting this error when try to add the _web-fonts.scss into my rails application. Have anyone face this problem?

if only one font with spaces is included (like 'Maven Pro') it crashes the parser

If there is only one Font which has white spaces in it, the parser handles it as two fonts. That could be caused by the scss language itself which interprets both strings comma-separated and white-space-separated as list.

e.g. If there is a list of two Fonts: Maven Pro, Josefin Sans then ',' is the separator of the list. But if there is only Maven Pro something tries to see it as a list of two strings.
'Maven' and 'Pro' separated with a white-space.

I hope my explanation is understandable and someone if not me can solve this bug ;)

Trying to include only one font with multiple weights breaks

Hi...

Trying to add just one font with multiple variants doesn't include all variants. For example:

@include web-font(Ubuntu, (400 700));

This only includes the 400 weight. Doing this makes it recognise both weights:

@include web-font(Ubuntu, (400 700,1));

Thanks

Add as npm package

Many have moved from bower to npm-only, so have I. Would you be so kind to add Sass-Web-Fonts as npm package. Appreciated!

Invalid CSS after... Error when parsing with multiple Varients

I am getting the following error when attempting to parse my scss file, the error I receive is:

Syntax error: Invalid CSS after "...ource Sans Pro"": expected ")", was ": ("300", "400"..."

I have the following in my scss file:

@include web-fonts(("Source Sans Pro": ("300", "400", "600", "700", "800", "300 italic", "400 italic", "600 italic", "700 italic", "800 italic")));

I am using gulp, specifically the gulp-ruby-sass package to compile, currently on version 0.5.0

Pathname css

When using this nice mixin I was receiving a 404 error when trying to reach the Google Fonts API from all tested browsers.

To make this mixin work in my project I had to change the pathname's url variable to css:

"fonts.googleapis.com/url?family="
to "fonts.googleapis.com/css?family=" 

This might be due to a change in implementation by Google or my own ignorance.

Error on process

error sass/web-fonts.scss (Line 6: Invalid CSS after "": expected selector or at-rule, was "")

included in my SASS file:

@include web-fonts("Open Sans", ("Droid Serif", ("Pacifico")));

Have uploaded the web-fonts.scss in the same folder as my screen.scss.

Have I done something wrong?

font-display: swap

How can I use Google Font's display:swap?

Eg:
<link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700&display=swap" rel="stylesheet">

Error when compiling with grunt compass

Using grant compass, I got this error when compiling the scss file:

error ... (Line 17 of src/assets/scss/components/_web-fonts.scss: 
Invalid CSS after "    "!"": expected ")", was ": "%21",")
...
Warning: ↑ Use --force to continue.

In the line 17 we have: "!": "%21",

libsass compatibility?

Hi,

I recently moved to the latest libsass and noticed this:

  [11:47:41] { [Error: /Users/rolle/test/web-fonts:91: @import directives are not allowed inside mixins and functions
  ]
    message: '/Users/rolle/test/web-fonts:91: @import directives are not allowed inside mixins and functions\n',
    showStack: false,
    showProperties: true,
    plugin: 'gulp-sass',
    __safety: { toString: [Function] } }

Any way to make this to work with libsass?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.