transmogrify 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/Rakefile +7 -0
  2. data/lib/transmogrify.rb +80 -0
  3. metadata +78 -0
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "rake/testtask"
2
+
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.warning = true
7
+ end
@@ -0,0 +1,80 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'coffee-script'
4
+ module Transmogrify
5
+ class TransmogrifyError < ::StandardError;
6
+ attr_accessor :inner
7
+ attr_accessor :processor
8
+
9
+ def initialize(msg, options = {})
10
+ self.inner = options[:inner]
11
+ self.processor = options[:processor]
12
+ super(msg)
13
+ end
14
+ end
15
+ class << self
16
+ def endpoint
17
+ @endpoint ||= nil
18
+ end
19
+ def endpoint=(v)
20
+ @endpoint = v
21
+ end
22
+
23
+ def default_processors
24
+ @default_processors ||= ['coffee','uglify']
25
+ end
26
+
27
+ def default_processors=(v)
28
+ @default_processors = v
29
+ end
30
+
31
+ def post(src, options = {})
32
+ processors = options[:processors] || default_processors
33
+ if processors.is_a?(Array)
34
+ processors = processors.join(',')
35
+ end
36
+
37
+ e = options[:endpoint] || endpoint
38
+
39
+ res = Net::HTTP.post_form(URI.parse(e + '?' + processors), {'data' => src})
40
+ begin
41
+ output = JSON.parse(res.body)
42
+ rescue
43
+ raise TransmogrifyError.new "Could not decode Transmogrify response", :inner => $!
44
+ end
45
+ if res.code.to_s == '200'
46
+ output
47
+ else
48
+ raise TransmogrifyError.new output['message'], :processor => output['processor']
49
+ end
50
+ end
51
+
52
+ def uglify(script)
53
+ post(script, :processors => 'uglify')[:output]
54
+ end
55
+
56
+ def install_coffeescript!
57
+ CoffeeScript.engine = CoffeeScript::Engines::Transmogrify
58
+ end
59
+ end
60
+ end
61
+ module CoffeeScript
62
+ module Engines
63
+ module Transmogrify
64
+ class << self
65
+ def compile(script, options = {})
66
+ begin
67
+ ::Transmogrify.post(script)['output']
68
+ rescue ::Transmogrify::TransmogrifyError => ex
69
+ if ex.inner
70
+ raise EngineError, ex.message
71
+ else
72
+ raise CompilationError, ex.message
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ CoffeeScript.engine ||= Transmogrify
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transmogrify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Kurt Mackey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-25 00:00:00 +00:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: coffee-script
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.1.1
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.5.1
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: The transmogrify gem is a thin Ruby wrapper around a Node.js based webservice that compiles CoffeeScript and uglifies Javascript. It also provides an engine for the ruby-coffee-script gem so you can use it on Heroku.
39
+ email: mrkurt@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - Rakefile
48
+ - lib/transmogrify.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/mrkurt/transmogrify/
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.5.2
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: A ruby consumer for the transmogrify Node.js service
77
+ test_files: []
78
+