typescript-rails 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Nzg4NDc0YzU3NGViY2NiMjk4Y2JmMGQzN2MzZTQ0Yjc4MGI4Y2RkNA==
5
- data.tar.gz: !binary |-
6
- NGYyY2I2NjAwOTEyZDVmODUzMjE2MTQ2Y2VhOTQ1NDBkOWI5ZTcyMQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDEzNGQ1YjU4NDVkNDI0NDcwZDZjZDc3MDk4MzFjMTkxMDgyMGQ1YjZkZjA5
10
- MGUzM2JkNGVlMjhkNjgxYjEwNTAyMzE5ZjUxY2M4NjljYWM4NzBmMTdlYTcy
11
- NTllN2NkOGM0ZmU2YzVhZGQxMGNlNzVhNzRmYTVjYzljMGQxNzk=
12
- data.tar.gz: !binary |-
13
- NWU2OTUwMmE3MDRkZDdmMzBlNjExYmRlY2QyMjliZDYyZmUxNzljZDg3ZDE3
14
- NDFmM2NhNWI1Yjc4YjgwZWZiNzllMjYxYmFiMjkzNjdmMDVmNWFiNGQzYWZi
15
- ZTFlZjIyZGUxMGVmZTY5NzFkM2Q0MDNiOTYwMjY1MGFlMmIzMTM=
2
+ SHA1:
3
+ metadata.gz: f5d77f08721b8681ce68d5aedb9dc14926de34fc
4
+ data.tar.gz: 2f96be0c4b65b5ede9f1ef812e488511401469f5
5
+ SHA512:
6
+ metadata.gz: 5672c91a06cf89f43577e5d0a8d43fdf5bd88866b54e85607b45c222fdfb4bc125bffa83fc814e8270826a4e533f5f6fb3aabb18d36d60b3c6bdd37dcb4c9ab9
7
+ data.tar.gz: 9826e185b8e56e55fcbdb61cb2ed46b2330dab8764655a766107dcd7340b7e3e6c143e7a2ca80c2af9ccac5988eb5c97fcbad4a1b533b721ef9eb611e7ce4684
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .idea/*
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -1,12 +1,11 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
- - ree
3
+ - 2.0.0
4
+ - 2.1.0
5
5
  - jruby
6
- - rbx
6
+ notifications:
7
+ email: false
7
8
  script: bundle exec rake test
8
9
  matrix:
9
10
  allow_failures:
10
- - rvm: rbx
11
- - rvm: ree
12
11
  - rvm: jruby
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in typescript-rails.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rails', '~> 3.2.0'
6
+ gem 'rails', '~> 4.0'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # TypeScript for Rails [![Build Status](https://travis-ci.org/klaustopher/typescript-rails.png?branch=master)](https://travis-ci.org/klaustopher/typescript-rails)
1
+ # TypeScript for Rails [![Build Status](https://travis-ci.org/typescript-rails/typescript-rails.svg?branch=master)](https://travis-ci.org/typescript-rails/typescript-rails)
2
2
 
3
3
  This is a wrapper for the [TypeScript](http://www.typescriptlang.org/) JavaScript superset language by Microsoft.
4
4
 
@@ -33,6 +33,7 @@ And then execute:
33
33
  $ bundle
34
34
 
35
35
  ## Usage
36
+
36
37
  Just add a `.js.ts` file in your `app/assets/javascripts` directory and include it just like you are used to do.
37
38
 
38
39
  ## Contributing
@@ -42,3 +43,12 @@ Just add a `.js.ts` file in your `app/assets/javascripts` directory and include
42
43
  3. Commit your changes (`git commit -am 'Add some feature'`)
43
44
  4. Push to the branch (`git push origin my-new-feature`)
44
45
  5. Create new Pull Request
46
+
47
+ ## Maintainers
48
+
49
+ FUJI Goro <gfuji@cpan.org>
50
+
51
+ ## Authors
52
+
53
+ Klaus Zanders <klaus.zanders@gmail.com>
54
+
@@ -4,7 +4,7 @@ module Typescript
4
4
  config.before_initialize do |app|
5
5
  require 'typescript-rails'
6
6
 
7
- if app.config.assets.enabled
7
+ if ::Rails::VERSION::MAJOR >= 4 || app.config.assets.enabled
8
8
  require 'sprockets'
9
9
  require 'sprockets/engines'
10
10
  Sprockets.register_engine '.ts', Typescript::Rails::TypeScriptTemplate
@@ -41,7 +41,8 @@ module Typescript
41
41
  end
42
42
 
43
43
  def evaluate(scope, locals, &block)
44
- @output ||= TypeScript::Node.compile(data)
44
+ source = Typescript::Rails.replace_relative_references(file, data)
45
+ @output ||= TypeScript::Node.compile(source)
45
46
  end
46
47
 
47
48
  def allows_script?
@@ -57,9 +58,39 @@ module Typescript
57
58
 
58
59
  def self.call(template)
59
60
  compiled_source = erb_handler.call(template)
60
- "TypeScript::Node.compile(begin;#{compiled_source};end)"
61
+ escaped_path = template.identifier.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
62
+ <<-EOS
63
+ TypeScript::Node.compile(
64
+ Typescript::Rails.replace_relative_references(
65
+ '#{escaped_path}', (begin;#{compiled_source};end)
66
+ )
67
+ )
68
+ EOS
61
69
  end
62
70
  end
71
+
72
+ # Replace relative paths specified in /// <reference path="..." /> with absolute paths.
73
+ #
74
+ # @param [String] ts_path Source .ts path
75
+ # @param [String] ts source. It might be pre-processed by erb.
76
+ # @return [String] replaces source
77
+ def self.replace_relative_references(ts_path, source)
78
+ ts_dir = File.dirname(File.expand_path(ts_path))
79
+ escaped_dir = ts_dir.gsub(/["\\]/, '\\\\\&') # "\"" => "\\\"", '\\' => '\\\\'
80
+
81
+ # Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
82
+ # So we go the long way around.
83
+ output = ''
84
+ source.each_line do |l|
85
+ if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
86
+ l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
87
+ end
88
+
89
+ output = output + l + $/
90
+ end
91
+
92
+ output
93
+ end
63
94
  end
64
95
  end
65
96
 
@@ -1,5 +1,5 @@
1
1
  module Typescript
2
2
  module Rails
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
- /// <reference path="<%= File.join(File.dirname(__FILE__), "ref1_1.js.ts") %>" />
1
+ /// <reference path="ref1_1.js.ts" />
2
2
 
3
3
  f(1, 2)
@@ -1 +1 @@
1
- var f: (x: number, y: number) => number;
1
+ declare var f: (x: number, y: number) => number;
@@ -1,3 +1,3 @@
1
- /// <reference path="<%= File.join(File.dirname(__FILE__), "ref2_1.d.ts") %>" />
1
+ /// <reference path="./ref2_1.d.ts" />
2
2
 
3
3
  f(1, 2)
@@ -0,0 +1,5 @@
1
+ /// <reference path="ref3_2.ts" />
2
+ /// <reference path="ref3_3.ts" />
3
+
4
+ f1();
5
+ f2();
@@ -0,0 +1,3 @@
1
+ var f1 = function() {
2
+
3
+ };
@@ -0,0 +1,3 @@
1
+ var f2 = function() {
2
+
3
+ };
@@ -13,6 +13,7 @@ DummyApp.draw do
13
13
  get "site/ref1_2"
14
14
  get "site/ref2_1"
15
15
  get "site/ref2_2"
16
+ get "site/ref3_1"
16
17
  end
17
18
 
18
19
  class TemplateHandlerTest < ActiveSupport::TestCase
@@ -22,20 +23,33 @@ class TemplateHandlerTest < ActiveSupport::TestCase
22
23
  @app ||= DummyApp
23
24
  end
24
25
 
26
+ def source
27
+ # source without comments
28
+ last_response.body.gsub(%r{^//[^\n]*}m, '')
29
+ end
30
+
25
31
  test "typescript views are served as javascript" do
26
32
  get "/site/index.js"
27
-
28
- assert_match "var x = 5;\r\n", last_response.body
33
+ assert_match /var x = 5;\s*/,
34
+ source
29
35
  end
