Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 77a181304d686e5b771ac2e8fec083b0fb9fe3cb 0 parents
@sstephenson sstephenson authored
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Sam Stephenson
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+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.
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the sprockets plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the sprockets plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Sprockets'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
7 config/sprockets.yml
@@ -0,0 +1,7 @@
+:load_path:
+ - app/javascripts
+ - vendor/sprockets/*/src
+ - vendor/plugins/*/javascripts
+:source_files:
+ - app/javascripts/application.js
+ - app/javascripts/**/*.js
7 init.rb
@@ -0,0 +1,7 @@
+require "sprockets"
+require "sprockets_helper"
+require "sprockets_application"
+
+class ActionController::Base
+ helper :sprockets
+end
4 install.rb
@@ -0,0 +1,4 @@
+require "fileutils"
+
+FileUtils.cp File.join(File.dirname(__FILE__), "config", "sprockets.yml"),
+ File.join(File.dirname(__FILE__), "..", "..", "..", "config")
37 lib/sprockets_application.rb
@@ -0,0 +1,37 @@
+module SprocketsApplication
+ class << self
+ def routes(map)
+ map.resource(:sprockets)
+ end
+
+ def source
+ preprocessor_for(configuration).output_file.to_s
+ end
+
+ def preprocessor_for(configruation)
+ environment = environment_for(configuration)
+ returning Sprockets::Preprocessor.new(environment) do |preprocessor|
+ expand_paths(configuration[:source_files]).each do |filename|
+ if pathname = environment.find(filename)
+ preprocessor.require(pathname.source_file)
+ else
+ raise Sprockets::LoadError, "no such file `#{filename}'"
+ end
+ end
+ end
+ end
+
+ def environment_for(configuration)
+ Sprockets::Environment.new(RAILS_ROOT, expand_paths(configuration[:load_path]))
+ end
+
+ protected
+ def configuration
+ YAML.load(IO.read(File.join(RAILS_ROOT, "config", "sprockets.yml"))) || {}
+ end
+
+ def expand_paths(paths)
+ paths.map { |path| Dir[path] }.flatten.compact
+ end
+ end
+end
7 lib/sprockets_controller.rb
@@ -0,0 +1,7 @@
+class SprocketsController < ActionController::Base
+ caches_page :show
+
+ def show
+ render :text => SprocketsApplication.source, :content_type => "text/javascript"
+ end
+end
5 lib/sprockets_helper.rb
@@ -0,0 +1,5 @@
+module SprocketsHelper
+ def sprockets_include_tag
+ content_tag(:script, "", :src => formatted_sprockets_path(:format => :js), :type => "text/javascript")
+ end
+end
4 tasks/sprockets_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :sprockets do
+# # Task goes here
+# end
8 test/sprockets_test.rb
@@ -0,0 +1,8 @@
+require 'test/unit'
+
+class SprocketsTest < Test::Unit::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.