lib/barista/compiler.rb in barista-0.2.1 vs lib/barista/compiler.rb in barista-0.3.0

- old
+ new

@@ -4,26 +4,23 @@ class Compiler class << self; attr_accessor :bin_path; end self.bin_path ||= "coffee" - def self.compile(content) - new(content).to_js + def self.compile(path) + new(path).to_js end - def initialize(content) + def initialize(path) @compiled = false - @content = content + @path = path end def compile! # Compiler code thanks to bistro_car. - tf = temp_file_for_content - @compiled_content = invoke_coffee(temp_file_for_content.path) + @compiled_content = invoke_coffee(@path) @compiled = true - ensure - tf.unlink rescue nil end def to_js compile! unless @compiled @compiled_content.to_s @@ -39,23 +36,16 @@ ["-p"].tap do |options| options << "--no-wrap" if Barista.no_wrap? end.join(" ") end - def temp_file_for_content(content = @content) - tf = Tempfile.new("barista-#{content_hash}.coffee") - tf.write content - tf.close - tf - end - def invoke_coffee(path) command = "#{self.class.bin_path} #{coffee_options} '#{path}'".squeeze(' ') %x(#{command}) end def content_hash @content_hash ||= Digest::SHA256.hexdigest(@content) end end -end \ No newline at end of file +end