30
36
 
31
37
  test "<reference> to other .ts file works" do
32
38
  get "/site/ref1_2.js"
33
- assert_match "var f = function (x, y) {\r\n return x + y;\r\n};\r\nf(1, 2);\r\n", last_response.body
39
+ assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
40
+ source
34
41
  end
35
42
 
36
43
  test "<reference> to other .d.ts file works" do
37
44
  get "/site/ref2_2.js"
38
- assert_match "f(1, 2);\r\n", last_response.body
45
+ assert_match /f\(1, 2\);\s*/,
46
+ source
47
+ end
48
+
49
+ test "<reference> to multiple .ts files works" do
50
+ get "/site/ref3_1.js"
51
+ assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
52
+ source
39
53
  end
40
54
 
41
55
  end
@@ -8,16 +8,16 @@ Gem::Specification.new do |gem|
8
8
  gem.name = "typescript-rails"
9
9
  gem.version = Typescript::Rails::VERSION
10
10
  gem.platform = Gem::Platform::RUBY
11
- gem.authors = ["Klaus Zanders"]
12
- gem.email = ["klaus.zanders@gmail.com"]
11
+ gem.authors = ["FUJI, Goro", "Klaus Zanders"]
12
+ gem.email = ["gfuji@cpan.org", "klaus.zanders@gmail.com"]
13
13
  gem.description = %q{Adds Typescript to the Rails Asset pipeline}
