dm-sprockets-rails 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.2)
19
+ rcov
20
+ shoulda
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,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "dm-sprockets-rails"
16
+ gem.homepage = "http://github.com/dudemeister/sprockets-rails"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{sprockets-rails}
19
+ gem.description = %Q{sprockets-rails containing changes to allow sections and rails3 compatability}
20
+ gem.email = "jelveh@web.de"
21
+ gem.authors = ["Ali Jelveh"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "sprockets-rails #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,7 @@
1
+ class SprocketsController < ActionController::Base
2
+ caches_page :show, :if => Proc.new { SprocketsApplication.use_page_caching }
3
+
4
+ def show
5
+ render :text => SprocketsApplication.source(params[:id]), :content_type => "text/javascript"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ :default:
2
+ :asset_root: public
3
+ :load_path:
4
+ - app/javascripts
5
+ - vendor/sprockets/*/src
6
+ - vendor/plugins/*/javascripts
7
+ :source_files:
8
+ - app/javascripts/application.js
9
+ - app/javascripts/**/*.js
data/init.rb ADDED
@@ -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
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
@@ -0,0 +1,12 @@
1
+ require "sprockets"
2
+ require "sprockets_helper"
3
+ require "sprockets_application"
4
+
5
+ class ActionController::Base
6
+ helper :sprockets
7
+ end
8
+
9
+ module SprocketsRails
10
+ class Engine < Rails::Engine
11
+ end
12
+ end
@@ -0,0 +1,53 @@
1
+ module SprocketsApplication
2
+ mattr_accessor :use_page_caching
3
+ self.use_page_caching = false
4
+
5
+ class << self
6
+ def routes(map)
7
+ map.resource(:sprockets)
8
+ end
9
+
10
+ def source(group = nil)
11
+ @group = group || "default"
12
+ concatenation.to_s
13
+ end
14
+
15
+ def install_script
16
+ concatenation.save_to(asset_path)
17
+ end
18
+
19
+ def install_assets
20
+ secretary.install_assets
21
+ end
22
+
23
+ protected
24
+
25
+ def secretaries
26
+ @secretaries ||= {}
27
+ end
28
+
29
+ def secretary
30
+ secretaries[@group] ||= Sprockets::Secretary.new(configuration[@group].symbolize_keys.merge(:root => ::Rails.root.to_s))
31
+ end
32
+
33
+ def configuration
34
+ YAML.load(IO.read(File.join(::Rails.root.to_s, "config", "sprockets.yml"))) || {}
35
+ end
36
+
37
+ def concatenation
38
+ secretary.reset! unless source_is_unchanged?
39
+ secretary.concatenation
40
+ end
41
+
42
+ def asset_path
43
+ File.join(Rails.public_path, "sprockets.js")
44
+ end
45
+
46
+ def source_is_unchanged?
47
+ previous_source_last_modified, @source_last_modified =
48
+ @source_last_modified, secretary.source_last_modified
49
+
50
+ previous_source_last_modified == @source_last_modified
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ class SprocketsController < ActionController::Base
2
+ caches_page :show, :if => Proc.new { SprocketsApplication.use_page_caching }
3
+
4
+ def show
5
+ render :text => SprocketsApplication.source(params[:id]), :content_type => "text/javascript"
6
+ end
7
+ 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,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,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-sprockets-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Ali Jelveh
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-03 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :development
22
+ name: shoulda
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ requirement: *id001
31
+ prerelease: false
32
+ - !ruby/object:Gem::Dependency
33
+ type: :development
34
+ name: bundler
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 0
42
+ - 0
43
+ version: 1.0.0
44
+ requirement: *id002
45
+ prerelease: false
46
+ - !ruby/object:Gem::Dependency
47
+ type: :development
48
+ name: jeweler
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 5
56
+ - 2
57
+ version: 1.5.2
58
+ requirement: *id003
59
+ prerelease: false
60
+ - !ruby/object:Gem::Dependency
61
+ type: :development
62
+ name: rcov
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirement: *id004
71
+ prerelease: false
72
+ description: sprockets-rails containing changes to allow sections and rails3 compatability
73
+ email: jelveh@web.de
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - README.markdown
80
+ files:
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - MIT-LICENSE
84
+ - README.markdown
85
+ - Rakefile
86
+ - VERSION
87
+ - app/controllers/sprockets_controller.rb
88
+ - config/sprockets.yml
89
+ - init.rb
90
+ - install.rb
91
+ - lib/sprockets-rails.rb
92
+ - lib/sprockets_application.rb
93
+ - lib/sprockets_controller.rb
94
+ - lib/sprockets_helper.rb
95
+ - recipes/sprockets_tasks.rb
96
+ - tasks/sprockets_tasks.rake
97
+ - test/sprockets_test.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/dudemeister/sprockets-rails
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.6
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: sprockets-rails
128
+ test_files:
129
+ - test/sprockets_test.rb