class Fangorn::Js

Constants

CACHE_BREAK

Public Class Methods

new(input) click to toggle source
Calls superclass method
# File lib/fangorn/js.rb, line 11
def initialize(input)
  output = Output::dist? ? application_js : File.join(Output::dest, input.sub(File.join(Output::source, ''), ''))
  super input, output
end

Protected Instance Methods

application_js() click to toggle source
# File lib/fangorn/js.rb, line 40
def application_js
  File.join Output::dest, 'js', 'application.js'
end
create_command() click to toggle source
# File lib/fangorn/js.rb, line 17
def create_command
  remove! unless @@cleaned
  @@cleaned = true

  File.open(@output, Output::dist? ? 'a' : 'w') do |f|
    f.puts "// #{@input}" if Output::dist?

    contents = File.read(@input) 
    if config = get_config
      config.each do |key,val|
        contents.gsub!("${#{key}}", val.to_s)
      end
    end
    contents.gsub!(/(templateUrl:\s*["'])([^'"]+)(['"])/, "\\1\\2?q=#{CACHE_BREAK}\\3")

    if Output::dist?
      f.puts Uglifier.compile(contents)
    else
      f.write contents
    end

  end
end