Class: Guard::Haml2erb
Instance Method Summary collapse
- #compile_haml2erb(file) ⇒ Object
-
#get_output(file) ⇒ String
Get the file path to output the erb based on the file being built.
-
#initialize(watchers = [], options = {}) ⇒ Haml2erb
constructor
Initialize a Guard.
-
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
-
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
-
#run_on_removals(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Haml2erb
Initialize a Guard.
10 11 12 |
# File 'lib/guard/haml2erb.rb', line 10 def initialize(watchers = [], = {}) super end |
Instance Method Details
#compile_haml2erb(file) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/guard/haml2erb.rb', line 64 def compile_haml2erb(file) template = File.read(file) output = ::Haml2Erb.convert(template) rescue StandardError => error ::Guard::UI.error "haml2erb error: " + error. throw :task_has_failed end |
#get_output(file) ⇒ String
Get the file path to output the erb based on the file being built. The output path is relative to where guard is being run.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/guard/haml2erb.rb', line 20 def get_output(file) file_dir = File.dirname(file) file_name = File.basename(file).split('.')[0..-2].join('.') file_name = "#{file_name}.erb" if file_name.match(/\.erb/).nil? file_dir = file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input] file_dir = File.join(@options[:output], file_dir) if @options[:output] if file_dir == '' file_name else File.join(file_dir, file_name) end end |
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
40 41 42 |
# File 'lib/guard/haml2erb.rb', line 40 def run_all run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*')))) end |
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/guard/haml2erb.rb', line 47 def run_on_changes(paths) paths.each do |file| output_file = get_output(file) FileUtils.mkdir_p File.dirname(output_file) File.open(output_file, 'w') { |f| f.write(compile_haml2erb(file)) } ::Guard::UI.info "# compiled haml in '#{file}' to erb in '#{output_file}'" ::Guard::Notifier.notify("# compiled haml to erb in #{file}", :title => "Guard::Haml2erb", :image => :success) if @options[:notifications] end notify paths end |
#run_on_removals(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
61 62 |
# File 'lib/guard/haml2erb.rb', line 61 def run_on_removals(paths) end |