Class: Minjs::MinjsCompressor

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/minjs/minjs_compressor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/minjs/minjs_compressor.rb', line 6

def logger
  @logger
end

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/minjs/minjs_compressor.rb', line 8

def self.engine_initialized?
  defined?(::Minjs)
end

Instance Method Details

#evaluate(context, locals, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/minjs/minjs_compressor.rb', line 20

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

#initialize_engineObject



12
13
# File 'lib/minjs/minjs_compressor.rb', line 12

def initialize_engine
end

#prepareObject



15
16
17
18
# File 'lib/minjs/minjs_compressor.rb', line 15

def prepare
  @logger = Logger.new(STDERR)
  @logger.level = Logger::WARN
end