Skip to content

Commit

Permalink
Merge branch '2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssais committed Oct 30, 2015
2 parents 04db4c0 + 3da3f6e commit ecff0ed
Show file tree
Hide file tree
Showing 27 changed files with 121 additions and 27 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GEM
remote: https://rubygems.org/
specs:
commander (4.3.0)
highline (~> 1.6.11)
highline (1.6.21)
minitest (5.5.1)
sass (3.4.12)
sassunit (1.0.1)
commander (4.3.5)
highline (~> 1.7.2)
highline (1.7.8)
minitest (5.8.2)
sass (3.4.19)
sassunit (1.0.0)
commander
minitest
sass
Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ A Sass mixin to allow easy, efficient usage of [Google Web Fonts](https://google

You can clone this repo and include [_web-fonts.scss](https://github.com/penman/Sass-Web-Fonts) in your project manually, or you can install the _sass-web-fonts_ package from [Bower](http://bower.io).

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](UPGRADING.md#upgrading-from-1x-to-2x). It's very easy. :)

Usage
-----
First, import Sass Web Fonts like this:
Expand All @@ -13,28 +18,41 @@ First, import Sass Web Fonts like this:
@import "web-fonts";
```

### Using with [libsass](https://github.com/sass/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.

```scss
// 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

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

### Specifying font variant

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

### Multiple variants

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

### Multiple fonts

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

Protocols
Expand All @@ -51,7 +69,7 @@ possible to override the automatic protocol detection by setting the

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

Extra parameters
Expand All @@ -61,7 +79,7 @@ To add additional parameters to the web fonts URL, you can override the `$web-fo

```scss
$web-fonts-params: (subset: "latin,latin-ext");
@include web-fonts("Open Sans");
@import url(web-fonts-url("Open Sans"));
```

```css
Expand Down Expand Up @@ -89,6 +107,7 @@ Troubleshooting
If you get a `Sass::SyntaxError` when using the library, you probably need to update Sass. See [issue #7](https://github.com/penman/Sass-Web-Fonts/issues/7) for more information.

---
_Requires Sass 3.3 or later version. **[Not compatible with libsass.](https://github.com/penman/Sass-Web-Fonts/issues/14)** Pull requests welcome._

_Requires Sass 3.3 or later version. Pull requests welcome._

[You can follow me on Twitter.](https://twitter.com/PenmanRoss)
21 changes: 21 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Upgrade Guide

## Upgrading from 1.x to 2.x

The syntax for Sass Web Fonts has changed.

What would previously have been written:

```scss
@include web-fonts("Open Sans");
```

Should now be written:

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

This change was made to allow Sass Web Fonts to be used with [libsass](https://github.com/sass/libsass).

If you have a large project with lots of calls to `web-fonts()` that you don't want to replace by hand, you can include `web-fonts/compat.scss` from the Sass Web Fonts repository and replace any occurrence of `@import "web-fonts"` with `@import "web-fonts/compat"` to continue using the old syntax. However, it is recommended that you switch to using the new syntax at some point, because `web-fonts/compat` will be removed in a future release of the library.
4 changes: 2 additions & 2 deletions _web-fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
@return wf-query-string-encode($params);
}

@mixin web-fonts($fonts...) {
@function web-fonts-url($fonts...) {
$protocol: wf-protocol();
$query-string: wf-params-string($fonts);
$url: "#{$protocol}//fonts.googleapis.com/css?#{$query-string}";
@import url($url);
@return $url;
}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sass-web-fonts",
"main": "_web-fonts.scss",
"version": "1.1.1",
"version": "2.0.0",
"homepage": "https://github.com/penman/Sass-Web-Fonts",
"authors": [
"Ross Penman <[email protected]>"
Expand Down
2 changes: 2 additions & 0 deletions test/compat/multiple-calls.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans");
@import url("//fonts.googleapis.com/css?family=Ubuntu");
3 changes: 3 additions & 0 deletions test/compat/multiple-calls.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "web-fonts/compat";
@include web-fonts("Open Sans");
@include web-fonts("Ubuntu");
1 change: 1 addition & 0 deletions test/compat/multiple-fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans|Ubuntu%3A400%2Citalic");
2 changes: 2 additions & 0 deletions test/compat/multiple-fonts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "web-fonts/compat";
@include web-fonts("Open Sans", ("Ubuntu": ("400", "italic")));
1 change: 1 addition & 0 deletions test/compat/multiple-variants.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans%3A500%2C600italic");
2 changes: 2 additions & 0 deletions test/compat/multiple-variants.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "web-fonts/compat";
@include web-fonts(("Open Sans": ("500", "600 italic")));
4 changes: 4 additions & 0 deletions test/compat/protocol.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans");
@import url("http://fonts.googleapis.com/css?family=Open%20Sans");
@import url("https://fonts.googleapis.com/css?family=Open%20Sans");
@import url("//fonts.googleapis.com/css?family=Open%20Sans");
12 changes: 12 additions & 0 deletions test/compat/protocol.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import "web-fonts/compat";

@include web-fonts("Open Sans");

$web-fonts-protocol: "http";
@include web-fonts("Open Sans");

$web-fonts-protocol: "https";
@include web-fonts("Open Sans");

$web-fonts-protocol: "";
@include web-fonts("Open Sans");
1 change: 1 addition & 0 deletions test/compat/single-font.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans");
2 changes: 2 additions & 0 deletions test/compat/single-font.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "web-fonts/compat";
@include web-fonts("Open Sans");
1 change: 1 addition & 0 deletions test/compat/single-variant.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans%3Abold");
2 changes: 2 additions & 0 deletions test/compat/single-variant.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "web-fonts/compat";
@include web-fonts(("Open Sans": "bold"));
1 change: 1 addition & 0 deletions test/compat/subset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("//fonts.googleapis.com/css?family=Open%20Sans&subset=latin%2Clatin-ext");
3 changes: 3 additions & 0 deletions test/compat/subset.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "web-fonts/compat";
$web-fonts-params: (subset: "latin,latin-ext");
@include web-fonts("Open Sans");
6 changes: 4 additions & 2 deletions test/multiple-calls.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "web-fonts";
@include web-fonts("Open Sans");
@include web-fonts("Ubuntu");
$url: web-fonts-url("Open Sans");
@import url($url);
$url: web-fonts-url("Ubuntu");
@import url($url);
3 changes: 2 additions & 1 deletion test/multiple-fonts.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "web-fonts";
@include web-fonts("Open Sans", ("Ubuntu": ("400", "italic")));
$url: web-fonts-url("Open Sans", ("Ubuntu": ("400", "italic")));
@import url($url);
3 changes: 2 additions & 1 deletion test/multiple-variants.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "web-fonts";
@include web-fonts(("Open Sans": ("500", "600 italic")));
$url: web-fonts-url(("Open Sans": ("500", "600 italic")));
@import url($url);
12 changes: 8 additions & 4 deletions test/protocol.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
@import "web-fonts";

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

$web-fonts-protocol: "http";
@include web-fonts("Open Sans");
$url: web-fonts-url("Open Sans");
@import url($url);

$web-fonts-protocol: "https";
@include web-fonts("Open Sans");
$url: web-fonts-url("Open Sans");
@import url($url);

$web-fonts-protocol: "";
@include web-fonts("Open Sans");
$url: web-fonts-url("Open Sans");
@import url($url);
4 changes: 3 additions & 1 deletion test/single-font.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
@import "web-fonts";
@include web-fonts("Open Sans");

$url: web-fonts-url("Open Sans");
@import url($url);
3 changes: 2 additions & 1 deletion test/single-variant.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "web-fonts";
@include web-fonts(("Open Sans": "bold"));
$url: web-fonts-url(("Open Sans": "bold"));
@import url($url);
3 changes: 2 additions & 1 deletion test/subset.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "web-fonts";
$web-fonts-params: (subset: "latin,latin-ext");
@include web-fonts("Open Sans");
$url: web-fonts-url("Open Sans");
@import url($url);
5 changes: 5 additions & 0 deletions web-fonts/compat.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "web-fonts";

@mixin web-fonts($fonts...) {
@import url(web-fonts-url($fonts...));
}

0 comments on commit ecff0ed

Please sign in to comment.