Sha256: 2a4feefb41a5c20038ee8ae27aa7a911936543582091b5b1765bbe9d0f1614d3

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 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::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

3 entries across 3 versions & 1 rubygems

Version Path
minjs-0.4.2 lib/minjs/minjs_compressor.rb
minjs-0.4.1 lib/minjs/minjs_compressor.rb
minjs-0.4.0 lib/minjs/minjs_compressor.rb