typescript-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/lib/assets/javascripts/typescript.js.erb +1 -0
- data/lib/typescript/rails/engine.rb +10 -0
- data/lib/typescript/rails/railtie.rb +15 -0
- data/lib/typescript/rails/template_handler.rb +68 -0
- data/lib/typescript/rails/version.rb +5 -0
- data/lib/typescript-rails.rb +5 -0
- data/typescript-rails.gemspec +21 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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,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,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: []
|