Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-organizing and cleaning up things to prepare for a working compass…
… extension instead of the Rakefile.
- Loading branch information
Showing
20 changed files
with
171 additions
and
158 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "compass/sprockets/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "compass-sprockets" | ||
s.version = Compass::Sprockets::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Grady Kuhnline"] | ||
s.email = ["heygrady@gmail.com"] | ||
s.homepage = "http://rubygems.org/gems/compass-sprockets" | ||
s.summary = %q{ Compass extension for Sprockets } | ||
s.description = %q{ An integration of Sprockets with Compass for auto-compiling JavaScript assets } | ||
|
||
s.rubyforge_project = "compass-sprockets" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
s.add_dependency("compass") | ||
s.add_dependency("sprockets") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "sprockets" | ||
require "sprockets/compressors" | ||
require "sprockets/static_compiler" | ||
require "compass/sprockets" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "compass/sprockets/version" | ||
|
||
module Compass | ||
module Sprockets | ||
# register the framework | ||
Compass::Frameworks.register("sprockets", :path => "#{File.dirname(__FILE__)}/..") | ||
|
||
# register the custom config variables | ||
Compass::Configuration.add_configuration_property(:javascripts_src_dir, "Location of JavaScript source files for use with Sprockets") do | ||
"javascripts/src" | ||
end | ||
|
||
# register a custom watch | ||
Compass::Configuration::Data.watch Compass.configuration.javascripts_src_dir + "/**/*" do |project_dir, relative_path| | ||
if File.exists?(File.join(project_dir, relative_path)) | ||
# configure environment | ||
environment = Sprockets::Environment.new(project_dir) | ||
environment.append_path(Compass.configuration.javascripts_src_dir) #Compass.configuration.javascripts_dir + "/src" | ||
environment.js_compressor = Sprockets::LazyCompressor.new { Sprockets::Compressors.registered_js_compressor(:uglifier) } | ||
|
||
# configure the static compiler | ||
compiler = Sprockets::StaticCompiler.new( | ||
environment, | ||
Compass.configuration.javascripts_dir, | ||
[/^([\w-]+\/)?[^_]\w+\.(js|coffee)$/], | ||
:manifest_path => Compass.configuration.javascripts_dir, | ||
:digest => false, | ||
:manifest => false, | ||
:zip_files => /a^/ | ||
) | ||
compiler.compile | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Compass | ||
module Sprockets | ||
VERSION = "0.0.0" | ||
#HTML5_BOILERPLATE_VERSION = "3.0.2" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
module Sprockets | ||
module Compressors | ||
extend self | ||
|
||
@@css_compressors = {} | ||
@@js_compressors = {} | ||
@@default_css_compressor = nil | ||
@@default_js_compressor = nil | ||
|
||
def register_css_compressor(name, klass, options = {}) | ||
@@default_css_compressor = name.to_sym if options[:default] || @@default_css_compressor.nil? | ||
@@css_compressors[name.to_sym] = { :klass => klass.to_s, :require => options[:require] } | ||
end | ||
|
||
def register_js_compressor(name, klass, options = {}) | ||
@@default_js_compressor = name.to_sym if options[:default] || @@default_js_compressor.nil? | ||
@@js_compressors[name.to_sym] = { :klass => klass.to_s, :require => options[:require] } | ||
end | ||
|
||
def registered_css_compressor(name) | ||
find_registered_compressor name, @@css_compressors, @@default_css_compressor | ||
end | ||
|
||
def registered_js_compressor(name) | ||
find_registered_compressor name, @@js_compressors, @@default_js_compressor | ||
end | ||
|
||
# The default compressors must be registered in default plugins (ex. Sass-Rails) | ||
register_css_compressor(:scss, 'Sass::Rails::Compressor', :require => 'sass/rails/compressor', :default => true) | ||
register_js_compressor(:uglifier, 'Uglifier', :require => 'uglifier', :default => true) | ||
|
||
# Automaticaly register some compressors | ||
register_css_compressor(:yui, 'YUI::CssCompressor', :require => 'yui/compressor') | ||
register_js_compressor(:closure, 'Closure::Compiler', :require => 'closure-compiler') | ||
register_js_compressor(:yui, 'YUI::JavaScriptCompressor', :require => 'yui/compressor') | ||
|
||
private | ||
|
||
def find_registered_compressor(name, compressors_hash, default_compressor_name) | ||
if name.respond_to?(:to_sym) | ||
compressor = compressors_hash[name.to_sym] || compressors_hash[default_compressor_name] | ||
require compressor[:require] if compressor[:require] | ||
constantize(compressor[:klass]).new | ||
else | ||
name | ||
end | ||
end | ||
|
||
def constantize(camel_cased_word) | ||
names = camel_cased_word.split('::') | ||
names.shift if names.empty? || names.first.empty? | ||
|
||
constant = Object | ||
names.each do |name| | ||
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) | ||
end | ||
constant | ||
end | ||
end | ||
|
||
# An asset compressor which does nothing. | ||
# | ||
# This compressor simply returns the asset as-is, without any compression | ||
# whatsoever. It is useful in development mode, when compression isn't | ||
# needed but using the same asset pipeline as production is desired. | ||
class NullCompressor #:nodoc: | ||
def compress(content) | ||
content | ||
end | ||
end | ||
|
||
# An asset compressor which only initializes the underlying compression | ||
# engine when needed. | ||
# | ||
# This postpones the initialization of the compressor until | ||
# <code>#compress</code> is called the first time. | ||
class LazyCompressor #:nodoc: | ||
# Initializes a new LazyCompressor. | ||
# | ||
# The block should return a compressor when called, i.e. an object | ||
# which responds to <code>#compress</code>. | ||
def initialize(&block) | ||
@block = block | ||
end | ||
|
||
def compress(content) | ||
compressor.compress(content) | ||
end | ||
|
||
private | ||
|
||
def compressor | ||
@compressor ||= (@block.call || NullCompressor.new) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.