gulp_assets 1.0.0.pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4ecce9a646f9dc86c138e0566dfd8333bdf81ec
4
+ data.tar.gz: 8b5b0bf7f472fe25d1785faa4ad500659c460ecf
5
+ SHA512:
6
+ metadata.gz: b2d0b2f48f9c90b9c4fa8de0b28eeef337369ac90cec07d2bf9849aa7da5117352474426f47eac60f955a21fc3d09d7fed889c2764903519cc5501ddcc85112b
7
+ data.tar.gz: e1049218df26d125db961681660fefd2224b3d5bd8a8f38f56556a92b1c8420b34296814c17d1ee10fdc992dbabce4720aeacffac2989ab1fa489fe91d21d836
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Jan Varwig
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # GulpAssets
2
+
3
+ Rails Plugin to augment frontend development with a gulp/webpack based
4
+ workflow.
5
+
6
+ - Installs Javascript infrastructure in your Rails project to manage
7
+ frontend assets
8
+ - Provides view helpers to Rails that allow you to easily reference
9
+ gulp generated assets from Rails views
10
+ - Puts Livereload into the Rails middleware stack. This injects the
11
+ Livereload client into Rails-renderd pages, updates are triggered from
12
+ gulp.
13
+
14
+ ## Usage
15
+
16
+ 1. Add `gem 'gulp_assets' to your Gemfile and run `bundle install`.
17
+ 2. Run `rails generate gulp_assets` to generate all necessary files.
18
+ 3. Develop your frontend code in the `frontend` directory
19
+ 4. Reference files generated by gulp using the `gulp_asset_path` helper
20
+ 5. Run `npm start` during development for livereload/Webpack
21
+ Hot Module replacement.
22
+
23
+ ## Structure
24
+
25
+ `frontend/assets` contains static assets (images, fonts, icons). A
26
+ static asset is a file that is not processed and that does not contain
27
+ references to other files. They are simply copied to
28
+ `public/assets/assets`.
29
+
30
+ `frontend/stylesheets` contains SCSS files which are compiled to
31
+ `public/assets/stylesheets`. Files beginning with underscores are
32
+ ignored.
33
+
34
+ `frontend/javascripts/main.js` is the entry point for the client-side
35
+ Javascript. This is picked up by Webpack, bundled and copied to
36
+ `public/assets/javascripts`. If you need additional entry points,
37
+ please adjust the webpack configuration accordingly.
38
+
39
+ ## Gulp Commands
40
+
41
+ ### `gulp default`
42
+
43
+ Runs the webpack development server which will watch files, trigger
44
+ livereload and serve static assets.
45
+
46
+ This also runs if you execute `npm start`.
47
+
48
+ ### `gulp precompile`
49
+
50
+ Compiles assets for production, hashes their names and generates a
51
+ `rev-mainfest.json`, which is used by the `gulp_asset_path` helper to
52
+ generate the correct links with the hash in the filename.
53
+
54
+ ## Referencing gulp assets from Rails views
55
+
56
+ The `gulp_assets_path` helper takes a partial path as a parameter that
57
+ sits inside the `public/assets` folder. It then operates differently,
58
+ depending on the `RAILS_ENV`:
59
+
60
+ - development: Prepend the path with the correct location on the webpack
61
+ dev server, usually `//localhost:8080/assets`. `javascripts/main.js`
62
+ would become `//localhost:8080/assets/javascripts/main.js`.
63
+ - production: Prepend the path with the correct asset path and replace
64
+ the filename with the hashed version. `javascripts/main.js` would
65
+ become `/assets/javascripts/main-a42bb48a5f83.js`.
66
+
67
+ ### Shortcuts
68
+
69
+ To include a gulp-generated javascript or stylesheet, use the `gulp_javascript` or
70
+ `gulp_stylesheet` helper:
71
+
72
+ <%= gulp_javascript "main" %>
73
+ <%= gulp_stylesheet "main" %>
74
+
75
+ Since "main" is the default name, you can omit it:
76
+
77
+ <%= gulp_javascript %>
78
+ <%= gulp_stylesheet %>
79
+
80
+ Both accept a second parameter for overwriting attributes. This can be
81
+ used for example to change the `media` attribute for a stylesheet.
82
+
83
+ ## Examples
84
+
85
+ ### CSS
86
+
87
+ - `frontend/stylesheets/main.scss` Input file
88
+ - `public/assets/stylesheets/main.css` Output File
89
+ - `<link rel="stylesheet" media="all" href="<%=gulp_asset_path('stylesheets/main.css')%>"/>` Used to link to the file.
90
+ - `<%= gulp_stylesheet "main" %>` or `<%= gulp_stylesheet %>` also generate correct links
91
+
92
+ ### JS
93
+
94
+ - `frontend/javscripts/main.js` Input file
95
+ - `public/assets/javscripts/main.js` Output File
96
+ - `<script src="<%=gulp_asset_path('javascripts/main.js')%>"></script>`
97
+ - `<%= gulp_javascript "main" %>` or `<%= gulp_javascript %>` also generate correct links
@@ -0,0 +1,28 @@
1
+ class GulpAssetsGenerator < Rails::Generators::Base
2
+ desc "Setup up the folder structure for Gulp Assets"
3
+ source_root File.expand_path('../../../template', __FILE__)
4
+
5
+ def create_frontend_folder
6
+ directory 'frontend'
7
+ copy_file ".eslintrc"
8
+ end
9
+
10
+ def create_webpack_config
11
+ copy_file 'webpack.common.config.js'
12
+ copy_file 'webpack.config.js'
13
+ copy_file 'webpack.hot.config.js' # TODO replace host dynamically
14
+ end
15
+
16
+ def create_gulpfile
17
+ copy_file 'gulpfile.js'
18
+ end
19
+
20
+ def create_module
21
+ template "package.json"
22
+ end
23
+
24
+ def install_dependencies
25
+ run "npm install"
26
+ end
27
+
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'gulp_assets/view_helpers'
2
+
3
+ module GulpAssets
4
+ class Railtie < Rails::Railtie
5
+ config.gulp_assets = ActiveSupport::OrderedOptions.new
6
+
7
+ config.gulp_assets.rev_manifest_path = 'public/assets/rev-manifest.json'
8
+ config.gulp_assets.rev_manifest = nil
9
+ config.gulp_assets.dev_host = "//localhost:8080"
10
+ config.gulp_assets.path = "/assets"
11
+
12
+ initializer "gulp_assets.rev_manifest" do
13
+ if File.exist?(config.gulp_assets.rev_manifest_path)
14
+ config.gulp_assets.rev_manifest = JSON.parse(File.read(config.gulp_assets.rev_manifest_path))
15
+ end
16
+ end
17
+
18
+ initializer "gulp_assets.view_helpers" do
19
+ ActionView::Base.send :include, ViewHelpers
20
+ end
21
+
22
+ initializer "gulp_assets.livereload" do
23
+ if Rails.env.development?
24
+ require 'rack-livereload'
25
+ config.app_middleware.insert_after ActionDispatch::Static, Rack::LiveReload
26
+ end
27
+ end
28
+
29
+ rake_tasks do
30
+ load "tasks/gulp_assets_tasks.rake"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module GulpAssets
2
+ VERSION = "1.0.0.pre.2"
3
+ end
@@ -0,0 +1,32 @@
1
+ module GulpAssets
2
+ module ViewHelpers
3
+
4
+ def gulp_asset_path(path)
5
+ config = Rails.application.config.gulp_assets
6
+
7
+ if Rails.env.development?
8
+ "#{config.dev_host}#{config.path}/#{path}"
9
+ else
10
+ path = config.rev_manifest[path] if config.rev_manifest
11
+ "#{config.path}/#{path}"
12
+ end
13
+ end
14
+
15
+ def gulp_javascript(filename="main", attributes={})
16
+ default_attributes = {
17
+ src: gulp_asset_path("javascripts/#{filename}.js")
18
+ }
19
+ content_tag "script", nil, default_attributes.merge(attributes)
20
+ end
21
+
22
+ def gulp_stylesheet(filename="main", attributes={})
23
+ default_attributes = {
24
+ rel: "stylesheet",
25
+ media: "all",
26
+ href: gulp_asset_path("stylesheets/#{filename}.css")
27
+ }
28
+ tag 'link', default_attributes.merge(attributes)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ module GulpAssets
2
+ end
3
+
4
+ require 'gulp_assets/railtie' if defined?(Rails)
@@ -0,0 +1,8 @@
1
+ namespace :gulp_assets do
2
+ desc "Compile Gulp Assets"
3
+ task :precompile do
4
+ sh "gulp precompile"
5
+ end
6
+ end
7
+
8
+ Rake::Task['assets:precompile'].enhance ['gulp_assets:precompile']
@@ -0,0 +1,22 @@
1
+ {
2
+ "parser": "babel-eslint",
3
+ "env": {
4
+ "es6": true,
5
+ "node": true,
6
+ "browser": true
7
+ },
8
+ "ecmaFeatures": {
9
+ "modules": true,
10
+ "jsx": true
11
+ },
12
+ "rules": {
13
+ "quotes": [1, "single"],
14
+ "no-return-assign": 0,
15
+ "no-multi-spaces": 0,
16
+ "no-use-before-define": 0,
17
+ "no-underscore-dangle": 0,
18
+ "no-unused-vars": 0,
19
+ "no-script-url": 0
20
+ },
21
+ "plugins": [ "react" ]
22
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ import $ from 'jquery';
4
+
5
+ $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
6
+ var token;
7
+ if (!options.crossDomain) {
8
+ token = $('meta[name="csrf-token"]').attr('content');
9
+ if (token) {
10
+ return jqXHR.setRequestHeader('X-CSRF-Token', token);
11
+ }
12
+ }
13
+ });
14
+
15
+ $(() => console.log('Hello World'));
@@ -0,0 +1,3 @@
1
+ /*
2
+ * Your styles here
3
+ */
@@ -0,0 +1,110 @@
1
+ var _ = require('lodash');
2
+ var gulp = require('gulp');
3
+ var sass = require('gulp-sass');
4
+ var gutil = require('gulp-util');
5
+ var livereload = require('gulp-livereload');
6
+ var rev = require('gulp-rev');
7
+ var revReplace = require('gulp-rev-replace');
8
+ var stream = require('webpack-stream');
9
+ var rename = require('gulp-rename');
10
+ //var debug = require('gulp-debug');
11
+ var sequence = require('run-sequence');
12
+
13
+ var path = require('path');
14
+ var webpack = require('webpack');
15
+ var WebpackDevServer = require('webpack-dev-server');
16
+ var webpackConfig = require('./webpack.common.config');
17
+ var webpackConfigHot = require('./webpack.hot.config');
18
+
19
+ var BASE = 'frontend/';
20
+ var ASSET_FILES = 'frontend/assets/**/*';
21
+ var STYLESHEET_FILES = 'frontend/stylesheets/**/*.scss';
22
+ var OUTPUT_FOLDER = 'public/assets/';
23
+
24
+ function replace() {
25
+ var manifest = gulp.src(OUTPUT_FOLDER + 'rev-manifest.json');
26
+ return revReplace({manifest: manifest});
27
+ }
28
+
29
+ gulp.task('assets:development', function(){
30
+ return gulp.src(ASSET_FILES, {base: BASE})
31
+ .pipe(gulp.dest(OUTPUT_FOLDER))
32
+ .pipe(livereload());
33
+ });
34
+
35
+ gulp.task('assets:production', function(){
36
+ return gulp.src(ASSET_FILES, {base: BASE})
37
+ .pipe(gulp.dest(OUTPUT_FOLDER))
38
+ .pipe(rev())
39
+ .pipe(gulp.dest(OUTPUT_FOLDER))
40
+ .pipe(rev.manifest(OUTPUT_FOLDER + 'rev-manifest.json', {
41
+ merge: true,
42
+ base: OUTPUT_FOLDER
43
+ }))
44
+ .pipe(gulp.dest(OUTPUT_FOLDER));
45
+ });
46
+
47
+ gulp.task('css:development', function () {
48
+ return gulp.src(STYLESHEET_FILES, {base: BASE})
49
+ .pipe(sass()
50
+ .on('error', sass.logError))
51
+ .pipe(gulp.dest(OUTPUT_FOLDER))
52
+ .pipe(livereload());
53
+ });
54
+
55
+ gulp.task('css:production', function () {
56
+ return gulp.src(STYLESHEET_FILES, {base: BASE})
57
+ .pipe(sass()
58
+ .on('error', sass.logError))
59
+ .pipe(replace())
60
+ .pipe(gulp.dest(OUTPUT_FOLDER))
61
+ .pipe(rev())
62
+ .pipe(gulp.dest(OUTPUT_FOLDER))
63
+ .pipe(rev.manifest(OUTPUT_FOLDER + 'rev-manifest.json', {
64
+ merge: true,
65
+ base: OUTPUT_FOLDER
66
+ }))
67
+ .pipe(gulp.dest(OUTPUT_FOLDER));
68
+ });
69
+
70
+ gulp.task('javascript:production', function(){
71
+ return gulp.src('frontend/javascripts/main.js', {base: 'frontend'})
72
+ .pipe(stream(webpackConfig, webpack))
73
+ .pipe(rename({dirname: 'javascripts'}))
74
+ .pipe(gulp.dest(OUTPUT_FOLDER))
75
+ .pipe(rev())
76
+ .pipe(gulp.dest(OUTPUT_FOLDER))
77
+ .pipe(rev.manifest(OUTPUT_FOLDER + 'rev-manifest.json', {
78
+ merge: true,
79
+ base: OUTPUT_FOLDER
80
+ }))
81
+ .pipe(gulp.dest(OUTPUT_FOLDER));
82
+ });
83
+
84
+ gulp.task('webpack:server', function(cb){
85
+ var compiler = webpack(webpackConfigHot);
86
+ var server = new WebpackDevServer(compiler, webpackConfigHot.devServer);
87
+ server.listen(8080, 'localhost', function(){
88
+ console.info('==> 🚧 Webpack development server listening on localhost:8080');
89
+ });
90
+ server.listeningApp.on('close', function(){
91
+ console.log('closing', arguments);
92
+ cb();
93
+ });
94
+ });
95
+
96
+ gulp.task('default', ['css:development', 'assets:development'], function(cb){
97
+ gulp.run('webpack:server');
98
+ livereload.listen();
99
+ gulp.watch(STYLESHEET_FILES, ['css:development']);
100
+ });
101
+
102
+ gulp.task('precompile', function(cb){
103
+ sequence(
104
+ 'assets:production',
105
+ 'css:production',
106
+ 'javascript:production',
107
+ cb
108
+ );
109
+ });
110
+
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "<%= Rails.application.class.parent_name %>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "start": "$(npm bin)/gulp"
7
+ },
8
+ "dependencies": {
9
+ "babel-core": "~5.5.8",
10
+ "babel-loader": "~5.1.4",
11
+ "gulp": "^3.9.0",
12
+ "gulp-rev-replace": "^0.4.2",
13
+ "gulp-livereload": "^3.8.0",
14
+ "gulp-rename": "^1.2.2",
15
+ "gulp-rev": "^5.1.0",
16
+ "gulp-sass": "^2.0.3",
17
+ "gulp-util": "^3.0.6",
18
+ "jquery": "~2.1.4",
19
+ "lodash": "^3.9.3",
20
+ "node-libs-browser": "~0.5.2",
21
+ "react": "~0.13.3",
22
+ "redux": "~0.12.0",
23
+ "redux-promise-middleware": "0.0.1",
24
+ "run-sequence": "^1.1.2",
25
+ "webpack": "~1.9.11",
26
+ "webpack-dev-server": "^1.10.1",
27
+ "webpack-stream": "^2.0.0",
28
+ "react-hot-loader": "^1.2.8"
29
+ }
30
+ }
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var webpack = require('webpack');
5
+
6
+ module.exports = {
7
+ entry: [
8
+ './frontend/javascripts/main.js'
9
+ ],
10
+ output: {
11
+ path: path.resolve('./public/assets/javascripts'),
12
+ publicPath: '/assets/javascripts',
13
+ filename: '[name].js'
14
+ },
15
+ module: {
16
+ loaders: [
17
+ {
18
+ test: /\.jsx?$/,
19
+ exclude: /(node_modules|bower_components)/,
20
+ loaders: ['babel']
21
+ }
22
+ ]
23
+ }
24
+ };
25
+
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('./webpack.hot.config');
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var webpack = require('webpack');
5
+ var _ = require('lodash');
6
+ var common = require('./webpack.common.config');
7
+
8
+ var hot = _.cloneDeep(common);
9
+
10
+ hot.entry.unshift(
11
+ 'webpack-dev-server/client?http://localhost:8080',
12
+ 'webpack/hot/only-dev-server'
13
+ );
14
+ hot.output.publicPath = '//localhost:8080/assets/javascripts';
15
+ hot.module.loaders[0].loaders.unshift('react-hot');
16
+ hot.devtool = 'cheap-module-eval-source-map';
17
+ hot.plugins = [
18
+ new webpack.HotModuleReplacementPlugin()
19
+ ];
20
+
21
+ hot.devServer = {
22
+ contentBase: './public',
23
+ publicPath: '/assets/javascripts',
24
+ hot: true,
25
+ colors: true
26
+ };
27
+
28
+ module.exports = hot;
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gulp_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.2
5
+ platform: ruby
6
+ authors:
7
+ - Jan Varwig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-livereload
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.16
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.16
41
+ description: |2
42
+ Rails Plugin to augment frontend development with a gulp/webpack based
43
+ workflow.
44
+
45
+ - Installs Javascript infrastructure in your Rails project to manage
46
+ frontend assets
47
+ - Provides view helpers to Rails that allow you to easily reference
48
+ gulp generated assets from Rails views
49
+ - Puts Livereload into the Rails middleware stack. This injects the
50
+ Livereload client into Rails-renderd pages, updates are triggered from
51
+ gulp.
52
+ email:
53
+ - jan.varwig@hitfoxgroup.com
54
+ executables: []
55
+ extensions: []
56
+ extra_rdoc_files: []
57
+ files:
58
+ - MIT-LICENSE
59
+ - README.md
60
+ - lib/generators/gulp_assets_generator.rb
61
+ - lib/gulp_assets.rb
62
+ - lib/gulp_assets/railtie.rb
63
+ - lib/gulp_assets/version.rb
64
+ - lib/gulp_assets/view_helpers.rb
65
+ - lib/tasks/gulp_assets_tasks.rake
66
+ - template/.eslintrc
67
+ - template/frontend/assets/.empty_directory
68
+ - template/frontend/javascripts/actions/.empty_directory
69
+ - template/frontend/javascripts/components/.empty_directory
70
+ - template/frontend/javascripts/constants/.empty_directory
71
+ - template/frontend/javascripts/main.js
72
+ - template/frontend/javascripts/stores/.empty_directoty
73
+ - template/frontend/stylesheets/main.scss
74
+ - template/gulpfile.js
75
+ - template/package.json.tt
76
+ - template/webpack.common.config.js
77
+ - template/webpack.config.js
78
+ - template/webpack.hot.config.js
79
+ homepage: http://github.com/hitfox/gulp_assets/
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.1
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Integrate Gulp with Rails
103
+ test_files: []