typescript-rails 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGES.md +7 -0
- data/lib/typescript-rails.rb +2 -0
- data/lib/typescript/rails.rb +5 -0
- data/lib/typescript/rails/compiler.rb +45 -0
- data/lib/typescript/rails/engine.rb +3 -7
- data/lib/typescript/rails/railtie.rb +8 -12
- data/lib/typescript/rails/template.rb +32 -0
- data/lib/typescript/rails/template_handler.rb +11 -92
- data/lib/typescript/rails/version.rb +1 -1
- data/test/assets_test.rb +1 -0
- data/test/support/site/ref3_2.ts +1 -1
- data/test/support/site/ref3_3.ts +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18c02ddb2925e76f99d15526b4d68d12ebce5a3d
|
4
|
+
data.tar.gz: 8f743d5be68031c673151ee590623f64b94377e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fd56936bee817a81102ff8f5353bf7d25ad549eec5e30339b87b3aaf95d1e0cbdf1df1f1b83c7aba0f88dd58f13b77d10e7b2a53f7324c11dcc62d9bdd6e8d7
|
7
|
+
data.tar.gz: 8d8884552159bcce98b011afc344b23bdc1362d0a589baa6f12a5ee127882e2a09e251324234647629bc077bc85e79b8517d0322f7eec6a4e952e7ae532195ed
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v0.4.0 2014-08-11 23:04:20+0900
|
2
|
+
|
3
|
+
* Set `--noImplicitAny` by default to tsc compiler
|
4
|
+
* Typescript::Rails::Compiler.default_options to provide tsc compiler with otpions
|
5
|
+
* default values: `--target ES5 --noImplicitAny`
|
6
|
+
* A lot of refactoring
|
7
|
+
|
1
8
|
## v0.3.0 2014-08-09 10:27:54+0900
|
2
9
|
|
3
10
|
* Compiles TypeScript files in ES5 mode
|
data/lib/typescript-rails.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'typescript/rails'
|
2
|
+
require 'typescript-node'
|
3
|
+
|
4
|
+
module Typescript::Rails::Compiler
|
5
|
+
class << self
|
6
|
+
# @!scope class
|
7
|
+
cattr_accessor :default_options
|
8
|
+
|
9
|
+
# Replace relative paths specified in /// <reference path="..." /> with absolute paths.
|
10
|
+
#
|
11
|
+
# @param [String] ts_path Source .ts path
|
12
|
+
# @param [String] source. It might be pre-processed by erb.
|
13
|
+
# @return [String] replaces source
|
14
|
+
def replace_relative_references(ts_path, source)
|
15
|
+
ts_dir = File.dirname(File.expand_path(ts_path))
|
16
|
+
escaped_dir = ts_dir.gsub(/["\\]/, '\\\\\&') # "\"" => "\\\"", '\\' => '\\\\'
|
17
|
+
|
18
|
+
# Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
|
19
|
+
# So we go the long way around.
|
20
|
+
output = ''
|
21
|
+
source.each_line do |l|
|
22
|
+
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
|
23
|
+
l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
|
24
|
+
end
|
25
|
+
output = output + l + $/
|
26
|
+
end
|
27
|
+
|
28
|
+
output
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [String] ts_path
|
32
|
+
# @param [String] source TypeScript source code
|
33
|
+
# @return [String] compiled JavaScript source code
|
34
|
+
def compile(ts_path, source, *options)
|
35
|
+
s = replace_relative_references(ts_path, source)
|
36
|
+
::TypeScript::Node.compile(s, *default_options, *options)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
self.default_options = [
|
42
|
+
'--target', 'ES5',
|
43
|
+
'--noImplicitAny'
|
44
|
+
]
|
45
|
+
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'rails/engine'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# For now, let's not be the default generator ...
|
7
|
-
# config.app_generators.javascript_engine :ts
|
8
|
-
end
|
9
|
-
end
|
3
|
+
class Typescript::Rails::Engine < Rails::Engine
|
4
|
+
# For now, let's not be the default generator ...
|
5
|
+
# config.app_generators.javascript_engine :ts
|
10
6
|
end
|
@@ -1,15 +1,11 @@
|
|
1
|
-
|
2
|
-
module Rails
|
3
|
-
class Railtie < ::Rails::Railtie
|
4
|
-
config.before_initialize do |app|
|
5
|
-
require 'typescript-rails'
|
1
|
+
require 'typescript/rails'
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
class Typescript::Rails::Railtie < ::Rails::Railtie
|
4
|
+
config.before_initialize do |app|
|
5
|
+
if ::Rails::VERSION::MAJOR >= 4 || app.config.assets.enabled
|
6
|
+
require 'typescript/rails/template'
|
7
|
+
require 'sprockets'
|
8
|
+
Sprockets.register_engine '.ts', Typescript::Rails::Template
|
13
9
|
end
|
14
10
|
end
|
15
|
-
end
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'typescript/rails'
|
2
|
+
require 'tilt/template'
|
3
|
+
|
4
|
+
class Typescript::Rails::Template < ::Tilt::Template
|
5
|
+
self.default_mime_type = 'application/javascript'
|
6
|
+
|
7
|
+
# @!scope class
|
8
|
+
class_attribute :default_bare
|
9
|
+
|
10
|
+
def self.engine_initialized?
|
11
|
+
defined? ::Typescript::Rails::Compiler
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize_engine
|
15
|
+
require_template_library 'typescript/rails/compiler'
|
16
|
+
end
|
17
|
+
|
18
|
+
def prepare
|
19
|
+
if !options.key?(:bare) and !options.key?(:no_wrap)
|
20
|
+
options[:bare] = self.class.default_bare
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def evaluate(scope, locals, &block)
|
25
|
+
@output ||= ::Typescript::Rails::Compiler.compile(file, source)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @override
|
29
|
+
def allows_script?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
@@ -1,98 +1,17 @@
|
|
1
|
-
require 'typescript
|
2
|
-
require 'tilt'
|
1
|
+
require 'typescript/rails/compiler'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
self.default_mime_type = 'application/javascript'
|
9
|
-
|
10
|
-
@@default_bare = false
|
11
|
-
|
12
|
-
def self.default_bare
|
13
|
-
@@default_bare
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.default_bare=(value)
|
17
|
-
@@default_bare = value
|
18
|
-
end
|
19
|
-
|
20
|
-
# @deprecated
|
21
|
-
def self.default_no_wrap
|
22
|
-
@@default_bare
|
23
|
-
end
|
24
|
-
|
25
|
-
# @deprecated
|
26
|
-
def self.default_no_wrap=(value)
|
27
|
-
@@default_bare = value
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.engine_initialized?
|
31
|
-
defined? ::TypeScript
|
32
|
-
end
|
33
|
-
|
34
|
-
def initialize_engine
|
35
|
-
require_template_library 'coffee_script'
|
36
|
-
end
|
37
|
-
|
38
|
-
def prepare
|
39
|
-
if !options.key?(:bare) and !options.key?(:no_wrap)
|
40
|
-
options[:bare] = self.class.default_bare
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def evaluate(scope, locals, &block)
|
45
|
-
source = Typescript::Rails.replace_relative_references(file, data)
|
46
|
-
# TODO: employs source-maps
|
47
|
-
@output ||= TypeScript::Node.compile(source, '--target', 'ES5')
|
48
|
-
end
|
49
|
-
|
50
|
-
def allows_script?
|
51
|
-
false
|
52
|
-
end
|
3
|
+
class Typescript::Rails::TemplateHandler
|
4
|
+
class << self
|
5
|
+
def erb_handler
|
6
|
+
@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
|
53
7
|
end
|
54
8
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def self.call(template)
|
62
|
-
compiled_source = erb_handler.call(template)
|
63
|
-
escaped_path = template.identifier.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
|
64
|
-
<<-EOS
|
65
|
-
TypeScript::Node.compile(
|
66
|
-
Typescript::Rails.replace_relative_references(
|
67
|
-
'#{escaped_path}', (begin;#{compiled_source};end)
|
68
|
-
),
|
69
|
-
'--target', 'ES5'
|
70
|
-
)
|
71
|
-
EOS
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Replace relative paths specified in /// <reference path="..." /> with absolute paths.
|
76
|
-
#
|
77
|
-
# @param [String] ts_path Source .ts path
|
78
|
-
# @param [String] ts source. It might be pre-processed by erb.
|
79
|
-
# @return [String] replaces source
|
80
|
-
def self.replace_relative_references(ts_path, source)
|
81
|
-
ts_dir = File.dirname(File.expand_path(ts_path))
|
82
|
-
escaped_dir = ts_dir.gsub(/["\\]/, '\\\\\&') # "\"" => "\\\"", '\\' => '\\\\'
|
83
|
-
|
84
|
-
# Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
|
85
|
-
# So we go the long way around.
|
86
|
-
output = ''
|
87
|
-
source.each_line do |l|
|
88
|
-
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
|
89
|
-
l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
|
90
|
-
end
|
91
|
-
|
92
|
-
output = output + l + $/
|
93
|
-
end
|
94
|
-
|
95
|
-
output
|
9
|
+
def call(template)
|
10
|
+
compiled_source = erb_handler.call(template)
|
11
|
+
path = template.identifier.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
|
12
|
+
<<-EOS
|
13
|
+
::Typescript::Rails::Compiler.compile('#{path}', (begin;#{compiled_source};end))
|
14
|
+
EOS
|
96
15
|
end
|
97
16
|
end
|
98
17
|
end
|
data/test/assets_test.rb
CHANGED
@@ -9,6 +9,7 @@ class AssetsTest < ActiveSupport::TestCase
|
|
9
9
|
require "sprockets/railtie"
|
10
10
|
|
11
11
|
@app = Class.new(Rails::Application)
|
12
|
+
@app.config.eager_load = false
|
12
13
|
@app.config.active_support.deprecation = :stderr
|
13
14
|
@app.config.assets.enabled = true
|
14
15
|
@app.config.assets.cache_store = [ :file_store, "#{tmp_path}/cache" ]
|
data/test/support/site/ref3_2.ts
CHANGED
data/test/support/site/ref3_3.ts
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typescript-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FUJI, Goro
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typescript-node
|
@@ -70,8 +70,11 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- lib/assets/javascripts/typescript.js.erb
|
72
72
|
- lib/typescript-rails.rb
|
73
|
+
- lib/typescript/rails.rb
|
74
|
+
- lib/typescript/rails/compiler.rb
|
73
75
|
- lib/typescript/rails/engine.rb
|
74
76
|
- lib/typescript/rails/railtie.rb
|
77
|
+
- lib/typescript/rails/template.rb
|
75
78
|
- lib/typescript/rails/template_handler.rb
|
76
79
|
- lib/typescript/rails/version.rb
|
77
80
|
- test/assets_test.rb
|