Skip to content

Commit

Permalink
4.0.0.rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenosloan committed Apr 6, 2016
1 parent 3cfe78f commit 6aea776
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 2 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,18 @@
4.0.0
=====

This is a major rewrite focussed on adding support for Sprockets 3+ & Middleman 4+. With this come a lot of changes, please read the [upgrade guide](docs/upgrade-3-to-4.md) for more information:

**tl;dr;**

* Requires Middleman 4.0+ & Sprockets 3.0+
* Remove auto-activation
* Remove the `import_asset` helper, assets should be linked via a manifest file
* Remove "automagical" asset placement, linked assets all go in the `imported_asset_path` option
* Add option to expose middleman helpers to sprockets assets
* Add compatability for SassC if using Sprockets 4+


3.4.2
===

Expand Down
4 changes: 3 additions & 1 deletion README.md
@@ -1,4 +1,6 @@
> The master branch is for a pre-released 4.x version of Middleman-Sprockets. For 3.x stable please see the [`v3-stable-real` branch](https://github.com/middleman/middleman-sprockets/tree/v3-stable-real).
> The master branch is for a pre-released 4.x version of Middleman-Sprockets.
> - For upgrading help please [read the upgrading guide](docs/upgrade-3-to-4.md)
> - For 3.x stable usage please see the [`v3-stable-real` branch](https://github.com/middleman/middleman-sprockets/tree/v3-stable-real)
# Middleman-Sprockets

Expand Down
118 changes: 118 additions & 0 deletions docs/upgrade-3-to-4.md
@@ -0,0 +1,118 @@
Version 4 represents a major rewrite of Middleman-Sprockets to maintain support for Middleman 4+ & gain support of Sprockets 3+. With this come a lot of changes, some you'll make in your code and others in your expectations.


## Activation

The biggest change to start with is the removal of auto-activation. Since some configuration options have been added, this makes configuring them follow the norm for other extensions. To activate, in your `config.rb`:

```ruby
activate :sprockets
```

After activation you can still access the sprockets environment to append paths

```ruby
activate :sprockets
sprockets.append_path File.join(root, 'bower_components')
```


## Importing Assets

For adding assets from a gem or bower you may have been used to using `sprockets.import_asset ASSET_PATH` and having it added to the sitemap based on it's type. The process for this is considerably different now.

First, the `#import_asset` method has been removed, instead you should add a [link directive](https://github.com/rails/sprockets#the-link-directive) to reference the file you want imported. To follow along with the rails convension and import files that aren't necessarily linked from other assets -- add a manifest file. For example lets say we want to import fonts from [Font-Awesome](https://github.com/FortAwesome/Font-Awesome).

Assuming Font-Awesome has been installed with bower:

```ruby
# config.rb
activate :sprockets
sprockets.append_path File.join(root, 'bower_components')
```

```javascript
// source/javascripts/manifest.js
//
//= link font-awesome-webfont.eot
//= link font-awesome-webfont.svg
//= link font-awesome-webfont.ttf
//= link font-awesome-webfont.wof
//= link font-awesome-webfont.wof2
```

This will import the fonts into the sitemap under the configured `imported_asset_path`. So on build it would look like:

```
build/
+-- assets/
+-- font-awesome-webfont.eot
+-- font-awesome-webfont.svg
+-- font-awesome-webfont.ttf
+-- font-awesome-webfont.wof
+-- font-awesome-webfont.wof2
```

You may have noticed that second difference from 3.x -- the fonts weren't placed into `:font_dir`. Instead of trying to determine file type & using that path -- with 4.x all imported assets are placed under the `imported_asset_path`.

This path defaults to `assets` and is configurable:

```ruby
# config.rb
activate :sprockets do |c|
c.imported_asset_path = 'imported'
end
sprockets.append_path File.join(root, 'bower_components')
```

```javascripts
// source/javascripts/manifest.js
//
//= link font-awesome-webfont.eot
```

```
build/
+-- imported/
+-- font-awesome-webfont.eot
```


In addition to importing assets through link directives, assets can also be linked via any of the path helper methods. Again, looking at font-awesome instead of using a manifest file -- lets link it directly from our css that will use it:

```css
/* source/stylesheets/fonts.css.scss */

@font-face {
font-family: "Font Awesome";
src: font-url('font-awesome-webfont.eot');
}
```

```
build/
+-- assets/
+-- font-awesome-webfont.eot
```

Check out the [feature test](../features/linked_assets.feature) for more specifics.


## Middleman Helpers

Helpers are no longer included in the sprockets rendering context by default. To expose them, configure `expose_middleman_helpers` to true:

```ruby
# config.rb
activate :sprockets do |c|
c.expose_middleman_helpers = true
end
```


## Less Support

With 3.x Sprockets has [dropped support for Less](https://github.com/sstephenson/sprockets/pull/547), so be aware that your `.less` files are handled by Middleman directly. As a concequence, sprockets directives or importing of assets won't work.


> Run into an issue or think something is missing? [Let us know](https://github.com/middleman/middleman-sprockets/issues/new) or submit a pull request to help us improve.
3 changes: 3 additions & 0 deletions features/linked_assets.feature
Expand Up @@ -41,6 +41,9 @@ Feature: Linked assets are included in the sitemap
When I go to "/assets/logo.png"
Then the status code should be "200"

When I go to "/stylesheets/site.css"
Then I should see "url(/assets/logo.png)"


Scenario: Linked asset destination is configurable
Given a fixture app "base-app"
Expand Down
2 changes: 1 addition & 1 deletion lib/middleman-sprockets/version.rb
@@ -1,5 +1,5 @@
module Middleman
module Sprockets
VERSION = '4.0.0.rc.1'.freeze
VERSION = '4.0.0.rc.2'.freeze
end
end

0 comments on commit 6aea776

Please sign in to comment.