typescript-rails 0.6.2 → 0.6.2.2

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: c751b651761e7485f8f819bc2f5532a4e7f14143
4
- data.tar.gz: 2a478762b57661926b117d59a09401b358113023
3
+ metadata.gz: bcd4ce63f85ea2ef761dc6e3f06f2eb3939489c7
4
+ data.tar.gz: 8ec37411498038e67091212f4abe33234038043e
5
5
  SHA512:
6
- metadata.gz: 5f87b29a0618c3a6351039d2f3023ae7f4b9a2a447d9c836fb498a706b7d746edb601e103abc89ece0d65ed6c6f1e60c970700686e146bc780a089f12403b94c
7
- data.tar.gz: 8f0f2dfe8aa3c913760744eecaf904de261bc46b462c52b96001da155225ed182299e8fd42d6f90f6219a21b7ae15900f575d38a3b6e11d747a5e5173a61fb15
6
+ metadata.gz: 22c2d2bdd59b8ff9c320936e3ebb7373c124b03fae0dd5ec3e99a56f37347e421ea4245f7ff3cd4ccf610be96e380bd1c2f10fa1a40fad174957d4b146be1c98
7
+ data.tar.gz: 94acdd48ae0ec799028a54e0db5faa1a1a233281bc2e8947cd36e669b6af892be4e933e5b6cd7d13c9d894445499b8512f64975b0ae263e7206c696af4972efc
@@ -1 +1 @@
1
- service_name: travis-ci
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -1,18 +1,18 @@
1
- .idea/*
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
1
+ .idea/*
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -1,9 +1,9 @@
1
- rvm:
2
- - 2.0.0
3
- - 2.1.1
4
- notifications:
5
- email: false
6
- script: bundle exec rake test
7
- matrix:
8
- allow_failures:
9
- - rvm:
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.1
4
+ notifications:
5
+ email: false
6
+ script: bundle exec rake test
7
+ matrix:
8
+ allow_failures:
9
+ - rvm:
data/CHANGES.md CHANGED
@@ -1,32 +1,40 @@
1
- ## v0.6.1 2015-07-27 21:52:50+0300
2
-
3
- * Now code raises exception with correct file name when TS compilation error occurs
4
-
5
- ## v0.6.0 2015-07-06 22:36:25+0300
6
-
7
- * Updated version to 0.6.0 for using Typescript source 1.4.1.3
8
-
9
- ## v0.5.0 2015-03-25 10:46:29+0900
10
-
11
- * Expire root TS cache in response to change in referenced `.ts` files (#24)
12
-
13
- ## v0.4.2 2014-11-26 07:30:12+0900
14
-
15
- * Fix newlines (#15)
16
- * Mention to `default_options` in README (#18)
17
-
18
- ## v0.4.1 2014-08-12 00:05:17+0900
19
-
20
- * Fix a runtime error
21
-
22
- ## v0.4.0 2014-08-11 23:04:20+0900
23
-
24
- * Set `--noImplicitAny` by default to tsc compiler
25
- * Typescript::Rails::Compiler.default_options to provide tsc compiler with otpions
26
- * default values: `--target ES5 --noImplicitAny`
27
- * A lot of refactoring
28
-
29
- ## v0.3.0 2014-08-09 10:27:54+0900
30
-
31
- * Compiles TypeScript files in ES5 mode
32
-
1
+ ## v0.6.2.1 2016-07-26 18:27:00+0300
2
+
3
+ * Added Sprockets 4 support. Thanks to @mihai-dinculescu
4
+
5
+ ## v0.6.2 2015-07-27 21:52:50+0300
6
+
7
+ * Updated to TS v1.6.2
8
+
9
+ ## v0.6.1 2015-07-27 21:52:50+0300
10
+
11
+ * Now code raises exception with correct file name when TS compilation error occurs
12
+
13
+ ## v0.6.0 2015-07-06 22:36:25+0300
14
+
15
+ * Updated version to 0.6.0 for using Typescript source 1.4.1.3
16
+
17
+ ## v0.5.0 2015-03-25 10:46:29+0900
18
+
19
+ * Expire root TS cache in response to change in referenced `.ts` files (#24)
20
+
21
+ ## v0.4.2 2014-11-26 07:30:12+0900
22
+
23
+ * Fix newlines (#15)
24
+ * Mention to `default_options` in README (#18)
25
+
26
+ ## v0.4.1 2014-08-12 00:05:17+0900
27
+
28
+ * Fix a runtime error
29
+
30
+ ## v0.4.0 2014-08-11 23:04:20+0900
31
+
32
+ * Set `--noImplicitAny` by default to tsc compiler
33
+ * Typescript::Rails::Compiler.default_options to provide tsc compiler with otpions
34
+ * default values: `--target ES5 --noImplicitAny`
35
+ * A lot of refactoring
36
+
37
+ ## v0.3.0 2014-08-09 10:27:54+0900
38
+
39
+ * Compiles TypeScript files in ES5 mode
40
+
data/Gemfile CHANGED
@@ -1,14 +1,14 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in typescript-rails.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'rails', '~> 4.0'
8
- gem 'sprockets-rails', '> 2.0'
9
- gem 'minitest-power_assert'
10
- gem 'coveralls'
11
- gem 'simplecov'
12
- gem 'tzinfo-data', platforms: [:mingw, :mswin]
13
- end
14
-
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in typescript-rails.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rails', '~> 4.0'
8
+ gem 'sprockets-rails', '> 2.0'
9
+ gem 'minitest-power_assert'
10
+ gem 'coveralls'
11
+ gem 'simplecov'
12
+ gem 'tzinfo-data', platforms: [:mingw, :mswin]
13
+ end
14
+
@@ -1,22 +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
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
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,65 +1,65 @@
1
- # TypeScript for Rails [![Build Status](https://travis-ci.org/typescript-ruby/typescript-rails.svg?branch=master)](https://travis-ci.org/typescript-ruby/typescript-rails) [![Coverage Status](https://coveralls.io/repos/typescript-ruby/typescript-rails/badge.png)](https://coveralls.io/r/typescript-ruby/typescript-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
- This gem uses the
8
- [typescript-node-ruby](https://github.com/typescript-ruby/typescript-node-ruby)
9
- library by KAWACHI Takashi for the typescript parsing with node js.
10
-
11
- The credit for the overall structure and the tests goes to the people that wrote the [coffee-rails](https://github.com/rails/coffee-rails) Gem, since I shamelessly copy&pasted some of their code.
12
-
13
- ## Requirements
14
-
15
- The current version requires that [node.js](http://nodejs.org/) is
16
- installed on the system.
17
-
18
- The requirement for node is tested upon starting the application. If
19
- the node command is not available you get the following error message:
20
-
21
- ```
22
- typescript-node requires node command, but it's not found. Please install it. Set TS_NODE environmental variable If you want to use node command in non-standard path.
23
- ```
24
-
25
- ## Installation
26
-
27
- Add this line to your application's Gemfile:
28
-
29
- gem 'typescript-rails'
30
-
31
- And then execute:
32
-
33
- $ bundle
34
-
35
- ## Usage
36
-
37
- Just add a `.js.ts` file in your `app/assets/javascripts` directory and include it just like you are used to do.
38
-
39
- Configurations:
40
-
41
- ```
42
- # Its defaults are `--target ES5 --noImplicitAny`.
43
- Typescript::Rails::Compiler.default_options = [ ... ]
44
- ```
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.
49
-
50
- ## Contributing
51
-
52
- 1. Fork it
53
- 2. Create your feature branch (`git checkout -b my-new-feature`)
54
- 3. Commit your changes (`git commit -am 'Add some feature'`)
55
- 4. Push to the branch (`git push origin my-new-feature`)
56
- 5. Create new Pull Request
57
-
58
- ## Maintainers
59
-
60
- FUJI Goro <gfuji@cpan.org>
61
-
62
- ## Authors
63
-
64
- Klaus Zanders <klaus.zanders@gmail.com>
65
-
1
+ # TypeScript for Rails [![Build Status](https://travis-ci.org/typescript-ruby/typescript-rails.svg?branch=master)](https://travis-ci.org/typescript-ruby/typescript-rails) [![Coverage Status](https://coveralls.io/repos/typescript-ruby/typescript-rails/badge.png)](https://coveralls.io/r/typescript-ruby/typescript-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
+ This gem uses the
8
+ [typescript-node-ruby](https://github.com/typescript-ruby/typescript-node-ruby)
9
+ library by KAWACHI Takashi for the typescript parsing with node js.
10
+
11
+ The credit for the overall structure and the tests goes to the people that wrote the [coffee-rails](https://github.com/rails/coffee-rails) Gem, since I shamelessly copy&pasted some of their code.
12
+
13
+ ## Requirements
14
+
15
+ The current version requires that [node.js](http://nodejs.org/) is
16
+ installed on the system.
17
+
18
+ The requirement for node is tested upon starting the application. If
19
+ the node command is not available you get the following error message:
20
+
21
+ ```
22
+ typescript-node requires node command, but it's not found. Please install it. Set TS_NODE environmental variable If you want to use node command in non-standard path.
23
+ ```
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ gem 'typescript-rails'
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ ## Usage
36
+
37
+ Just add a `.js.ts` file in your `app/assets/javascripts` directory and include it just like you are used to do.
38
+
39
+ Configurations:
40
+
41
+ ```
42
+ # Its defaults are `--target ES5 --noImplicitAny`.
43
+ Typescript::Rails::Compiler.default_options = [ ... ]
44
+ ```
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.
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
57
+
58
+ ## Maintainers
59
+
60
+ FUJI Goro <gfuji@cpan.org>
61
+
62
+ ## Authors
63
+
64
+ Klaus Zanders <klaus.zanders@gmail.com>
65
+
data/Rakefile CHANGED
@@ -1,13 +1,13 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rake/testtask'
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << 'lib'
8
- t.libs << 'test'
9
- t.pattern = 'test/**/*_test.rb'
10
- t.verbose = false
11
- end
12
-
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
13
  task :default => :test
