typescript-rails 0.3.0 → 0.4.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: d275ff8fd90b13580de3f11a3798e0cbd9aec47c
4
- data.tar.gz: 2942656ec7afda0c974fb05f3300058747862e58
3
+ metadata.gz: 18c02ddb2925e76f99d15526b4d68d12ebce5a3d
4
+ data.tar.gz: 8f743d5be68031c673151ee590623f64b94377e7
5
5
  SHA512:
6
- metadata.gz: 55f7d3ee2d3e65b07e65fa0e3c7d2a742abbff70679eb00cd3d20c9267532be40d4909b9883d10d905b0f081afca82cb8c1678ad918142be74322813abfb4530
7
- data.tar.gz: bee501dd861c693c090563015b480e5aac5d161390c301a742b26fde02ed96d1dbd5269e24228dae9a807d3a7d58828906b78ab05919d687ab7517dec2b1a7f6
6
+ metadata.gz: 4fd56936bee817a81102ff8f5353bf7d25ad549eec5e30339b87b3aaf95d1e0cbdf1df1f1b83c7aba0f88dd58f13b77d10e7b2a53f7324c11dcc62d9bdd6e8d7
7
+ data.tar.gz: 8d8884552159bcce98b011afc344b23bdc1362d0a589baa6f12a5ee127882e2a09e251324234647629bc077bc85e79b8517d0322f7eec6a4e952e7ae532195ed
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - 2.1.0
4
+ - 2.1.1
5
5
  - jruby
6
6
  notifications:
7
7
  email: false
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## v0.4.0 2014-08-11 23:04:20+0900
2
+
3
+ * Set `--noImplicitAny` by default to tsc compiler
4
+ * Typescript::Rails::Compiler.default_options to provide tsc compiler with otpions
5
+ * default values: `--target ES5 --noImplicitAny`
6
+ * A lot of refactoring
7
+
1
8
  ## v0.3.0 2014-08-09 10:27:54+0900
2
9
 
3
10
  * Compiles TypeScript files in ES5 mode
@@ -1,4 +1,6 @@
1
+ require 'typescript/rails'
1
2
  require 'typescript/rails/railtie'
2
3
  require 'typescript/rails/engine'
4
+ require 'typescript/rails/template'
3
5
  require 'typescript/rails/template_handler'
4
6
  require 'typescript/rails/version'
@@ -0,0 +1,5 @@
1
+ module Typescript
2
+ module Rails
3
+ # just to define the module Typescript::Rails
4
+ end
5
+ end
@@ -0,0 +1,45 @@
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 = ''
21
+ source.each_line do |l|
22
+ if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
23
+ l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
24
+ end
25
+ output = output + l + $/
26
+ end
27
+
28
+ output
29
+ end
30
+
31
+ # @param [String] ts_path
32
+ # @param [String] source TypeScript source code
33
+ # @return [String] compiled JavaScript source code
34
+ def compile(ts_path, source, *options)
35
+ s = replace_relative_references(ts_path, source)
36
+ ::TypeScript::Node.compile(s, *default_options, *options)
37
+ end
38
+
39
+ end
40
+
41
+ self.default_options = [
42
+ '--target', 'ES5',
43
+ '--noImplicitAny'
44
+ ]
45
+ end
@@ -1,10 +1,6 @@
1
1
  require 'rails/engine'
2
2
 
3
- module Typescript
4
- module Rails
5
- class Engine < ::Rails::Engine
6
- # For now, let's not be the default generator ...
7
- # config.app_generators.javascript_engine :ts
8
- end
9
- end
3
+ class Typescript::Rails::Engine < Rails::Engine
4
+ # For now, let's not be the default generator ...
5
+ # config.app_generators.javascript_engine :ts
10
6
  end
@@ -1,15 +1,11 @@
1
- module Typescript
2
- module Rails
3
- class Railtie < ::Rails::Railtie
4
- config.before_initialize do |app|
5
- require 'typescript-rails'
1
+ require 'typescript/rails'
6
2
 
7
- if ::Rails::VERSION::MAJOR >= 4 || app.config.assets.enabled
8
- require 'sprockets'
9
- require 'sprockets/engines'
10
- Sprockets.register_engine '.ts', Typescript::Rails::TypeScriptTemplate
11
- end
12
- end
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
13
9
  end
14
10
  end
15
- end
11
+ end
@@ -0,0 +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(scope, locals, &block)
25
+ @output ||= ::Typescript::Rails::Compiler.compile(file, source)
26
+ end
27
+
28
+ # @override
29
+ def allows_script?
30
+ false
31
+ end
32
+ end
@@ -1,98 +1,17 @@
1
- require 'typescript-node'
2
- require 'tilt'
1
+ require 'typescript/rails/compiler'
3
2
 
