half-pipe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in half-pipe.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joe Fiorini
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Half Pipe
2
+
3
+ Gem to replace the Rails asset pipeline with a Grunt.js-based workflow, providing dependencies via Bower.
4
+
5
+ ## Who is this For?
6
+
7
+ This initial release assumes you have been using [Grunt.js](http://www.gruntjs.com) in non-Rails apps and would like to start using it in Rails as well. It uses [Bower](http://bower.io) for dependency management, [RequireJS](http://www.requirejs.org) for Javascript modules and Sass for CSS. If you use alternatives to these tools, we'd love to hear from you.
8
+
9
+ ## Getting Started
10
+
11
+ ### Directory Structure
12
+
13
+ We believe that the directory structured imposed by the Rails asset pipeline was a step in the right direction, but did not go far enough in making client code a first-class part of your application. Given that, we have put assets at the same level as the rest of your Ruby code:
14
+
15
+ - `app/scripts` - Javascript files (currently all RequireJS modules)
16
+ - `app/styles` - Sass templates
17
+
18
+ #### Rails Generator
19
+
20
+ In a Rails app, use `rails g half_pipe:install` to get started. This will generate the directory structure and any files necessary for your Grunt workflow.
21
+
22
+ <table>
23
+ <thead>
24
+ <tr>
25
+ <th>
26
+ Generated
27
+ </th>
28
+ <th>
29
+ Purpose
30
+ </th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <tr>
35
+ <td>Gruntfile.js</td>
36
+ <td>
37
+ Main configuration for your Grunt tasks
38
+ </td>
39
+ </tr>
40
+ <tr>
41
+ <td>bower.json</td>
42
+ <td>
43
+ 3rd-party asset dependencies (includes normalize-css, requirejs, and html5shiv by default)
44
+ </td>
45
+ </tr>
46
+ <tr>
47
+ <td>package.json</td>
48
+ <td>
49
+ NPM dependencies (ie. Bower, Grunt, any Grunt tasks)
50
+ </td>
51
+ </tr>
52
+ <tr>
53
+ <td>.jshintrc</td>
54
+ <td>
55
+ Linting configuration for Javascript
56
+ </td>
57
+ </tr>
58
+ <tr>
59
+ <td>app/scripts/application.js</td>
60
+ <td>
61
+ Entry point for requirejs; includes requirejs configuration, main module require and bootstraps page
62
+ </td>
63
+ </tr>
64
+ <tr>
65
+ <td>app/scripts/main.js</td>
66
+ <td>
67
+ Main module for your app; includes page initialization and requires any modules necessary for initialization
68
+ </td>
69
+ </tr>
70
+ <tr>
71
+ <td>config/initializers/sass.rb</td>
72
+ <td>
73
+ Bootstraps Sass with bower importer
74
+ </td>
75
+ </tr>
76
+ </table>
77
+
78
+ Beyond these files, the generator also removes sprockets from `config/application.rb` and replaces `javascript_include_tag "application"` in your application layout with `requirejs_include_tag "/scripts/application.js"`.
79
+
80
+ #### Post-generator Tasks
81
+
82
+ If you're in an app with existing assets, the generator **DOES NOT** touch them. It is up to you to move them into their new homes and incorporate any existing Javascript files into `requirejs` modules.
83
+
84
+ ### Building Assets
85
+
86
+ Build assets by running `grunt build`. This will compile Javascripts to `public/scripts` and stylesheets to `public/styles`.
87
+
88
+ ### Configuration
89
+
90
+ In this early release if you want to configure anything, you'll have to manually change `Gruntfile.js`. We'd like to make this more invisible in the future; please post any use cases for configuration as Github issues.
91
+
92
+ ## Roadmap
93
+
94
+ - Asset fingerprinting
95
+ - Precompilation of client-side templates
96
+ - Javascript module generator
97
+ - Configurable asset directories
98
+ - Configurable build directories
99
+ - Better support for images
100
+ - Better support for non-Rails Ruby frameworks
101
+ - Support for most popular [AltJS](http://www.altjs.com) languages
102
+ - BYO support for less common languages
103
+ - Automatic symlinking of CSS files within bower to SCSS partials within `app/styles`
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ module HalfPipeHelper
2
+
3
+ def requirejs_include_tag(script, options={})
4
+ root = if Rails.env.production? then "scripts" else "components/requirejs" end
5
+ javascript_include_tag "/#{root}/require.js", { data: { main: script } }
6
+ end
7
+
8
+ end
data/half-pipe.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'half-pipe/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "half-pipe"
8
+ gem.version = Half::Pipe::VERSION
9
+ gem.authors = ["Joe Fiorini"]
10
+ gem.email = ["joe@joefiorini.com"]
11
+ gem.description = %q{Grunt-based workflow for your Rails assets}
12
+ gem.summary = %q{Gem to replace the Rails asset pipeline with a Grunt.js-based workflow, providing dependencies via Bower.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rack-asset-compiler"
21
+ end
@@ -0,0 +1,63 @@
1
+ module HalfPipe
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ desc "Installs basic Grunt/Bower setup with Sass & requirejs to your Rails project"
6
+
7
+ def self.source_root
8
+ @_half_pipe_source_root ||= File.expand_path("../templates", __FILE__)
9
+ end
10
+
11
+ def create_initializer_file
12
+ template "package.json", "package.json"
13
+ template "_bowerrc", ".bowerrc"
14
+ template "bower.json", "bower.json"
15
+ template "_jshintrc", ".jshintrc"
16
+ template "Gruntfile.js", "Gruntfile.js"
17
+
18
+ comment_lines "config/application.rb", %r{sprockets/railtie}
19
+
20
+ railties_requires = File.read(File.join(self.class.source_root, "railties.rb"))
21
+ gsub_file "config/application.rb", %r{require 'rails/all'}, railties_requires
22
+
23
+ gsub_file "app/views/layouts/application.html.erb", %r{\s*<%= javascript_include_tag "application" %>$}, ''
24
+ insert_into_file "app/views/layouts/application.html.erb", %Q{ <%= requirejs_include_tag "/scripts/application.js" %>\n }, before: "</body>"
25
+
26
+ directory "app"
27
+
28
+ empty_directory "app/scripts"
29
+
30
+ inside "app/scripts" do
31
+ template "main.js", force: true
32
+ template "application.js", force: true
33
+ end
34
+
35
+ initializer "sass.rb" do
36
+ %Q{
37
+ require 'sass/importers/bower_importer'
38
+ Sass.load_paths << Sass::Importers::BowerImporter.new("components")
39
+ }
40
+ end
41
+
42
+ run "npm install"
43
+
44
+ ENV["PATH"] = "./node_modules/.bin:#{ENV["PATH"]}"
45
+
46
+ run "bower install"
47
+ run "grunt build"
48
+
49
+ say "You may now safely migrate your assets to app/scripts and/or app/styles. Feel free to delete app/assets/javascripts and app/assets/stylesheets when you're done."
50
+ end
51
+
52
+ def main_module_name
53
+ app_name.underscore.dasherize
54
+ end
55
+
56
+ def app_name
57
+ Rails.application.class.parent_name
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,67 @@
1
+ /*global module:false*/
2
+ module.exports = function(grunt) {
3
+
4
+
5
+ // Project configuration.
6
+ grunt.initConfig({
7
+ // Metadata.
8
+ pkg: grunt.file.readJSON('package.json'),
9
+
10
+ jshint: {
11
+ options: {
12
+ jshintrc: '.jshintrc'
13
+ },
14
+ gruntfile: {
15
+ src: 'Gruntfile.js'
16
+ }
17
+ },
18
+
19
+ sass: {
20
+ options: {
21
+ style: 'expanded',
22
+ require: ['./config/initializers/sass']
23
+ },
24
+ 'tmp/styles/main.css': [
25
+ 'app/styles/main.scss'
26
+ ]
27
+ },
28
+
29
+ cssmin: {
30
+ 'public/styles/main.css': 'tmp/styles/main.css'
31
+ },
32
+
33
+ requirejs: {
34
+ options: {
35
+ baseUrl: "app/scripts",
36
+ mainConfigFile: "app/scripts/application.js",
37
+ name: "main",
38
+ out: "public/scripts/application.js"
39
+ },
40
+ scripts: {
41
+ }
42
+ },
43
+
44
+ copy: {
45
+ 'public/scripts/require.js': 'components/requirejs/require.js'
46
+ },
47
+
48
+ clean: ['public/assets/', 'tmp/']
49
+
50
+ });
51
+
52
+ // These plugins provide necessary tasks.
53
+ grunt.loadNpmTasks('grunt-contrib-jshint');
54
+ grunt.loadNpmTasks('grunt-contrib-sass');
55
+ grunt.loadNpmTasks('grunt-contrib-cssmin');
56
+ grunt.loadNpmTasks('grunt-contrib-copy');
57
+ grunt.loadNpmTasks('grunt-contrib-clean');
58
+ grunt.loadNpmTasks('grunt-contrib-requirejs');
59
+
60
+ // Default task.
61
+ grunt.registerTask('default', 'build');
62
+
63
+ // Build task.
64
+ grunt.registerTask('build', ['jshint', 'sass', 'cssmin', 'copy', 'requirejs']);
65
+
66
+ };
67
+
@@ -0,0 +1,3 @@
1
+ {
2
+ "json": "bower.json"
3
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "camelcase": true,
3
+ "indent": 2,
4
+ "white": false,
5
+ "curly": true,
6
+ "eqeqeq": true,
7
+ "immed": true,
8
+ "latedef": true,
9
+ "newcap": false,
10
+ "noarg": true,
11
+ "sub": true,
12
+ "undef": true,
13
+ "boss": true,
14
+ "eqnull": true,
15
+ "browser": true,
16
+ "globals": {
17
+ "test": true,
18
+ "asyncTest": true,
19
+ "start": true,
20
+ "expect": true,
21
+ "module": true,
22
+ "define": true,
23
+ "sinon": true,
24
+ "require": true,
25
+ "console": true,
26
+ "Class": true,
27
+ "Events": true,
28
+ "Options": true,
29
+ "Element": true,
30
+ "$": true,
31
+ "$$": true
32
+ }
33
+ }
34
+
@@ -0,0 +1,17 @@
1
+ require.config({
2
+ baseUrl: '/scripts',
3
+ paths: {
4
+ '<%= main_module_name %>': 'main'
5
+ }
6
+ });
7
+
8
+ require(
9
+ [
10
+ // Add your dependencies here
11
+ '<%= main_module_name %>'
12
+ ],
13
+
14
+ function(initialize/*, modules */){
15
+ initialize();
16
+ }
17
+ );
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ define('<%= main_module_name %>',
4
+ [
5
+ // Add your dependencies here
6
+ ],
7
+
8
+ function(/* modules */){
9
+
10
+ function initialize(){
11
+ // Add your initialization code here
12
+ }
13
+
14
+ return initialize;
15
+
16
+ }
17
+ );
@@ -0,0 +1 @@
1
+ @import "bower!normalize-css/normalize";
@@ -0,0 +1,8 @@
1
+ {
2
+ "dependencies": {
3
+ "html5shiv": "latest",
4
+ "requirejs": "latest",
5
+ "normalize-css": "latest"
6
+ }
7
+ }
8
+
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "<%= app_name %>",
3
+ "devDependencies": {
4
+ "grunt-cli": "~0.1.7",
5
+ "grunt": "~0.4.1",
6
+ "bower": "~0.9.2",
7
+ "grunt-contrib-sass": "~0.3.0",
8
+ "grunt-contrib-copy": "~0.4.1",
9
+ "grunt-contrib-clean": "~0.4.1",
10
+ "grunt-contrib-jshint": "~0.4.3",
11
+ "grunt-contrib-cssmin": "~0.6.0",
12
+ "grunt-contrib-requirejs": "~0.4.0"
13
+ }
14
+ }
15
+
@@ -0,0 +1,7 @@
1
+ require "active_record/railtie"
2
+ # require "sprockets/railtie"
3
+ require "action_controller/railtie"
4
+ require "action_mailer/railtie"
5
+ require "active_resource/railtie"
6
+ require "rails/test_unit/railtie"
7
+
data/lib/half-pipe.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "half-pipe/version"
2
+
3
+ if defined?(Rails)
4
+ require "half-pipe/rails"
5
+ end
6
+
7
+ require "rack/half-pipe"
8
+
9
+ module Half
10
+ module Pipe
11
+ # Your code goes here...
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module HalfPipe
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module Half
2
+ module Pipe
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,99 @@
1
+ require "rack/asset_compiler"
2
+ require "rack/sass_compiler"
3
+
4
+ module Rack
5
+ class HalfPipe
6
+
7
+ def initialize(app)
8
+ @compilers = []
9
+
10
+ @compilers << Rack::AssetCompiler.new(app, scripts_config)
11
+ @compilers << Rack::AssetCompiler.new(app, bower_js_config)
12
+ @compilers << Rack::AssetCompiler.new(app, bower_css_config)
13
+ @compilers << Rack::SassCompiler.new(app, sass_config)
14
+
15
+ @app = app
16
+ end
17
+
18
+ def call(env)
19
+ res = @compilers[0].call(env)
20
+
21
+ if res[0] != 404
22
+ return res
23
+ end
24
+
25
+ res = @compilers[1].call(env)
26
+
27
+ if res[0] != 404
28
+ return res
29
+ end
30
+
31
+ res = @compilers[2].call(env)
32
+
33
+ if res[0] != 404
34
+ return res
35
+ end
36
+
37
+ res = @compilers[3].call(env)
38
+
39
+ if res[0] != 404
40
+ return res
41
+ end
42
+
43
+ @app.call(env)
44
+
45
+
46
+ # @compilers.reduce(nil) do |response,compiler|
47
+ # response.tap{ |u| puts "response: #{response.inspect}" } || compiler.call(env).tap { |u| puts "call returned: #{u.inspect}" }
48
+ # end
49
+
50
+ # res || @app.call(env)
51
+
52
+ end
53
+
54
+ private
55
+
56
+ def scripts_config
57
+ {
58
+ source_dir: 'app/scripts',
59
+ url: '/scripts',
60
+ source_extension: 'js',
61
+ content_type: 'application/javascript',
62
+ compiler: pass_thru_compiler
63
+ }
64
+ end
65
+
66
+ def bower_js_config
67
+ {
68
+ source_dir: 'components',
69
+ url: '/components',
70
+ source_extension: 'js',
71
+ content_type: 'application/javascript',
72
+ compiler: pass_thru_compiler
73
+ }
74
+ end
75
+
76
+ def bower_css_config
77
+ {
78
+ source_dir: 'components',
79
+ url: '/components/css',
80
+ source_extension: 'css',
81
+ content_type: 'text/css',
82
+ compiler: pass_thru_compiler
83
+ }
84
+ end
85
+
86
+ def sass_config
87
+ {
88
+ :source_dir => 'app/styles',
89
+ :url => '/styles'
90
+ }
91
+ end
92
+
93
+ def pass_thru_compiler
94
+ ->(source_file){
95
+ ::File.read(source_file)
96
+ }
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,32 @@
1
+ module Sass
2
+ module Importers
3
+ class BowerImporter < Sass::Importers::Filesystem
4
+
5
+ SUPPORTED_EXTNAMES = ["css", "scss", "sass"]
6
+
7
+ protected
8
+
9
+ def extensions
10
+ super.merge('css' => :scss)
11
+ end
12
+
13
+ def possible_files(name)
14
+ if name.start_with? "bower!"
15
+ name.sub!(/^bower!/, "")
16
+
17
+ path = File.join(@root, name)
18
+ SUPPORTED_EXTNAMES.each do |extname|
19
+ lookup = "#{path}.#{extname}"
20
+ if File.exist? lookup
21
+ return [[lookup, extensions[extname]]]
22
+ end
23
+ end
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: half-pipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joe Fiorini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack-asset-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Grunt-based workflow for your Rails assets
31
+ email:
32
+ - joe@joefiorini.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - app/helpers/half_pipe_helper.rb
43
+ - half-pipe.gemspec
44
+ - lib/generators/half_pipe/install_generator.rb
45
+ - lib/generators/half_pipe/templates/Gruntfile.js
46
+ - lib/generators/half_pipe/templates/_bowerrc
47
+ - lib/generators/half_pipe/templates/_jshintrc
48
+ - lib/generators/half_pipe/templates/app/scripts/application.js
49
+ - lib/generators/half_pipe/templates/app/scripts/main.js
50
+ - lib/generators/half_pipe/templates/app/styles/main.scss
51
+ - lib/generators/half_pipe/templates/bower.json
52
+ - lib/generators/half_pipe/templates/package.json
53
+ - lib/generators/half_pipe/templates/railties.rb
54
+ - lib/half-pipe.rb
55
+ - lib/half-pipe/rails.rb
56
+ - lib/half-pipe/version.rb
57
+ - lib/rack/half-pipe.rb
58
+ - lib/sass/importers/bower_importer.rb
59
+ homepage: ''
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.23
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Gem to replace the Rails asset pipeline with a Grunt.js-based workflow, providing
83
+ dependencies via Bower.
84
+ test_files: []