14
14
  gem.summary = %q{Adds Typescript to the Rails Asset pipeline}
15
- gem.homepage = "http://github.com/klaustopher/typescript-rails"
15
+ gem.homepage = "https://github.com/typescript-rails/typescript-rails"
16
16
 
17
17
  gem.rubyforge_project = "typescript-rails"
18
18
 
19
- gem.add_runtime_dependency 'typescript-node', '~> 0.0'
20
- gem.add_runtime_dependency 'tilt', '~> 1.3'
19
+ gem.add_runtime_dependency 'typescript-node'
20
+ gem.add_runtime_dependency 'tilt'
21
21
  gem.add_runtime_dependency 'railties'
22
22
 
23
23
  gem.files = `git ls-files`.split($/)
@@ -25,5 +25,5 @@ Gem::Specification.new do |gem|
25
25
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
26
  gem.require_paths = ["lib"]
27
27
 
28
- gem.required_ruby_version = ">= 1.9.2"
28
+ gem.required_ruby_version = ">= 1.9.3"
29
29
  end
metadata CHANGED
@@ -1,66 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typescript-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
+ - FUJI, Goro
7
8
  - Klaus Zanders
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2014-07-29 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: typescript-node
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ~>
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: '0.0'
20
+ version: '0'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ~>
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
- version: '0.0'
27
+ version: '0'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: tilt
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ~>
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: '1.3'
34
+ version: '0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ~>
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
- version: '1.3'
41
+ version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: railties
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ! '>='
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ! '>='
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  description: Adds Typescript to the Rails Asset pipeline
56
57
  email:
58
+ - gfuji@cpan.org
57
59
  - klaus.zanders@gmail.com
58
60
  executables: []
59
61
  extensions: []
60
62
  extra_rdoc_files: []
61
63
  files:
62
- - .gitignore
63
- - .travis.yml
64
+ - ".gitignore"
65
+ - ".travis.yml"
64
66
  - Gemfile
65
67
  - LICENSE.txt
66
68
  - README.md
@@ -78,10 +80,13 @@ files:
78
80
  - test/support/site/ref1_2.js.ts
79
81
  - test/support/site/ref2_1.d.ts
80
82
  - test/support/site/ref2_2.js.ts
83
+ - test/support/site/ref3_1.js.ts
84
+ - test/support/site/ref3_2.ts
85
+ - test/support/site/ref3_3.ts
81
86
  - test/template_handler_test.rb
82
87
  - test/test_helper.rb
83
88
  - typescript-rails.gemspec
84
- homepage: http://github.com/klaustopher/typescript-rails
89
+ homepage: https://github.com/typescript-rails/typescript-rails
85
90
  licenses: []
86
91
  metadata: {}
87
92
  post_install_message:
@@ -90,17 +95,17 @@ require_paths:
90
95
  - lib
91
96
  required_ruby_version: !ruby/object:Gem::Requirement
92
97
  requirements:
93
- - - ! '>='
98
+ - - ">="
94
99
  - !ruby/object:Gem::Version
95
- version: 1.9.2
100
+ version: 1.9.3
96
101
  required_rubygems_version: !ruby/object:Gem::Requirement
97
102
  requirements:
98
- - - ! '>='
103
+ - - ">="
99
104
  - !ruby/object:Gem::Version
100
105
  version: '0'
101
106
  requirements: []
102
107
  rubyforge_project: typescript-rails
103
- rubygems_version: 2.0.2
108
+ rubygems_version: 2.2.2
104
109
  signing_key:
105
110
  specification_version: 4
106
111
  summary: Adds Typescript to the Rails Asset pipeline
@@ -112,5 +117,8 @@ test_files:
112
117
  - test/support/site/ref1_2.js.ts
113
118
  - test/support/site/ref2_1.d.ts
114
119
  - test/support/site/ref2_2.js.ts
120
+ - test/support/site/ref3_1.js.ts
121
+ - test/support/site/ref3_2.ts
122
+ - test/support/site/ref3_3.ts
115
123
  - test/template_handler_test.rb
116
124
  - test/test_helper.rb