@@ -1 +1 @@
1
- <%= TypeScript::Src.js_content %>
1
+ <%= TypeScript::Src.js_content %>
@@ -1,6 +1,7 @@
1
- require 'typescript/rails'
2
- require 'typescript/rails/railtie'
3
- require 'typescript/rails/engine'
4
- require 'typescript/rails/template'
5
- require 'typescript/rails/template_handler'
6
- require 'typescript/rails/version'
1
+ require 'typescript/rails'
2
+ require 'typescript/rails/railtie'
3
+ require 'typescript/rails/engine'
4
+ require 'typescript/rails/template'
5
+ require 'typescript/rails/template_handler'
6
+ require 'typescript/rails/transformer'
7
+ require 'typescript/rails/version'
@@ -1,5 +1,5 @@
1
- module Typescript
2
- module Rails
3
- # just to define the module Typescript::Rails
4
- end
1
+ module Typescript
2
+ module Rails
3
+ # just to define the module Typescript::Rails
4
+ end
5
5
  end
@@ -1,70 +1,70 @@
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
- (source.each_line.map do |l|
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))
24
- end
25
- next l
26
- end).join
27
- end
28
-
29
- # Get all references
30
- #
31
- # @param [String] path Source .ts path
32
- # @param [String] source. It might be pre-processed by erb.
33
- # @yieldreturn [String] matched ref abs_path
34
- def get_all_reference_paths(path, source, visited_paths=Set.new, &block)
35
- visited_paths << path
36
- source ||= File.read(path)
37
- source.each_line do |l|
38
- if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
39
- matched_path = m.captures.compact[0]
40
- abs_matched_path = File.expand_path(matched_path, File.dirname(path))
41
- unless visited_paths.include? abs_matched_path
42
- block.call abs_matched_path
43
- get_all_reference_paths(abs_matched_path, nil, visited_paths, &block)
44
- end
45
- end
46
- end
47
- end
48
-
49
- # @param [String] ts_path
50
- # @param [String] source TypeScript source code
51
- # @param [Sprockets::Context] sprockets context object
52
- # @return [String] compiled JavaScript source code
53
- def compile(ts_path, source, context=nil, *options)
54
- if context
55
- get_all_reference_paths(File.expand_path(ts_path), source) do |abs_path|
56
- context.depend_on abs_path
57
- end
58
- end
59
- s = replace_relative_references(ts_path, source)
60
- begin
61
- ::TypeScript::Node.compile(s, *default_options, *options)
62
- rescue Exception => e
63
- raise "Typescript error in file '#{ts_path}':\n#{e.message}"
64
- end
65
- end
66
-
67
- end
68
-
69
- self.default_options = %w(--target ES5 --noImplicitAny)
70
- end
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
+ (source.each_line.map do |l|
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))
24
+ end
25
+ next l
26
+ end).join
27
+ end
28
+
29
+ # Get all references
30
+ #
31
+ # @param [String] path Source .ts path
32
+ # @param [String] source. It might be pre-processed by erb.
33
+ # @yieldreturn [String] matched ref abs_path
34
+ def get_all_reference_paths(path, source, visited_paths=Set.new, &block)
35
+ visited_paths << path
36
+ source ||= File.read(path)
37
+ source.each_line do |l|
38
+ if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
39
+ matched_path = m.captures.compact[0]
40
+ abs_matched_path = File.expand_path(matched_path, File.dirname(path))
41
+ unless visited_paths.include? abs_matched_path
42
+ block.call abs_matched_path
43
+ get_all_reference_paths(abs_matched_path, nil, visited_paths, &block)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # @param [String] ts_path
50
+ # @param [String] source TypeScript source code
51
+ # @param [Sprockets::Context] sprockets context object
52
+ # @return [String] compiled JavaScript source code
53
+ def compile(ts_path, source, context=nil, *options)
54
+ if context
55
+ get_all_reference_paths(File.expand_path(ts_path), source) do |abs_path|
56
+ context.depend_on abs_path
57
+ end
58
+ end
59
+ s = replace_relative_references(ts_path, source)
60
+ begin
61
+ ::TypeScript::Node.compile(s, *default_options, *options)
62
+ rescue Exception => e
63
+ raise "Typescript error in file '#{ts_path}':\n#{e.message}"
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ self.default_options = %w(--target ES5 --noImplicitAny)
70
+ end
@@ -1,6 +1,6 @@
1
- require 'rails/engine'
2
-
3
- class Typescript::Rails::Engine < Rails::Engine
4
- # For now, let's not be the default generator ...
5
- # config.app_generators.javascript_engine :ts
1
+ require 'rails/engine'
2
+
3
+ class Typescript::Rails::Engine < Rails::Engine
4
+ # For now, let's not be the default generator ...
5
+ # config.app_generators.javascript_engine :ts
6
6
  end
