lib/minjs/minjs_compressor.rb in minjs-0.1.3 vs lib/minjs/minjs_compressor.rb in minjs-0.1.5
- old
+ new
@@ -1,25 +1,28 @@
require 'tilt'
+require 'logger'
module Minjs
class MinjsCompressor < Tilt::Template
- DEBUG = false
+ attr_reader :logger
def self.engine_initialized?
defined?(::Minjs)
end
def initialize_engine
end
def prepare
+ @logger = Logger.new(STDERR)
+ @logger.level = Logger::WARN
end
def evaluate(context, locals, &block)
case context.content_type
when 'application/javascript'
- if DEBUG
+ if logger.debug?
@@c = 0 unless defined?(@@c)
puts "start: compressing"
file = "tmp#{@@c}.js"
output = "tmp#{@@c}.js.min"
@@c += 1
@@ -27,11 +30,12 @@
puts "output: #{output}"
tmp = open(file, "w")
tmp.write(data)
tmp.close
end
- t = Minjs::Compressor.new.compress(data)
- if DEBUG
+ #TODO
+ t = Minjs::Compressor.new(:logger => logger).compress(data)
+ if logger.debug?
tmp = open(output, "w")
tmp.write(t)
tmp.close
end
t