Sha256: 2ac3f1db805431aacc3cdc404f65c11a0558347e04b67bf9e8f68ba49324d813

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'tilt'
require 'logger'

module Minjs
  class MinjsCompressor < Tilt::Template
    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 logger.info?
          @@c = 0 unless defined?(@@c)
          puts "start: compressing"
          file = "tmp#{@@c}.js"
          output = "tmp#{@@c}.js.min"
          @@c += 1
          puts "source: #{file}"
          puts "output: #{output}"
          tmp = open(file, "w")
          tmp.write(data)
          tmp.close
        end
        #TODO
        t = Minjs::Compressor.new(:logger => logger).compress(data).to_js
        if logger.info?
          tmp = open(output, "w")
          tmp.write(t)
          tmp.close
        end
        t
      else
        data
      end
    end
  end

end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
minjs-0.3.0 lib/minjs/minjs_compressor.rb
minjs-0.2.2 lib/minjs/minjs_compressor.rb
minjs-0.2.1 lib/minjs/minjs_compressor.rb
minjs-0.2.0 lib/minjs/minjs_compressor.rb