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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d716f7abc650659d6d0265678a5a085144c53106
4
- data.tar.gz: dc6a563215325cec71abfab77557f64835cb6fb4
3
+ metadata.gz: ff9a4a7b974ccde9082b7c16c4f9e04dca61e1b6
4
+ data.tar.gz: d92a70618cf4472c5668263d520457576c88ced6
5
5
  SHA512:
6
- metadata.gz: 13286cd68dc352b52e6822aa36999fa9499492dcd7c3d98d7bcbe42c15cc70e49e3af5222f5df748aa58cb640e5e4f5e367157c11fcab8defc8c511d299f32c7
7
- data.tar.gz: 5ce4c3dc47c79cc660fc911b6d8573a71abb2496e33324d1c1e05606ea74865298715383979b778193f7004750a1a20fb585eafd3e0e65596557995f5c4c63cd
6
+ metadata.gz: 92e08dbe08a9bb5216bd9a0d8f7fe6b77e7ede6787d88e0724d065eeea717b00b826e4233a810c6de4887161cb5d96c37e2d556e72cb8466a7407e095597d3fd
7
+ data.tar.gz: e1f9344a67a40b4fc78241f230da8d9ea4dec2a73d2ba4b9610c6e3fd3ae2c8a0b2ffb6371ec9b0028d40b80792689e3a1f18c3467585d340f64b20a0aec4a79
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.5.0 2015-03-25 10:46:29+0900
2
+
3
+ * Expire root TS cache in response to change in referenced `.ts` files (#24)
4
+
1
5
  ## v0.4.2 2014-11-26 07:30:12+0900
2
6
 
3
7
  * Fix newlines (#15)
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'rails', '~> 4.0'
8
+ gem 'sprockets-rails', '> 2.0'
8
9
  gem 'minitest-power_assert'
9
10
  gem 'coveralls'
10
11
  gem 'simplecov'
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
- l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
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(scope, locals, &block)
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
@@ -1,5 +1,5 @@
1
1
  module Typescript
2
2
  module Rails
3
- VERSION = '0.4.2'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
@@ -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
@@ -1,2 +1,3 @@
1
+ /// <reference path="reference.ts" />
1
2
  var s: string = "Hello, world!";
2
- console.log(s)
3
+ log_to_console(s);
@@ -0,0 +1,4 @@
1
+ /// <reference path="reference.ts" />
2
+ var log_to_console = function(x: string): void {
3
+ console.log(x)
4
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference path="hello.js.ts" />
2
+ /// <reference path="included.ts" />
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.2
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: 2014-11-25 00:00:00.000000000 Z
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.2.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