typescript-rails 0.5.0 → 0.6.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: ff9a4a7b974ccde9082b7c16c4f9e04dca61e1b6
4
- data.tar.gz: d92a70618cf4472c5668263d520457576c88ced6
3
+ metadata.gz: e8748e73884fdec3f410d1e9b2dc9636491c5f6a
4
+ data.tar.gz: ddc998a9a74dc95dbdeeb85433395237e7b36fd0
5
5
  SHA512:
6
- metadata.gz: 92e08dbe08a9bb5216bd9a0d8f7fe6b77e7ede6787d88e0724d065eeea717b00b826e4233a810c6de4887161cb5d96c37e2d556e72cb8466a7407e095597d3fd
7
- data.tar.gz: e1f9344a67a40b4fc78241f230da8d9ea4dec2a73d2ba4b9610c6e3fd3ae2c8a0b2ffb6371ec9b0028d40b80792689e3a1f18c3467585d340f64b20a0aec4a79
6
+ metadata.gz: f63584413a05e868fda930fcb1c707ae136273a01714c9d25118c2f0aee7767b4ee37e76f18d419049754df794497af23e08e2da1706112bbb5c6ff7b4d1f2f0
7
+ data.tar.gz: 801b4363023b1f711c4de1ad428c5657df957270cf32f26a4c546467a55a4b503ea3134588ff37139fe2dde0255320a6e9bb71eedf11e923b5102fbfedaaaea7
@@ -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,24 +1,28 @@
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
-
5
- ## v0.4.2 2014-11-26 07:30:12+0900
6
-
7
- * Fix newlines (#15)
8
- * Mention to `default_options` in README (#18)
9
-
10
- ## v0.4.1 2014-08-12 00:05:17+0900
11
-
12
- * Fix a runtime error
13
-
14
- ## v0.4.0 2014-08-11 23:04:20+0900
15
-
16
- * Set `--noImplicitAny` by default to tsc compiler
17
- * Typescript::Rails::Compiler.default_options to provide tsc compiler with otpions
18
- * default values: `--target ES5 --noImplicitAny`
19
- * A lot of refactoring
20
-
21
- ## v0.3.0 2014-08-09 10:27:54+0900
22
-
23
- * Compiles TypeScript files in ES5 mode
24
-
1
+ ## v0.6.0 2015-07-06 22:36:25+0300
2
+
3
+ * Updated version to 0.6.0 for using Typescript source 1.4.1.3
4
+
5
+ ## v0.5.0 2015-03-25 10:46:29+0900
6
+
7
+ * Expire root TS cache in response to change in referenced `.ts` files (#24)
8
+
9
+ ## v0.4.2 2014-11-26 07:30:12+0900
10
+
11
+ * Fix newlines (#15)
12
+ * Mention to `default_options` in README (#18)
13
+
14
+ ## v0.4.1 2014-08-12 00:05:17+0900
15
+
16
+ * Fix a runtime error
17
+
18
+ ## v0.4.0 2014-08-11 23:04:20+0900
19
+
20
+ * Set `--noImplicitAny` by default to tsc compiler
21
+ * Typescript::Rails::Compiler.default_options to provide tsc compiler with otpions
22
+ * default values: `--target ES5 --noImplicitAny`
23
+ * A lot of refactoring
24
+
25
+ ## v0.3.0 2014-08-09 10:27:54+0900
26
+
27
+ * Compiles TypeScript files in ES5 mode
28
+
data/Gemfile CHANGED
@@ -1,13 +1,13 @@
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
- end
13
-
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
+ end
13
+
@@ -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,6 @@
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/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,71 +1,66 @@
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 = (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
-
28
- output
29
- end
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
-
51
- # @param [String] ts_path
52
- # @param [String] source TypeScript source code
53
- # @param [Sprockets::Context] sprockets context object
54
- # @return [String] compiled JavaScript source code
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
61
- s = replace_relative_references(ts_path, source)
62
- ::TypeScript::Node.compile(s, *default_options, *options)
63
- end
64
-
65
- end
66
-
67
- self.default_options = [
68
- '--target', 'ES5',
69
- '--noImplicitAny'
70
- ]
71
- 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
+ ::TypeScript::Node.compile(s, *default_options, *options)
61
+ end
62
+
63
+ end
64
+
65
+ self.default_options = %w(--target ES5 --noImplicitAny)
66
+ 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,11 @@
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 'sprockets'
8
+ Sprockets.register_engine '.ts', Typescript::Rails::Template
9
+ end
10
+ end
11
+ 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
@@ -1,5 +1,5 @@
1
- module Typescript
2
- module Rails
3
- VERSION = '0.5.0'
4
- end
5
- end
1
+ module Typescript
2
+ module Rails
3
+ VERSION = '0.6.0'
4
+ end
5
+ end
@@ -1,48 +1,48 @@
1
- require 'test_helper'
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"].pathname.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
40
- assert { assets["typescript"].body.include?('var TypeScript') }
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"].send(:dependency_paths).map(&:pathname).map(&:to_s).include? File.expand_path("#{File.dirname(__FILE__)}/fixtures/assets/javascripts/included.ts") }
46
- assert { assets["javascripts/hello"].body.include?('var s = "Hello, world!";') }
47
- 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"].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
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 'test_helper'
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 'test_helper'
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 = ["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.1.0'
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.4.1'
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.5.0
4
+ version: 0.6.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: 2015-03-25 00:00:00.000000000 Z
12
+ date: 2015-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typescript-node
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 1.1.0
20
+ version: 1.4.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 1.1.0
27
+ version: 1.4.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: tilt
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.4.6
117
+ rubygems_version: 2.2.3
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Adds Typescript to the Rails Asset pipeline