Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Rework directory structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
greypants committed Feb 17, 2015
1 parent d793cb4 commit 3bb5a3b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -31,6 +31,11 @@ Install javascript dependencies. Once npm install runs, the `postinstall` settin
npm install
```

Start the rails server.
```
rails s
```

Run gulp and rejoice! This will start watching and recompiling files on the fly, as well as open a with BrowserSync running.
````
gulp
Expand All @@ -52,6 +57,14 @@ This is where any processed assets (images and fonts) will end up EXCEPT for css
## Rails setup notes:
### config/application.rb
```rb
# Make public assets requireable in manifest files
config.assets.paths << Rails.root.join("public", "assets", "stylesheets")
config.assets.paths << Rails.root.join("public", "assets", "javascripts")
```
If you plan on continuing to use Sprockets to `//require=` gem assets, you'll include your compiled js and css files in the `application.js` and `application.css` manifests files. The snippet above tells Sprockets to look in our `public/assets` directories when searching for required files. With this implementation, you'll continue using the Rails `javascript_include_tag` and `stylesheet_link_tag` asset pipeline helpers to pull in your manifest files (and everything they require). If you end up *not* needing the pipeline at all, you can pull in your compiled css and js directly with the `gulp_asset_path` helper (see below) and regular html.
### config/environments/development.rb
```rb
config.assets.debug = true
Expand Down Expand Up @@ -82,7 +95,7 @@ def gulp_asset_path(path)
"/assets/#{path}"
end
```
Because we're storing our font and image assets outside of the Rails Asset Pipeline, we need to re-implement the `asset_path` path helper (as `gulp_asset_path` to reference un-hashed files in `development`, and the cacheable hashed versions of the files in `production`. This goes for other Rails Asset Pipeline helpers, such as `<%= image_tag, 'asset.png' %>`. Instead, use `<img src="<%= gulp_asset_path('asset.png') %>">`.
Because we're storing our assets outside of the Rails Asset Pipeline, we need to re-implement the `asset_path` path helper (as `gulp_asset_path` to reference un-hashed files in `development`, and the cacheable hashed versions of the files in `production`. This goes for other Rails Asset Pipeline helpers, such as `<%= image_tag, 'asset.png' %>`. Instead, use `<img src="<%= gulp_asset_path('asset.png') %>">`.
### config/initialiers/rev_manifest.rb
```rb
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Expand Up @@ -7,4 +7,4 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require compiled/global.js
//= require global.js
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css
Expand Up @@ -5,5 +5,5 @@
* Use this file to include any stylesheet assets from installed gems. All other css is compiled with
* libsass with Gulp.
*
*= require compiled/global.css
*= require global.css
*/
4 changes: 2 additions & 2 deletions app/views/welcome/index.html.erb
@@ -1,6 +1,6 @@
<h1>Gulp Asset Pipeline</h1>
<h1>Gulp Asset Pipeline on Rails</h1>
<img src="<%= gulp_asset_path('images/gulp.png') %>" alt="">
<p>Say goodbye to the Rails Asset Pipeline headaches forever.</p>
<p><a href="https://github.com/greypants/gulp-rails-pipeline">Ditch the Rails Asset Pipeline and roll your own with Gulp.</a></p>
<i class="icon -facebook"></i>
<i class="icon -twitter"></i>
<i class="icon -linkedin"></i>
Expand Down
4 changes: 4 additions & 0 deletions config/application.rb
Expand Up @@ -22,5 +22,9 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true

# Make public assets requireable in manifest files
config.assets.paths << Rails.root.join("public", "assets", "stylesheets")
config.assets.paths << Rails.root.join("public", "assets", "javascripts")
end
end
Binary file modified file-structure.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions gulp/config.js
@@ -1,18 +1,15 @@
var railsAssets = "./app/assets";
var publicAssets = "./public/assets";
var sourceFiles = "./gulp/assets";

module.exports = {
publicAssets: publicAssets,
railsAssets: railsAssets,

browserSync: {
proxy: 'localhost:3000',
files: ['./app/views/**']
},
sass: {
src: sourceFiles + "/stylesheets/*.{sass,scss}",
dest: railsAssets + "/stylesheets/compiled",
dest: publicAssets + "/stylesheets",
settings: {
indentedSyntax: true, // Enable .sass syntax!
imagePath: '/assets/images' // Used by the image-url helper
Expand Down Expand Up @@ -40,7 +37,7 @@ module.exports = {
browserify: {
bundleConfigs: [{
entries: sourceFiles + '/javascripts/global.coffee',
dest: railsAssets + '/javascripts/compiled',
dest: publicAssets + '/javascripts',
outputName: 'global.js',
extensions: ['.js','.coffee']
}]
Expand Down
2 changes: 1 addition & 1 deletion gulp/tasks/rev.js
Expand Up @@ -14,7 +14,7 @@ gulp.task('rev-assets', function(){

// Replace asset references in compiled css and js files
gulp.task('rev', ['rev-assets'], function(){
return gulp.src([config.publicAssets + '/rev-manifest.json', config.railsAssets + '/**/compiled/*.{css,js}'])
return gulp.src([config.publicAssets + '/rev-manifest.json', config.publicAssets + '/**.{css,js}'])
.pipe(revCollector())
.pipe(gulp.dest(config.railsAssets));
});

4 comments on commit 3bb5a3b

@astjohn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greypants, This repo is awesome. Thanks for your hard work. I'm in the process of using what you have here to wire up something for our stack. I think you missed a config.railsAssets on line 19.

@greypants
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yeah, I think you're right. Good catch, thanks! Will fix.

@greypants
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. 877ea2d

The glob pattern was slightly off as well. Thanks again!

@astjohn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem!

Please sign in to comment.