Class: EmacsOrgProtocolServer::Uglify

Inherits:
Object
  • Object
show all
Defined in:
lib/emacs_org_protocol_server/uglify.rb

Constant Summary collapse

DEFAULTS =
{
  output: {
    preamble: 'javascript:'
  },
  mangle: {
    toplevel: true
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output = nil, options = nil) ⇒ Uglify

Returns a new instance of Uglify.



16
17
18
19
20
# File 'lib/emacs_org_protocol_server/uglify.rb', line 16

def initialize(input, output=nil, options=nil)
  self.input = input
  self.output = output
  self.options = DEFAULTS.merge(options || {})
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



14
15
16
# File 'lib/emacs_org_protocol_server/uglify.rb', line 14

def input
  @input
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/emacs_org_protocol_server/uglify.rb', line 14

def options
  @options
end

#outputObject

Returns the value of attribute output.



14
15
16
# File 'lib/emacs_org_protocol_server/uglify.rb', line 14

def output
  @output
end

Instance Method Details

#run!Object



23
24
25
26
27
28
29
30
31
# File 'lib/emacs_org_protocol_server/uglify.rb', line 23

def run!
  ugli = Uglifier.new(options).compile(File.read(input))
  ugli.gsub!(/\n/,'')
  if output
    File.write(output, ugli)
  else
    ugli
  end
end