Module: StaticWatcher
- Defined in:
- lib/static_watcher.rb,
lib/static_watcher/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
- .compile_coffeescript(b, r) ⇒ Object
- .compile_haml(b, r) ⇒ Object
- .compile_sass(b, r) ⇒ Object
- .install ⇒ Object
- .watch ⇒ Object
Class Method Details
.compile_coffeescript(b, r) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/static_watcher.rb', line 93 def self.compile_coffeescript(b,r) file = "#{b}/#{r}" puts "Compiling #{file} ..." begin %x[ coffee -o #{PATH + '/public/javascripts'} -c #{file} ] puts "done!" rescue puts "Error in Coffeescript Compilation" end end |
.compile_haml(b, r) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/static_watcher.rb', line 54 def self.compile_haml(b,r) file = "#{b}/#{r}" puts "Compiling #{file} ... " content = File.new(file).read begin engine = ::Haml::Engine.new(content) output = engine.render rescue StandardError => error puts "Error in HAML compilation of #{r}" end output_filename = r.gsub('.haml', '') output_file = PATH + "/public/#{output_filename}.html" FileUtils.mkdir_p File.dirname(output_file) File.open(output_file, 'w') { |f| f.write(output) } puts "done!" end |
.compile_sass(b, r) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/static_watcher.rb', line 71 def self.compile_sass(b,r) file = "#{b}/#{r}" output_split = r.split('.') output_filename = output_split[0] filetype = output_split[1] if filetype == "scss" = {:syntax => :scss} end puts "Compiling #{file} ... " content = File.new(file).read begin engine = ::Sass::Engine.new(content, ( || {})) output = engine.render rescue StandardError => error puts "Error in SASS compilation of #{r}" end output_file = PATH + "/public/stylesheets/#{output_filename}.css" FileUtils.mkdir_p File.dirname(output_file) File.open(output_file, 'w') { |f| f.write(output) } puts "done!" end |
.install ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/static_watcher.rb', line 10 def self.install puts "Creating directory structure..." folders = ['/public', '/public/stylesheets', '/public/javascripts', '/src', '/src/haml', '/src/sass', '/src/coffeescripts'] folders.each do |folder| if FileTest::directory?(PATH + folder) puts "Folder #{PATH + folder} already exists!" else puts "Creating folder #{PATH + folder}" Dir::mkdir(PATH + folder) end end puts "Complete!" end |
.watch ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/static_watcher.rb', line 24 def self.watch puts "watching for changes" FSSM.monitor do path PATH + '/src/haml' do glob '**/*.haml' update { |b, r| StaticWatcher::compile_haml(b,r) } delete { |b, r| puts "HAML Delete in #{b} to #{r}" } create { |b, r| StaticWatcher::compile_haml(b,r) } end path PATH + '/src/sass' do glob '**/*' update { |b, r| StaticWatcher::compile_sass(b,r) } delete { |b, r| puts "SASS Delete in #{b} to #{r}" } create { |b, r| StaticWatcher::compile_sass(b,r) } end path PATH + '/src/coffeescripts' do glob '**/*.coffee' update { |b, r| StaticWatcher::compile_coffeescript(b,r) } delete { |b, r| puts "Coffeescript Delete in #{b} to #{r}" } create { |b, r| StaticWatcher::compile_coffeescript(b,r) } end end end |