typescript-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in typescript-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Klaus Zanders
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # TypeScript for Rails
2
+
3
+ This is a wrapper for the [TypeScript](http://www.typescriptlang.org/) JavaScript superset language by Microsoft.
4
+
5
+ It enables you to use the `.ts` extension in the Asset Pipeline and also in ActionView Templates.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'typescript-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Just add a `.js.ts` file in your `app/assets/javascripts` directory and include it just like you are used to do.
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ <%= TypeScript::Source.contents %>
@@ -0,0 +1,10 @@
1
+ require 'rails/engine'
2
+
3
+ module Typescript
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ # For now, let's not be the default generator ...
7
+ # config.app_generators.javascript_engine :ts
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Typescript
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ config.before_initialize do |app|
5
+ require 'typescript-rails'
6
+
7
+ if app.config.assets.enabled
8
+ require 'sprockets'
9
+ require 'sprockets/engines'
10
+ Sprockets.register_engine '.ts', Typescript::Rails::TypeScriptTemplate
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,68 @@
1
+ require 'tilt'
2
+
3
+ module Typescript
4
+ module Rails
5
+
6
+ class TypeScriptTemplate < ::Tilt::Template
7
+ self.default_mime_type = 'application/javascript'
8
+
9
+ @@default_bare = false
10
+
11
+ def self.default_bare
12
+ @@default_bare
13
+ end
14
+
15
+ def self.default_bare=(value)
16
+ @@default_bare = value
17
+ end
18
+
19
+ # DEPRECATED
20
+ def self.default_no_wrap
21
+ @@default_bare
22
+ end
23
+
24
+ # DEPRECATED
25
+ def self.default_no_wrap=(value)
26
+ @@default_bare = value
27
+ end
28
+
29
+ def self.engine_initialized?
30
+ defined? ::TypeScript
31
+ end
32
+
33
+ def initialize_engine
34
+ require_template_library 'coffee_script'
35
+ end
36
+
37
+ def prepare
38
+ if !options.key?(:bare) and !options.key?(:no_wrap)
39
+ options[:bare] = self.class.default_bare
40
+ end
41
+ end
42
+
43
+ def evaluate(scope, locals, &block)
44
+ @output ||= TypeScript.compile(data, options)
45
+ end
46
+
47
+ def allows_script?
48
+ false
49
+ end
50
+ end
51
+
52
+ class TemplateHandler
53
+
54
+ def self.erb_handler
55
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
56
+ end
57
+
58
+ def self.call(template)
59
+ compiled_source = erb_handler.call(template)
60
+ "TypeScript.compile(begin;#{compiled_source};end)"
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ ActiveSupport.on_load(:action_view) do
67
+ ActionView::Template.register_template_handler :ts, Typescript::Rails::TemplateHandler
68
+ end
@@ -0,0 +1,5 @@
1
+ module Typescript
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require "typescript"
2
+ require "typescript/rails/railtie"
3
+ require "typescript/rails/engine"
4
+ require "typescript/rails/template_handler"
5
+ require "typescript/rails/version"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'typescript/rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "typescript-rails"
8
+ gem.version = Typescript::Rails::VERSION
9
+ gem.authors = ["Klaus Zanders"]
10
+ gem.email = ["klaus.zanders@gmail.com"]
11
+ gem.description = %q{Adds Typescript to the Rails Asset pipeline}
12
+ gem.summary = %q{Adds Typescript to the Rails Asset pipeline}
13
+ gem.homepage = ""
14
+
15
+ gem.add_runtime_dependency 'typescript'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typescript-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Klaus Zanders
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typescript
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Adds Typescript to the Rails Asset pipeline
31
+ email:
32
+ - klaus.zanders@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/assets/javascripts/typescript.js.erb
43
+ - lib/typescript-rails.rb
44
+ - lib/typescript/rails/engine.rb
45
+ - lib/typescript/rails/railtie.rb
46
+ - lib/typescript/rails/template_handler.rb
47
+ - lib/typescript/rails/version.rb
48
+ - typescript-rails.gemspec
49
+ homepage: ''
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ segments:
62
+ - 0
63
+ hash: -2708116633053488
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ segments:
71
+ - 0
72
+ hash: -2708116633053488
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.23
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Adds Typescript to the Rails Asset pipeline
79
+ test_files: []