Module: CoffeeProcessing
- Defined in:
- lib/coffee-processing.rb,
lib/coffee-processing/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
- .compile(javascript_object, code) ⇒ Object
- .generate_template_page(javascript_object, code, output_dir) ⇒ Object
Class Method Details
.compile(javascript_object, code) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/coffee-processing.rb', line 6 def self.compile javascript_object, code first_line = code.lines.map(&:chomp).find { |line| !line.empty? } if first_line && indentation = first_line.scan(/^\s+/).first code = code.lines.map { |line| line.sub(/^#{indentation}/, '')}.join end code = code.lines.map { |line| "#{line} " }.join code = code.strip CoffeeScript.compile( Erubis::Eruby.new( File.read File.join( File.dirname(__FILE__), 'coffee-processing', 'boilerplate.coffee.erb' ) ).result(binding) ) end |
.generate_template_page(javascript_object, code, output_dir) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coffee-processing.rb', line 27 def self.generate_template_page javascript_object, code, output_dir require 'fileutils' FileUtils.mkdir_p output_dir File.open(File.join(output_dir, 'sketch.js'), 'w') do |f| f << compile(javascript_object, code) end File.open(File.join(output_dir, 'index.html'), 'w') do |f| f << Erubis::Eruby.new( File.read File.join( File.dirname(__FILE__), 'coffee-processing', 'template.html.erb' ) ).result(binding) end end |