Class: Guard::ConcatFilter
Constant Summary collapse
- VERSION =
'0.0.6'
Instance Method Summary collapse
-
#concat ⇒ Object
The actual concat method.
-
#initialize(watchers = [], opts = {}) ⇒ ConcatFilter
constructor
A new instance of ConcatFilter.
- #input_dir ⇒ Object
- #run_on_changes(paths) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(watchers = [], opts = {}) ⇒ ConcatFilter
Returns a new instance of ConcatFilter.
10 11 12 13 14 15 16 17 18 |
# File 'lib/guard/concatfilter.rb', line 10 def initialize(watchers=[], opts={}) @output = "#{opts[:output]}.#{opts[:type]}" files = opts[:files].join("|") regex = %r{^#{opts[:input_dir]}/(#{files})\.#{opts[:type]}$} watcher = ::Guard::Watcher.new regex watchers << watcher @watchers, @opts = watchers, opts super watchers, opts end |
Instance Method Details
#concat ⇒ Object
The actual concat method
scans the :files passed as options supports * and expands them requiring all files in that path/folder
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/guard/concatfilter.rb', line 29 def concat content = "" files = [] @opts[:files].each do |file| files += if single? file ["#{@opts[:input_dir]}/#{file}.#{@opts[:type]}"] else file end end files.each do |file| content << File.read(file) content << "\n" end if @opts[:outputs] @opts[:outputs].each do |name| output = "#{name}.#{@opts[:type]}" local = content local = @opts[:filter].call(output, local) if @opts[:filter] File.open(output, "w"){ |f| f.write local.strip } UI.info "Concatenated #{output}" end else content = @opts[:filter].call(@output, content) if @opts[:filter] File.open(@output, "w"){ |f| f.write content.strip } UI.info "Concatenated #{@output}" end end |
#input_dir ⇒ Object
59 60 61 |
# File 'lib/guard/concatfilter.rb', line 59 def input_dir @opts[:input_dir] end |
#run_on_changes(paths) ⇒ Object
20 21 22 |
# File 'lib/guard/concatfilter.rb', line 20 def run_on_changes(paths) concat end |
#type ⇒ Object
63 64 65 |
# File 'lib/guard/concatfilter.rb', line 63 def type @opts[:type] end |