@@ -1,11 +1,20 @@
1
- require 'typescript/rails'
2
-
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
9
- end
10
- end
11
- end
1
+ require 'typescript/rails'
2
+
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 'typescript/rails/transformer'
8
+ require 'sprockets'
9
+
10
+ if Sprockets.respond_to?(:register_engine)
11
+ Sprockets.register_engine '.ts', Typescript::Rails::Template, silence_deprecation: true
12
+ end
13
+
14
+ if Sprockets.respond_to?(:register_transformer)
15
+ Sprockets.register_mime_type 'text/typescript', extensions: ['.js.ts']
16
+ Sprockets.register_transformer 'text/typescript', 'application/javascript', Typescript::Rails::Transformer
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,32 +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(context, locals, &block)
25
- @output ||= ::Typescript::Rails::Compiler.compile(file, data, context)
26
- end
27
-
28
- # @override
29
- def allows_script?
30
- false
31
- end
32
- end
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(context, locals, &block)
25
+ @output ||= ::Typescript::Rails::Compiler.compile(file, data, context)
26
+ end
27
+
28
+ # @override
29
+ def allows_script?
30
+ false
31
+ end
32
+ end
@@ -1,21 +1,21 @@
1
- require 'typescript/rails/compiler'
2
-
3
- class Typescript::Rails::TemplateHandler
4
- class << self
5
- def erb_handler
6
- @erb_handler ||= ActionView::Template.registered_template_handler(:erb)
7
- end
8
-
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
15
- end
16
- end
17
- end
18
-
19
- ActiveSupport.on_load(:action_view) do
20
- ActionView::Template.register_template_handler :ts, Typescript::Rails::TemplateHandler
21
- end
1
+ require 'typescript/rails/compiler'
2
+
3
+ class Typescript::Rails::TemplateHandler
4
+ class << self
5
+ def erb_handler
6
+ @erb_handler ||= ActionView::Template.registered_template_handler(:erb)
7
+ end
8
+
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
15
+ end
16
+ end
17
+ end
18
+
19
+ ActiveSupport.on_load(:action_view) do
20
+ ActionView::Template.register_template_handler :ts, Typescript::Rails::TemplateHandler
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'typescript/rails'
2
+
3
+ class Typescript::Rails::Transformer
4
+ def self.instance
5
+ @instance ||= new
6
+ end
7
+
8
+ def self.call(input)
9
+ instance.call(input)
10
+ end
11
+
12
+ def call(input)
13
+ filename = input[:filename]
14
+ source = input[:data]
15
+ context = input[:environment].context_class.new(input)
16
+
17
+ result = ::Typescript::Rails::Compiler.compile(filename, source, context)
18
+ { data: result }
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
- module Typescript
2
- module Rails
3
- VERSION = '0.6.2'
4
- end
5
- end
1
+ module Typescript
2
+ module Rails
3
+ VERSION = '0.6.2.2'
4
+ end
5
+ end
@@ -1,48 +1,48 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
- require 'typescript-rails'
3
-
4
- require 'action_controller/railtie'
5
- require 'sprockets/railtie'
6
-
7
-
8
- class AssetsTest < ActiveSupport::TestCase
9
- include Minitest::PowerAssert::Assertions
10
-
11
- def setup
12
- FileUtils.mkdir_p tmp_path
13
-
14
- @app = Class.new(Rails::Application)
15
-
16
- @app.config.eager_load = false
17
- @app.config.active_support.deprecation = :stderr
18
- @app.config.assets.configure do |env|
19
- env.cache = ActiveSupport::Cache.lookup_store(:memory_store)
20
- end
21
- @app.config.assets.paths << "#{File.dirname(__FILE__)}/fixtures/assets"
22
- @app.paths['log'] = "#{tmp_path}/log/test.log"
23
- @app.initialize!
24
- end
25
-
26
- def teardown
27
- FileUtils.rm_rf tmp_path
28
- end
29
-
30
- def tmp_path
31
- "#{File.dirname(__FILE__)}/tmp"
32
- end
33
-
34
- def assets
35
- @app.assets
36
- end
37
-
38
- test 'typescript.js is included in Sprockets environment' do
39
- assert { assets["typescript"].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
40
- assert { assets["typescript"].source.include?('var ts;') }
41
- end
42
-
43
- test 'assets .js.ts is compiled from TypeScript to JavaScript' do
44
- assert { assets['javascripts/hello'].present? }
45
- assert { assets['javascripts/hello'].source.include?('var log_to_console = function (x) {') }
46
- assert { assets['javascripts/hello'].source.include?('var s = "Hello, world!";') }
47
- end
48
- end
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ require 'typescript-rails'
3
+
4
+ require 'action_controller/railtie'
5
+ require 'sprockets/railtie'
6
+
7
+
8
+ class AssetsTest < ActiveSupport::TestCase
9
+ include Minitest::PowerAssert::Assertions
10
+
11
+ def setup
12
+ FileUtils.mkdir_p tmp_path
13
+
14
+ @app = Class.new(Rails::Application)
15
+
16
+ @app.config.eager_load = false
17
+ @app.config.active_support.deprecation = :stderr
18
+ @app.config.assets.configure do |env|
19
+ env.cache = ActiveSupport::Cache.lookup_store(:memory_store)
20
+ end
21
+ @app.config.assets.paths << "#{File.dirname(__FILE__)}/fixtures/assets"
22
+ @app.paths['log'] = "#{tmp_path}/log/test.log"
23
+ @app.initialize!
24
+ end
25
+
26
+ def teardown
27
+ FileUtils.rm_rf tmp_path
28
+ end
29
+
30
+ def tmp_path
31
+ "#{File.dirname(__FILE__)}/tmp"
32
+ end
33
+
34
+ def assets
35
+ @app.assets
36
+ end
37
+
38
+ test 'typescript.js is included in Sprockets environment' do
39
+ assert { assets["typescript"].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
40
+ assert { assets["typescript"].source.include?('var ts;') }
41
+ end
42
+
43
+ test 'assets .js.ts is compiled from TypeScript to JavaScript' do
44
+ assert { assets['javascripts/hello.js'].present? }
45
+ assert { assets['javascripts/hello.js'].source.include?('var log_to_console = function (x) {') }
46
+ assert { assets['javascripts/hello.js'].source.include?('var s = "Hello, world!";') }
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
- /// <reference path="reference.ts" />
2
- var s: string = "Hello, world!";
3
- log_to_console(s);
1
+ /// <reference path="reference.ts" />
2
+ var s: string = "Hello, world!";
3
+ log_to_console(s);
@@ -1,4 +1,4 @@
1
- /// <reference path="reference.ts" />
2
- var log_to_console = function(x: string): void {
3
- console.log(x)
4
- }
1
+ /// <reference path="reference.ts" />
2
+ var log_to_console = function(x: string): void {
3
+ console.log(x)
4
+ }
@@ -1,2 +1,2 @@
1
- /// <reference path="hello.js.ts" />
2
- /// <reference path="included.ts" />
1
+ /// <reference path="hello.js.ts" />
2
+ /// <reference path="included.ts" />
@@ -1,7 +1,7 @@
1
- class Person {
2
- private _name = "Alice";
3
-
4
- public get name(): string {
5
- return this._name
6
- }
1
+ class Person {
2
+ private _name = "Alice";
3
+
4
+ public get name(): string {
5
+ return this._name
6
+ }
7
7
  }
@@ -1 +1 @@
1
- var x:number = 5
1
+ var x:number = 5
@@ -1,3 +1,3 @@
1
- var f = function(x: number, y: number): number {
2
- return x + y
3
- }
1
+ var f = function(x: number, y: number): number {
2
+ return x + y
3
+ }
@@ -1,3 +1,3 @@
1
- /// <reference path="ref1_1.js.ts" />
2
-
3
- f(1, 2)
1
+ /// <reference path="ref1_1.js.ts" />
2
+
3
+ f(1, 2)
@@ -1 +1 @@
1
- declare var f: (x: number, y: number) => number;
1
+ declare var f: (x: number, y: number) => number;
@@ -1,3 +1,3 @@
1
- /// <reference path="./ref2_1.d.ts" />
2
-
3
- f(1, 2)
1
+ /// <reference path="./ref2_1.d.ts" />
2
+
3
+ f(1, 2)
@@ -1,5 +1,5 @@
1
- /// <reference path="ref3_2.ts" />
2
- /// <reference path="ref3_3.ts" />
3
-
4
- f1();
1
+ /// <reference path="ref3_2.ts" />
2
+ /// <reference path="ref3_3.ts" />
3
+
4
+ f1();
5
5
  f2();
@@ -1,3 +1,3 @@
1
- var f1 = function(): void {
2
-
3
- };
1
+ var f1 = function(): void {
2
+
3
+ };
@@ -1,3 +1,3 @@
1
- var f2 = function(): void {
2
-
3
- };
1
+ var f2 = function(): void {
2
+
3
+ };
@@ -1,60 +1,60 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
- require 'action_controller'
3
- require 'typescript-rails'
4
-
5
- class SiteController < ActionController::Base
6
- self.view_paths = File.expand_path('../fixtures', __FILE__)
7
- end
8
-
9
- DummyApp = ActionDispatch::Routing::RouteSet.new
10
- DummyApp.draw do
11
- get 'site/index'
12
- get 'site/ref1_1'
13
- get 'site/ref1_2'
14
- get 'site/ref2_1'
15
- get 'site/ref2_2'
16
- get 'site/ref3_1'
17
- get 'site/es5'
18
- end
19
-
20
- class TemplateHandlerTest < ActiveSupport::TestCase
21
- include Rack::Test::Methods
22
-
23
- def app
24
- @app ||= DummyApp
25
- end
26
-
27
- def source
28
- # source without comments
29
- last_response.body.gsub(%r{^//[^\n]*}m, '')
30
- end
31
-
32
- test 'typescript views are served as javascript' do
33
- get '/site/index.js'
34
- assert_match /var x = 5;\s*/,
35
- source
36
- end
37
-
38
- test '<reference> to other .ts file works' do
39
- get '/site/ref1_2.js'
40
- assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
41
- source
42
- end
43
-
44
- test '<reference> to other .d.ts file works' do
45
- get '/site/ref2_2.js'
46
- assert_match /f\(1, 2\);\s*/,
47
- source
48
- end
49
-
50
- test '<reference> to multiple .ts files works' do
51
- get '/site/ref3_1.js'
52
- assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
53
- source
54
- end
55
-
56
- test 'ES5 features' do
57
- get '/site/es5.js'
58
- assert_equal 200, last_response.status
59
- end
60
- end
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ require 'action_controller'
3
+ require 'typescript-rails'
4
+
5
+ class SiteController < ActionController::Base
6
+ self.view_paths = File.expand_path('../fixtures', __FILE__)
7
+ end
8
+
9
+ DummyApp = ActionDispatch::Routing::RouteSet.new
10
+ DummyApp.draw do
11
+ get 'site/index'
12
+ get 'site/ref1_1'
13
+ get 'site/ref1_2'
14
+ get 'site/ref2_1'
15
+ get 'site/ref2_2'
16
+ get 'site/ref3_1'
17
+ get 'site/es5'
18
+ end
19
+
20
+ class TemplateHandlerTest < ActiveSupport::TestCase
21
+ include Rack::Test::Methods
22
+
23
+ def app
24
+ @app ||= DummyApp
25
+ end
26
+
27
+ def source
28
+ # source without comments
29
+ last_response.body.gsub(%r{^//[^\n]*}m, '')
30
+ end
31
+
32
+ test 'typescript views are served as javascript' do
33
+ get '/site/index.js'
34
+ assert_match /var x = 5;\s*/,
35
+ source
36
+ end
37
+
38
+ test '<reference> to other .ts file works' do
39
+ get '/site/ref1_2.js'
40
+ assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
41
+ source
42
+ end
43
+
44
+ test '<reference> to other .d.ts file works' do
45
+ get '/site/ref2_2.js'
46
+ assert_match /f\(1, 2\);\s*/,
47
+ source
48
+ end
49
+
50
+ test '<reference> to multiple .ts files works' do
51
+ get '/site/ref3_1.js'
52
+ assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
53
+ source
54
+ end
55
+
56
+ test 'ES5 features' do
57
+ get '/site/es5.js'
58
+ assert_equal 200, last_response.status
59
+ end
60
+ end
@@ -1,27 +1,27 @@
1
- # Configure coveralls environment
2
-
3
- require 'coveralls'
4
- require 'simplecov'
5
-
6
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
- SimpleCov::Formatter::HTMLFormatter,
8
- Coveralls::SimpleCov::Formatter
9
- ]
10
- SimpleCov.start do
11
- add_filter '.bundle/'
12
- end
13
-
14
- # Configure Rails environment
15
- ENV["RAILS_ENV"] = "test"
16
-
17
- require 'rails'
18
- require "rails/test_help"
19
- require 'minitest-power_assert'
20
-
21
- def copy_routes
22
- routes = File.expand_path("../support/routes.rb", __FILE__)
23
- destination = File.join(destination_root, "config")
24
-
25
- FileUtils.mkdir_p(destination)
26
- FileUtils.cp routes, destination
1
+ # Configure coveralls environment
2
+
3
+ require 'coveralls'
4
+ require 'simplecov'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start do
11
+ add_filter '.bundle/'
12
+ end
13
+
14
+ # Configure Rails environment
15
+ ENV['RAILS_ENV'] = 'test'
16
+
17
+ require 'rails'
18
+ require 'rails/test_help'
19
+ require 'minitest-power_assert'
20
+
21
+ def copy_routes
22
+ routes = File.expand_path('../support/routes.rb', __FILE__)
23
+ destination = File.join(destination_root, 'config')
24
+
25
+ FileUtils.mkdir_p(destination)
26
+ FileUtils.cp routes, destination
27
27
  end
@@ -1,27 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
-
5
- require 'typescript/rails/version'
6
-
7
- Gem::Specification.new do |gem|
8
- gem.name = 'typescript-rails'
9
- gem.version = Typescript::Rails::VERSION
10
- gem.platform = Gem::Platform::RUBY
11
- gem.authors = ['FUJI, Goro', 'Klaus Zanders']
12
- gem.email = %w(gfuji@cpan.org klaus.zanders@gmail.com)
13
- gem.description = %q{Adds Typescript to the Rails Asset pipeline}
14
- gem.summary = %q{Adds Typescript to the Rails Asset pipeline}
15
- gem.homepage = 'https://github.com/typescript-ruby/typescript-rails'
16
-
17
- gem.add_runtime_dependency 'typescript-node', '>= 1.6.2'
18
- gem.add_runtime_dependency 'tilt'
19
- gem.add_runtime_dependency 'railties'
20
-
21
- gem.files = `git ls-files`.split($/)
22
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
- gem.require_paths = ['lib']
25
-
26
- gem.required_ruby_version = '>= 2.0.0'
27
- end
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'typescript/rails/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = 'typescript-rails'
9
+ gem.version = Typescript::Rails::VERSION
10
+ gem.platform = Gem::Platform::RUBY
11
+ gem.authors = ['FUJI, Goro', 'Klaus Zanders']
12
+ gem.email = %w(gfuji@cpan.org klaus.zanders@gmail.com)
13
+ gem.description = %q{Adds Typescript to the Rails Asset pipeline}
14
+ gem.summary = %q{Adds Typescript to the Rails Asset pipeline}
15
+ gem.homepage = 'https://github.com/typescript-ruby/typescript-rails'
16
+
17
+ gem.add_runtime_dependency 'typescript-node', '>= 1.6.2'
18
+ gem.add_runtime_dependency 'tilt'
19
+ gem.add_runtime_dependency 'railties'
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ['lib']
25
+
26
+ gem.required_ruby_version = '>= 2.0.0'
27
+ 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.6.2
4
+ version: 0.6.2.2
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: 2015-09-30 00:00:00.000000000 Z
12
+ date: 2016-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typescript-node
@@ -77,6 +77,7 @@ files:
77
77
  - lib/typescript/rails/railtie.rb
78
78
  - lib/typescript/rails/template.rb
79
79
  - lib/typescript/rails/template_handler.rb
80
+ - lib/typescript/rails/transformer.rb
80
81
  - lib/typescript/rails/version.rb
81
82
  - test/assets_test.rb
82
83
  - test/fixtures/assets/javascripts/hello.js.ts
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  requirements: []
116
117
  rubyforge_project:
117
- rubygems_version: 2.2.3
118
+ rubygems_version: 2.4.8
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: Adds Typescript to the Rails Asset pipeline
@@ -135,3 +136,4 @@ test_files:
135
136
  - test/fixtures/site/ref3_3.ts
136
137
  - test/template_handler_test.rb
137
138
  - test/test_helper.rb
139
+ has_rdoc: