Skip to content
Browse files

Merge pull request #1 from roundlake/master

Root file feature
  • Loading branch information...
2 parents df9ddad + ba75743 commit 11e49084f5b7b67b346d5d7e6254f50f15cf1c82 @pferdefleisch committed
Showing with 46 additions and 30 deletions.
  1. +3 −3 guard-sprockets.gemspec
  2. +40 −23 lib/guard/sprockets.rb
  3. +3 −4 lib/guard/sprockets/version.rb
View
6 guard-sprockets.gemspec
@@ -4,7 +4,7 @@ require 'guard/sprockets/version'
Gem::Specification.new do |s|
s.name = "guard-sprockets"
- s.version = Guard::Sprockets::VERSION
+ s.version = Guard::SprocketsVersion::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Aaron Cruz", 'Kematzy']
s.email = ["aaron@aaroncruz.com", "kematzy at gmail"]
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
s.description = %q{guard file for sprockets}
s.rubyforge_project = "guard-sprockets"
-
+
s.add_dependency 'guard', '>= 0.2.2'
s.add_dependency "sprockets", '~> 2'
-
+
s.files = Dir.glob('{lib}/**/*') #+ %w[LICENSE README.rdoc]
s.require_path = 'lib'
end
View
63 lib/guard/sprockets.rb
@@ -1,62 +1,79 @@
require 'guard'
require 'guard/guard'
-require 'erb'
require 'sprockets'
+require 'execjs'
module Guard
class Sprockets < Guard
def initialize(watchers=[], options={})
- super
-
- # init Sprocket env for use later
- @sprockets_env = ::Sprockets::Environment.new
-
+ super
+
+ @sprockets = ::Sprockets::Environment.new
+
@asset_paths = options.delete(:asset_paths) || []
- # add the asset_paths to the Sprockets env
@asset_paths.each do |p|
- @sprockets_env.append_path p
+ @sprockets.append_path p
end
- # store the output destination
+
@destination = options.delete(:destination)
+ @root_file = options.delete(:root_file)
+
@opts = options
end
def start
- UI.info "Sprockets activated..."
- UI.info " -- external asset paths = [#{@asset_paths.inspect}]" unless @asset_paths.empty?
- UI.info " -- destination path = [#{@destination.inspect}]"
- UI.info "Sprockets is ready and waiting for some file changes..."
+ UI.info "Sprockets activated."
+ UI.info " - external asset paths = #{@asset_paths.inspect}" unless @asset_paths.empty?
+ UI.info " - destination path = #{@destination.inspect}"
+ UI.info "Sprockets guard is ready and waiting for some file changes..."
+
+ run_all
end
-
+
def run_all
+ run_on_change([ @root_file ]) if @root_file
+
true
end
def run_on_change(paths)
- paths.each{ |js| sprocketize(js) }
+ if @root_file
+ sprocketize(@root_file)
+ else
+ paths.each do |file|
+ sprocketize(file)
+ end
+ end
+
true
end
-
+
private
-
+
def sprocketize(path)
changed = Pathname.new(path)
- @sprockets_env.append_path changed.dirname
+ @sprockets.append_path changed.dirname
output_basename = changed.basename.to_s
- if match = output_basename.match(/^(.*\.(?:js|css))\.[^.]+$/)
- output_basename = match[1]
- end
+ output_basename.gsub!(/^(.*\.(?:js|css))\.[^.]+$/, '\1')
output_file = Pathname.new(File.join(@destination, output_basename))
- UI.info "Sprockets started compiling #{output_file}"
+
+ UI.info "Sprockets: compiling #{output_file}"
+
FileUtils.mkdir_p(output_file.parent) unless output_file.parent.exist?
output_file.open('w') do |f|
- f.write @sprockets_env[output_basename]
+ f.write @sprockets[output_basename]
end
+
UI.info "Sprockets finished compiling #{output_file}"
+ Notifier.notify "Compiled #{output_basename}"
+ rescue ExecJS::ProgramError => e
+ UI.error "Sprockets failed to compile #{output_file}"
+ UI.error e.message
+ Notifier.notify "Syntax error in #{output_basename}: #{e.message}", :priority => 2, :image => :failed
end
end
end
View
7 lib/guard/sprockets/version.rb
@@ -1,6 +1,5 @@
-# encoding: utf-8
module Guard
- module Sprockets
- VERSION = '0.2.0'
+ module SprocketsVersion
+ VERSION = "0.2.0"
end
-end
+end

0 comments on commit 11e4908

Please sign in to comment.
Something went wrong with that request. Please try again.