Class: Guard::Sprockets
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Sprockets
- Defined in:
- lib/guard/sprockets.rb
Instance Attribute Summary collapse
-
#asset_paths ⇒ Object
readonly
Returns the value of attribute asset_paths.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#root_file ⇒ Object
readonly
Returns the value of attribute root_file.
-
#sprockets ⇒ Object
readonly
Returns the value of attribute sprockets.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Sprockets
constructor
A new instance of Sprockets.
- #run_all ⇒ Object
- #run_on_changes(paths) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Sprockets
Returns a new instance of Sprockets.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/guard/sprockets.rb', line 12 def initialize( = {}) super @options = @asset_paths = Array(@options[:asset_paths] || 'app/assets/javascripts') @destination = @options[:destination] || 'public/javascripts' @root_file = Array(@options[:root_file]) @keep_paths = @options[:keep_paths] || false @sprockets = ::Sprockets::Environment.new @asset_paths.each { |p| @sprockets.append_path(p) } @root_file.each { |f| @sprockets.append_path(Pathname.new(f).dirname) } if @options.delete(:minify) begin require 'uglifier' @sprockets.js_compressor = ::Uglifier.new UI.info 'Sprockets will compress JavaScript output.' rescue LoadError => ex UI.error "minify: Uglifier cannot be loaded. No JavaScript compression will be used.\nPlease include 'uglifier' in your Gemfile." UI.debug ex. end end if @options.delete(:css_minify) begin require 'yui/compressor' @sprockets.css_compressor = YUI::CssCompressor.new UI.info 'Sprockets will compress CSS output.' rescue LoadError => ex UI.error "minify: yui-compressor cannot be loaded. No CSS compression will be used.\nPlease include 'yui-compressor' in your Gemfile." UI.debug ex. end end end |
Instance Attribute Details
#asset_paths ⇒ Object (readonly)
Returns the value of attribute asset_paths.
10 11 12 |
# File 'lib/guard/sprockets.rb', line 10 def asset_paths @asset_paths end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
10 11 12 |
# File 'lib/guard/sprockets.rb', line 10 def destination @destination end |
#root_file ⇒ Object (readonly)
Returns the value of attribute root_file.
10 11 12 |
# File 'lib/guard/sprockets.rb', line 10 def root_file @root_file end |
#sprockets ⇒ Object (readonly)
Returns the value of attribute sprockets.
10 11 12 |
# File 'lib/guard/sprockets.rb', line 10 def sprockets @sprockets end |
Instance Method Details
#run_all ⇒ Object
57 58 59 |
# File 'lib/guard/sprockets.rb', line 57 def run_all run_on_changes([]) end |
#run_on_changes(paths) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/guard/sprockets.rb', line 61 def run_on_changes(paths) paths = @root_file unless @root_file.empty? success = true paths.each do |file| success &= sprocketize(file) end success end |
#start ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/guard/sprockets.rb', line 49 def start UI.info 'Guard::Sprockets is ready and waiting for some file changes...' UI.debug "Guard::Sprockets.asset_paths = #{@asset_paths.inspect}" unless @asset_paths.empty? UI.debug "Guard::Sprockets.destination = #{@destination.inspect}" run_all end |