sprockets-rails 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Sam Stephenson
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.markdown ADDED
@@ -0,0 +1,67 @@
1
+ `sprockets-rails`
2
+ =================
3
+
4
+ The `sprockets-rails` plugin sets up your Rails application for use with [Sprockets](http://github.com/sstephenson/sprockets). To install it, first install the `sprockets` RubyGem, then check out a copy of the `sprockets-rails` repository into your `vendor/plugins/` directory. When you run the bundled `install.rb` script, `sprockets-rails` will create two new directories in your application and copy a configuration file into your `config/` directory.
5
+
6
+ `sprockets-rails` includes a controller named `SprocketsController` that renders your application's Sprockets concatenation. When caching is enabled, e.g. in production mode, `SprocketsController` uses Rails page caching to save the concatenated output to `public/sprockets.js` the first time it is requested. When caching is disabled, e.g. in development mode, `SprocketsController` will render a fresh concatenation any time a source file changes.
7
+
8
+ To source Sprockets' JavaScript concatenation from your HTML templates, use the provided `sprockets_include_tag` helper.
9
+
10
+ `sprockets-rails` also includes a set of Rake tasks for generating the concatenation (`rake sprockets:install_script`) and installing provided assets (`rake sprockets:install_assets`). Run `sprockets:install_assets` any time you add or update a Sprockets plugin in your application. Add `after "deploy:update_code", "sprockets:install_script"` as a [Capistrano](http://www.capify.org/) post-deploy hook to generate the Sprockets concatenation on your servers automatically at deploy time.
11
+
12
+ Here's a walkthrough of the installation process:
13
+
14
+ 1. `gem install --remote sprockets`
15
+
16
+ 2. `script/plugin install git://github.com/sstephenson/sprockets-rails.git`
17
+
18
+ You now have `app/javascripts/` and `vendor/sprockets/` directories in your application, as well as a `config/sprockets.yml` file.
19
+
20
+ 3. Edit your `config/routes.rb` file to add routes for `SprocketsController`:
21
+
22
+ ActionController::Routing::Routes.draw do |map|
23
+ # Add the following line:
24
+ SprocketsApplication.routes(map)
25
+ ...
26
+ end
27
+
28
+ 4. Move your JavaScript source files from `public/javascripts/` into `app/javascripts/`. All files in all subdirectories of `app/javascripts/` will be required by Sprockets in alphabetical order, with the exception of `app/javascripts/application.js`, which is required _before any other file_. (You can change this behavior by editing the `source_files` line of `config/sprockets.yml`.)
29
+
30
+ 5. Adjust your HTML templates to call `<%= sprockets_include_tag %>` instead of `<%= javascript_include_tag ... %>`.
31
+
32
+ Once `sprockets-rails` is installed, you can check out Sprockets plugins into the `vendor/sprockets/` directory. By default, `sprockets-rails` configures Sprockets' load path to search `vendor/sprockets/*/src/`, as well as `vendor/plugins/*/javascripts/`. This means that the `javascripts/` directories of Rails plugins are automatically installed into your Sprockets load path.
33
+
34
+ ## Using multiple sprockets configurations in a project
35
+
36
+ 1. Edit your `config/sprockets.rb` file to name the configurations:
37
+
38
+ :default:
39
+ :asset_root: public
40
+ :load_path:
41
+ - app/javascripts
42
+ - vendor/sprockets/*/src
43
+ - vendor/plugins/*/javascripts
44
+ :source_files:
45
+ - app/javascripts/application.js
46
+ :special:
47
+ :asset_root: public
48
+ :load_path:
49
+ - app/javascripts
50
+ - vendor/sprockets/*/src
51
+ - vendor/plugins/*/javascripts
52
+ :source_files:
53
+ - app/javascripts/special.js
54
+
55
+ 2. Adjust your HTML templates to call `<%= sprockets_include_tag(:config_name) %>` with the name of the configuration you wish to use.
56
+
57
+ 3. Concatenations are located at `RAILS_ROOT/sprockets/<config_name>.js`, except for the default configuration, whose concatenation located at `RAILS_ROOT/sprockets.js`.
58
+
59
+ ## License
60
+
61
+ Copyright &copy; 2009 Sam Stephenson.
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "sprockets-rails"
10
+ gem.summary = %Q{Sprockets JavaScript dependency management and concatenation support for Rails applications}
11
+ gem.description = %Q{Sprockets JavaScript dependency management and concatenation support for Rails applications}
12
+ gem.email = "jeff@80beans.com"
13
+ gem.homepage = "http://github.com/80beans/sprockets-rails"
14
+ gem.authors = ["Jeff Kreeftmeijer"]
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ desc 'Default: run unit tests.'
21
+ task :default => :test
22
+
23
+ desc 'Test the sprockets plugin.'
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = true
28
+ end
29
+
30
+ desc 'Generate documentation for the sprockets plugin.'
31
+ Rake::RDocTask.new(:rdoc) do |rdoc|
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = 'Sprockets'
34
+ rdoc.options << '--line-numbers' << '--inline-source'
35
+ rdoc.rdoc_files.include('README')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
38
+
39
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,10 @@
1
+ :default:
2
+ :asset_root: public
3
+ :load_path:
4
+ - app/javascripts
5
+ - vendor/sprockets/*/src
6
+ - vendor/plugins/*/javascripts
7
+ - vendor/plugins/*/app/javascripts
8
+ :source_files:
9
+ - app/javascripts/application.js
10
+ - app/javascripts/**/*.js
@@ -0,0 +1,13 @@
1
+ class SprocketsRailsGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.directory 'vendor/sprockets'
6
+ m.directory 'app/javascripts'
7
+
8
+ m.file 'application.js', 'app/javascripts/application.js'
9
+ m.file '/../../../config/sprockets.yml', 'config/sprockets.yml'
10
+ m.file '/../../../tasks/sprockets_tasks.rake', 'lib/tasks/sprockets_tasks.rake'
11
+ end
12
+ end
13
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'sprockets-rails')
data/install.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "fileutils"
2
+ include FileUtils::Verbose
3
+
4
+ RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..")) unless defined?(RAILS_ROOT)
5
+
6
+ mkdir_p File.join(RAILS_ROOT, "vendor", "sprockets")
7
+ mkdir_p File.join(RAILS_ROOT, "app", "javascripts")
8
+ touch File.join(RAILS_ROOT, "app", "javascripts", "application.js")
9
+
10
+ unless File.exists?(File.join(RAILS_ROOT, "config", "sprockets.yml"))
11
+ cp File.join(File.dirname(__FILE__), "config", "sprockets.yml"),
12
+ File.join(RAILS_ROOT, "config")
13
+ end
data/lib/sprocket.rb ADDED
@@ -0,0 +1,74 @@
1
+ require "fileutils"
2
+
3
+ class Sprocket
4
+ attr_reader :group
5
+
6
+ def initialize(group='default')
7
+ group = 'default' if group.nil?
8
+ @group = group.to_sym
9
+ end
10
+
11
+ def source
12
+ concatenation.to_s
13
+ end
14
+
15
+ def install_script
16
+ # /public/sprocktes might not exist yet, and sprockets-1.0.2 throws an exception
17
+ FileUtils.mkdir_p(File.dirname(asset_path))
18
+ concatenation.save_to(asset_path)
19
+ end
20
+
21
+ def install_assets
22
+ secretary.install_assets
23
+ end
24
+
25
+ class << self
26
+ def configurations
27
+ @conf ||= YAML.load(IO.read(Sprocket.configuration_path)) || {}
28
+ @conf.keys
29
+ end
30
+
31
+ def configuration_path
32
+ File.join(Rails.root, "config", "sprockets.yml")
33
+ end
34
+ end
35
+
36
+ protected
37
+ def secretary
38
+ @secretary ||= Sprockets::Secretary.new(configuration.merge(:root => Rails.root))
39
+ end
40
+
41
+ def configuration
42
+ load_configuration
43
+ end
44
+
45
+ def load_configuration
46
+ @conf ||= YAML.load(IO.read(Sprocket.configuration_path)) || {}
47
+ if @conf[group]
48
+ @conf[group]
49
+ else
50
+ {}
51
+ end
52
+ end
53
+
54
+ def concatenation
55
+ secretary.reset! unless source_is_unchanged?
56
+ secretary.concatenation
57
+ end
58
+
59
+ def asset_path
60
+ if group == :default
61
+ File.join(Rails.public_path, "sprockets.js")
62
+ else
63
+ File.join(Rails.public_path, "sprockets", "#{group}.js")
64
+ end
65
+ end
66
+
67
+ def source_is_unchanged?
68
+ previous_source_last_modified, @source_last_modified =
69
+ @source_last_modified, secretary.source_last_modified
70
+
71
+ previous_source_last_modified == @source_last_modified
72
+ end
73
+
74
+ end
@@ -0,0 +1,8 @@
1
+ require "sprockets"
2
+ require "sprockets_helper"
3
+ require "sprocket"
4
+ require "sprockets_application"
5
+
6
+ class ActionController::Base
7
+ helper :sprockets
8
+ end
@@ -0,0 +1,8 @@
1
+ module SprocketsApplication
2
+ mattr_accessor :use_page_caching
3
+ self.use_page_caching = true
4
+
5
+ def self.routes(map)
6
+ map.resources(:sprockets, :only => [:index, :show])
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ class SprocketsController < ActionController::Base
2
+ caches_page :show, :if => Proc.new { SprocketsApplication.use_page_caching }
3
+
4
+ def index
5
+ show
6
+ end
7
+
8
+ def show
9
+ sprocket = Sprocket.new(params[:id])
10
+ render :text => sprocket.source, :content_type => "text/javascript"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module SprocketsHelper
2
+ def sprockets_include_tag(name = nil)
3
+ if name
4
+ javascript_include_tag("/sprockets/#{ name.to_s }.js")
5
+ else
6
+ javascript_include_tag("/sprockets.js")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ def run_sprockets_rake_task(task)
2
+ rake = fetch(:rake, 'rake')
3
+ rails_env = fetch(:rails_env, 'production')
4
+ run "cd #{current_release}; #{rake} RAILS_ENV=#{rails_env} sprockets:#{task}"
5
+ end
6
+
7
+ namespace :sprockets do
8
+ desc "Generate and install the Sprockets concatenated JavaScript file for all configuration groups"
9
+ task :install_script, :roles => :app do
10
+ run_sprockets_rake_task 'install_script'
11
+ end
12
+
13
+ desc "Install any assets provided by Sprockets script, for all configuration groups"
14
+ task :install_assets, :roles => :app do
15
+ run_sprockets_rake_task 'install_assets'
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sprockets-rails}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeff Kreeftmeijer"]
12
+ s.date = %q{2009-12-02}
13
+ s.description = %q{Sprockets JavaScript dependency management and concatenation support for Rails applications}
14
+ s.email = %q{jeff@80beans.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "config/sprockets.yml",
25
+ "generators/sprockets_rails/sprockets_rails_generator.rb",
26
+ "generators/sprockets_rails/templates/application.js",
27
+ "init.rb",
28
+ "install.rb",
29
+ "lib/sprocket.rb",
30
+ "lib/sprockets-rails.rb",
31
+ "lib/sprockets_application.rb",
32
+ "lib/sprockets_controller.rb",
33
+ "lib/sprockets_helper.rb",
34
+ "recipes/sprockets_tasks.rb",
35
+ "sprockets-rails.gemspec",
36
+ "tasks/sprockets_tasks.rake",
37
+ "test/sprockets_test.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/80beans/sprockets-rails}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{Sprockets JavaScript dependency management and concatenation support for Rails applications}
44
+ s.test_files = [
45
+ "test/sprockets_test.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ else
54
+ end
55
+ else
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ def process_config
2
+ if (config = ENV['CONFIG'] || config = ENV['CONFIGURATION']) && !Sprocket.configurations.include?(config)
3
+ raise "Configuration #{config} doesn't exist. Valid configurations: #{Sprocket.configurations.to_sentence}."
4
+ end
5
+
6
+ return config
7
+ end
8
+
9
+ namespace :sprockets do
10
+ desc "Generate and install the Sprockets concatenated JavaScript file for all configuration groups. Generate and install for a specific configuration by specifying CONFIG=<name>."
11
+ task :install_script => :environment do
12
+ if config = process_config
13
+ Sprocket.new(config).install_script
14
+ else
15
+ Sprocket.configurations.each { |configuration| Sprocket.new(configuration).install_script }
16
+ end
17
+ end
18
+
19
+ desc "Install any assets provided by Sprockets script, for all configuration groups. Install assets for a specific configuration by specifying CONFIG=<name>."
20
+ task :install_assets => :environment do
21
+ if config = process_config
22
+ Sprocket.new(config).install_assets
23
+ else
24
+ Sprocket.configurations.each { |configuration| Sprocket.new(configuration).install_assets }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class SprocketsTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Kreeftmeijer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-02 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Sprockets JavaScript dependency management and concatenation support for Rails applications
17
+ email: jeff@80beans.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - .gitignore
26
+ - MIT-LICENSE
27
+ - README.markdown
28
+ - Rakefile
29
+ - VERSION
30
+ - config/sprockets.yml
31
+ - generators/sprockets_rails/sprockets_rails_generator.rb
32
+ - generators/sprockets_rails/templates/application.js
33
+ - init.rb
34
+ - install.rb
35
+ - lib/sprocket.rb
36
+ - lib/sprockets-rails.rb
37
+ - lib/sprockets_application.rb
38
+ - lib/sprockets_controller.rb
39
+ - lib/sprockets_helper.rb
40
+ - recipes/sprockets_tasks.rb
41
+ - sprockets-rails.gemspec
42
+ - tasks/sprockets_tasks.rake
43
+ - test/sprockets_test.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/80beans/sprockets-rails
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Sprockets JavaScript dependency management and concatenation support for Rails applications
72
+ test_files:
73
+ - test/sprockets_test.rb