typescript-rails 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/Gemfile +1 -0
- data/README.md +3 -0
- data/lib/typescript/rails/compiler.rb +30 -3
- data/lib/typescript/rails/template.rb +2 -2
- data/lib/typescript/rails/version.rb +1 -1
- data/test/assets_test.rb +1 -0
- data/test/fixtures/assets/javascripts/hello.js.ts +2 -1
- data/test/fixtures/assets/javascripts/included.ts +4 -0
- data/test/fixtures/assets/javascripts/reference.ts +2 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff9a4a7b974ccde9082b7c16c4f9e04dca61e1b6
|
4
|
+
data.tar.gz: d92a70618cf4472c5668263d520457576c88ced6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92e08dbe08a9bb5216bd9a0d8f7fe6b77e7ede6787d88e0724d065eeea717b00b826e4233a810c6de4887161cb5d96c37e2d556e72cb8466a7407e095597d3fd
|
7
|
+
data.tar.gz: e1f9344a67a40b4fc78241f230da8d9ea4dec2a73d2ba4b9610c6e3fd3ae2c8a0b2ffb6371ec9b0028d40b80792689e3a1f18c3467585d340f64b20a0aec4a79
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,9 @@ Configurations:
|
|
43
43
|
Typescript::Rails::Compiler.default_options = [ ... ]
|
44
44
|
```
|
45
45
|
|
46
|
+
## Referenced TypeScript dependencies
|
47
|
+
|
48
|
+
`typescript-rails` recurses through all [TypeScript-style](https://github.com/teppeis/typescript-spec-md/blob/master/en/ch11.md#1111-source-files-dependencies) referenced files and tells its [`Sprockets::Context`](https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/context.rb) that the TS file being processed [`depend`s`_on`](https://github.com/sstephenson/sprockets#the-depend_on-directive) each file listed as a reference. This activates Sprocket’s cache-invalidation behavior when any of the descendant references of the root TS file is changed.
|
46
49
|
|
47
50
|
## Contributing
|
48
51
|
|
@@ -18,8 +18,9 @@ module Typescript::Rails::Compiler
|
|
18
18
|
# Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
|
19
19
|
# So we go the long way around.
|
20
20
|
output = (source.each_line.map do |l|
|
21
|
-
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
|
22
|
-
|
21
|
+
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
|
22
|
+
matched_path = m.captures.compact[0]
|
23
|
+
l = l.sub(matched_path, File.join(escaped_dir, matched_path))
|
23
24
|
end
|
24
25
|
next l
|
25
26
|
end).join
|
@@ -27,10 +28,36 @@ module Typescript::Rails::Compiler
|
|
27
28
|
output
|
28
29
|
end
|
29
30
|
|
31
|
+
# Get all references
|
32
|
+
#
|
33
|
+
# @param [String] path Source .ts path
|
34
|
+
# @param [String] source. It might be pre-processed by erb.
|
35
|
+
# @yieldreturn [String] matched ref abs_path
|
36
|
+
def get_all_reference_paths(path, source, visited_paths=Set.new, &block)
|
37
|
+
visited_paths << path
|
38
|
+
source ||= File.read(path)
|
39
|
+
source.each_line do |l|
|
40
|
+
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
|
41
|
+
matched_path = m.captures.compact[0]
|
42
|
+
abs_matched_path = File.expand_path(matched_path, File.dirname(path))
|
43
|
+
unless visited_paths.include? abs_matched_path
|
44
|
+
block.call abs_matched_path
|
45
|
+
get_all_reference_paths(abs_matched_path, nil, visited_paths, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
30
51
|
# @param [String] ts_path
|
31
52
|
# @param [String] source TypeScript source code
|
53
|
+
# @param [Sprockets::Context] sprockets context object
|
32
54
|
# @return [String] compiled JavaScript source code
|
33
|
-
def compile(ts_path, source, *options)
|
55
|
+
def compile(ts_path, source, context=nil, *options)
|
56
|
+
if context
|
57
|
+
get_all_reference_paths(File.expand_path(ts_path), source) do |abs_path|
|
58
|
+
context.depend_on abs_path
|
59
|
+
end
|
60
|
+
end
|
34
61
|
s = replace_relative_references(ts_path, source)
|
35
62
|
::TypeScript::Node.compile(s, *default_options, *options)
|
36
63
|
end
|
@@ -21,8 +21,8 @@ class Typescript::Rails::Template < ::Tilt::Template
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def evaluate(
|
25
|
-
@output ||= ::Typescript::Rails::Compiler.compile(file, data)
|
24
|
+
def evaluate(context, locals, &block)
|
25
|
+
@output ||= ::Typescript::Rails::Compiler.compile(file, data, context)
|
26
26
|
end
|
27
27
|
|
28
28
|
# @override
|
data/test/assets_test.rb
CHANGED
@@ -42,6 +42,7 @@ class AssetsTest < ActiveSupport::TestCase
|
|
42
42
|
|
43
43
|
test "assets .js.ts is compiled from TypeScript to JavaScript" do
|
44
44
|
assert { assets["javascripts/hello"].present? }
|
45
|
+
assert { assets["javascripts/hello"].send(:dependency_paths).map(&:pathname).map(&:to_s).include? File.expand_path("#{File.dirname(__FILE__)}/fixtures/assets/javascripts/included.ts") }
|
45
46
|
assert { assets["javascripts/hello"].body.include?('var s = "Hello, world!";') }
|
46
47
|
end
|
47
48
|
end
|
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.5.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:
|
12
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typescript-node
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- lib/typescript/rails/version.rb
|
81
81
|
- test/assets_test.rb
|
82
82
|
- test/fixtures/assets/javascripts/hello.js.ts
|
83
|
+
- test/fixtures/assets/javascripts/included.ts
|
84
|
+
- test/fixtures/assets/javascripts/reference.ts
|
83
85
|
- test/fixtures/routes.rb
|
84
86
|
- test/fixtures/site/es5.js.ts
|
85
87
|
- test/fixtures/site/index.js.ts
|
@@ -112,13 +114,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
114
|
version: '0'
|
113
115
|
requirements: []
|
114
116
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.4.6
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: Adds Typescript to the Rails Asset pipeline
|
119
121
|
test_files:
|
120
122
|
- test/assets_test.rb
|
121
123
|
- test/fixtures/assets/javascripts/hello.js.ts
|
124
|
+
- test/fixtures/assets/javascripts/included.ts
|
125
|
+
- test/fixtures/assets/javascripts/reference.ts
|
122
126
|
- test/fixtures/routes.rb
|
123
127
|
- test/fixtures/site/es5.js.ts
|
124
128
|
- test/fixtures/site/index.js.ts
|