Sha256: 7b2400076b088dfdd6ef53e5c122875550bc882b6eeaa97b523200995529ca0f

Contents?: true

Size: 793 Bytes

Versions: 3

Compression:

Stored size: 793 Bytes

Contents

# encoding: UTF-8

module Bunch
  class JsMinifier
    def initialize(tree)
      require "uglifier"
      @input  = tree
      @output = FileTree.new
      @uglifier = Uglifier.new
    rescue LoadError => e
      raise "'gem install uglifier' to minify JavaScript files."
    end

    def result
      @path = []
      @input.accept(self)
      @output
    end

    def enter_tree(tree)
      @path << tree.name if tree.name
    end

    def leave_tree(tree)
      @path.pop if tree.name
    end

    def visit_file(file)
      file_path = [*@path, file.path].join("/")
      content = if file.extension == ".js"
                  @uglifier.compile(file.content)
                else
                  file.content
                end
      @output.write file_path, content
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bunch-1.0.0pre3 lib/bunch/js_minifier.rb
bunch-1.0.0pre2 lib/bunch/js_minifier.rb
bunch-1.0.0pre1 lib/bunch/js_minifier.rb