Module: Transmogrify

Defined in:
lib/transmogrify.rb

Defined Under Namespace

Classes: TransmogrifyError

Class Method Summary collapse

Class Method Details

.default_processorsObject



23
24
25
# File 'lib/transmogrify.rb', line 23

def default_processors
  @default_processors ||= ['coffee','uglify']
end

.default_processors=(v) ⇒ Object



27
28
29
# File 'lib/transmogrify.rb', line 27

def default_processors=(v)
  @default_processors = v
end

.endpointObject



16
17
18
# File 'lib/transmogrify.rb', line 16

def endpoint
  @endpoint ||= 'http://transmogrify.no.de/compile'
end

.endpoint=(v) ⇒ Object



19
20
21
# File 'lib/transmogrify.rb', line 19

def endpoint=(v)
  @endpoint = v
end

.install_coffeescript!Object



56
57
58
# File 'lib/transmogrify.rb', line 56

def install_coffeescript!
  CoffeeScript.engine = CoffeeScript::Engines::Transmogrify
end

.post(src, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/transmogrify.rb', line 31

def post(src, options = {})
  processors = options[:processors] || default_processors
  if processors.is_a?(Array)
    processors = processors.join(',')
  end

  e = options[:endpoint] || endpoint

  res = Net::HTTP.post_form(URI.parse(e + '?' + processors), {'data' => src})
  begin
    output = JSON.parse(res.body)
  rescue
    raise TransmogrifyError.new "Could not decode Transmogrify response", :inner => $!
  end
  if res.code.to_s == '200'
    output
  else
    raise TransmogrifyError.new output['message'], :processor => output['processor']
  end
end

.uglify(script) ⇒ Object



52
53
54
# File 'lib/transmogrify.rb', line 52

def uglify(script)
  post(script, :processors => 'uglify')[:output]
end