4
- module Typescript
5
- module Rails
6
-
7
- class TypeScriptTemplate < ::Tilt::Template
8
- self.default_mime_type = 'application/javascript'
9
-
10
- @@default_bare = false
11
-
12
- def self.default_bare
13
- @@default_bare
14
- end
15
-
16
- def self.default_bare=(value)
17
- @@default_bare = value
18
- end
19
-
20
- # @deprecated
21
- def self.default_no_wrap
22
- @@default_bare
23
- end
24
-
25
- # @deprecated
26
- def self.default_no_wrap=(value)
27
- @@default_bare = value
28
- end
29
-
30
- def self.engine_initialized?
31
- defined? ::TypeScript
32
- end
33
-
34
- def initialize_engine
35
- require_template_library 'coffee_script'
36
- end
37
-
38
- def prepare
39
- if !options.key?(:bare) and !options.key?(:no_wrap)
40
- options[:bare] = self.class.default_bare
41
- end
42
- end
43
-
44
- def evaluate(scope, locals, &block)
45
- source = Typescript::Rails.replace_relative_references(file, data)
46
- # TODO: employs source-maps
47
- @output ||= TypeScript::Node.compile(source, '--target', 'ES5')
48
- end
49
-
50
- def allows_script?
51
- false
52
- end
3
+ class Typescript::Rails::TemplateHandler
4
+ class << self
5
+ def erb_handler
6
+ @erb_handler ||= ActionView::Template.registered_template_handler(:erb)
53
7
  end
54
8
 
55
- class TemplateHandler
56
-
57
- def self.erb_handler
58
- @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
59
- end
60
-
61
- def self.call(template)
62
- compiled_source = erb_handler.call(template)
63
- escaped_path = template.identifier.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
64
- <<-EOS
65
- TypeScript::Node.compile(
66
- Typescript::Rails.replace_relative_references(
67
- '#{escaped_path}', (begin;#{compiled_source};end)
68
- ),
69
- '--target', 'ES5'
70
- )
71
- EOS
72
- end
73
- end
74
-
75
- # Replace relative paths specified in /// <reference path="..." /> with absolute paths.
76
- #
77
- # @param [String] ts_path Source .ts path
78
- # @param [String] ts source. It might be pre-processed by erb.
79
- # @return [String] replaces source
80
- def self.replace_relative_references(ts_path, source)
81
- ts_dir = File.dirname(File.expand_path(ts_path))
82
- escaped_dir = ts_dir.gsub(/["\\]/, '\\\\\&') # "\"" => "\\\"", '\\' => '\\\\'
83
-
84
- # Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
85
- # So we go the long way around.
86
- output = ''
87
- source.each_line do |l|
88
- if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
89
- l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
90
- end
91
-
92
- output = output + l + $/
93
- end
94
-
95
- output
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
96
15
  end
97
16
  end
98
17
  end
@@ -1,5 +1,5 @@
1
1
  module Typescript
2
2
  module Rails
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/test/assets_test.rb CHANGED
@@ -9,6 +9,7 @@ class AssetsTest < ActiveSupport::TestCase
9
9
  require "sprockets/railtie"
10
10
 
11
11
  @app = Class.new(Rails::Application)
12
+ @app.config.eager_load = false
12
13
  @app.config.active_support.deprecation = :stderr
13
14
  @app.config.assets.enabled = true
14
15
  @app.config.assets.cache_store = [ :file_store, "#{tmp_path}/cache" ]
@@ -1,3 +1,3 @@
1
- var f1 = function() {
1
+ var f1 = function(): void {
2
2
 
3
3
  };
@@ -1,3 +1,3 @@
1
- var f2 = function() {
1
+ var f2 = function(): void {
2
2
 
3
3
  };
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.3.0
4
+ version: 0.4.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-08-09 00:00:00.000000000 Z
12
+ date: 2014-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typescript-node
@@ -70,8 +70,11 @@ files:
70
70
  - Rakefile
71
71
  - lib/assets/javascripts/typescript.js.erb
72
72
  - lib/typescript-rails.rb
73
+ - lib/typescript/rails.rb
74
+ - lib/typescript/rails/compiler.rb
73
75
  - lib/typescript/rails/engine.rb
74
76
  - lib/typescript/rails/railtie.rb
77
+ - lib/typescript/rails/template.rb
75
78
  - lib/typescript/rails/template_handler.rb
76
79
  - lib/typescript/rails/version.rb
77
80
  - test/assets_test.rb