diff --git a/.gitignore b/.gitignore
index 10aa7a7..c8e8cf2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,6 @@
.bundle
.config
.yardoc
-Gemfile.lock
InstalledFiles
_yardoc
coverage
diff --git a/Gemfile b/Gemfile
index 702e422..52210ab 100644
--- a/Gemfile
+++ b/Gemfile
@@ -4,7 +4,8 @@ source 'https://rubygems.org'
gemspec
group :test do
- gem 'rails', '~> 4.0'
+ gem 'rails', '>= 4.0'
+ gem 'sprockets', '~> 3'
gem 'sprockets-rails', '> 2.0'
gem 'minitest-power_assert'
gem 'coveralls'
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..e025d7d
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,216 @@
+PATH
+ remote: .
+ specs:
+ typescript-rails (0.6.2.4)
+ railties
+ tilt
+ typescript-node (>= 1.6.2)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actioncable (7.0.4.3)
+ actionpack (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ nio4r (~> 2.0)
+ websocket-driver (>= 0.6.1)
+ actionmailbox (7.0.4.3)
+ actionpack (= 7.0.4.3)
+ activejob (= 7.0.4.3)
+ activerecord (= 7.0.4.3)
+ activestorage (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ mail (>= 2.7.1)
+ net-imap
+ net-pop
+ net-smtp
+ actionmailer (7.0.4.3)
+ actionpack (= 7.0.4.3)
+ actionview (= 7.0.4.3)
+ activejob (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ mail (~> 2.5, >= 2.5.4)
+ net-imap
+ net-pop
+ net-smtp
+ rails-dom-testing (~> 2.0)
+ actionpack (7.0.4.3)
+ actionview (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ rack (~> 2.0, >= 2.2.0)
+ rack-test (>= 0.6.3)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
+ actiontext (7.0.4.3)
+ actionpack (= 7.0.4.3)
+ activerecord (= 7.0.4.3)
+ activestorage (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ globalid (>= 0.6.0)
+ nokogiri (>= 1.8.5)
+ actionview (7.0.4.3)
+ activesupport (= 7.0.4.3)
+ builder (~> 3.1)
+ erubi (~> 1.4)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
+ activejob (7.0.4.3)
+ activesupport (= 7.0.4.3)
+ globalid (>= 0.3.6)
+ activemodel (7.0.4.3)
+ activesupport (= 7.0.4.3)
+ activerecord (7.0.4.3)
+ activemodel (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ activestorage (7.0.4.3)
+ actionpack (= 7.0.4.3)
+ activejob (= 7.0.4.3)
+ activerecord (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ marcel (~> 1.0)
+ mini_mime (>= 1.1.0)
+ activesupport (7.0.4.3)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 1.6, < 2)
+ minitest (>= 5.1)
+ tzinfo (~> 2.0)
+ builder (3.2.4)
+ concurrent-ruby (1.2.2)
+ coveralls (0.7.1)
+ multi_json (~> 1.3)
+ rest-client
+ simplecov (>= 0.7)
+ term-ansicolor
+ thor
+ crass (1.0.6)
+ date (3.3.3)
+ docile (1.4.0)
+ domain_name (0.5.20190701)
+ unf (>= 0.0.5, < 1.0.0)
+ erubi (1.12.0)
+ globalid (1.1.0)
+ activesupport (>= 5.0)
+ http-accept (1.7.0)
+ http-cookie (1.0.5)
+ domain_name (~> 0.5)
+ i18n (1.12.0)
+ concurrent-ruby (~> 1.0)
+ loofah (2.20.0)
+ crass (~> 1.0.2)
+ nokogiri (>= 1.5.9)
+ mail (2.8.1)
+ mini_mime (>= 0.1.1)
+ net-imap
+ net-pop
+ net-smtp
+ marcel (1.0.2)
+ method_source (1.0.0)
+ mime-types (3.4.1)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2023.0218.1)
+ mini_mime (1.1.2)
+ minitest (5.18.0)
+ minitest-power_assert (0.3.1)
+ minitest
+ power_assert (>= 1.1)
+ multi_json (1.15.0)
+ net-imap (0.3.4)
+ date
+ net-protocol
+ net-pop (0.1.2)
+ net-protocol
+ net-protocol (0.2.1)
+ timeout
+ net-smtp (0.3.3)
+ net-protocol
+ netrc (0.11.0)
+ nio4r (2.5.9)
+ nokogiri (1.14.2-x86_64-darwin)
+ racc (~> 1.4)
+ power_assert (2.0.3)
+ racc (1.6.2)
+ rack (2.2.6.4)
+ rack-test (2.1.0)
+ rack (>= 1.3)
+ rails (7.0.4.3)
+ actioncable (= 7.0.4.3)
+ actionmailbox (= 7.0.4.3)
+ actionmailer (= 7.0.4.3)
+ actionpack (= 7.0.4.3)
+ actiontext (= 7.0.4.3)
+ actionview (= 7.0.4.3)
+ activejob (= 7.0.4.3)
+ activemodel (= 7.0.4.3)
+ activerecord (= 7.0.4.3)
+ activestorage (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ bundler (>= 1.15.0)
+ railties (= 7.0.4.3)
+ rails-dom-testing (2.0.3)
+ activesupport (>= 4.2.0)
+ nokogiri (>= 1.6)
+ rails-html-sanitizer (1.5.0)
+ loofah (~> 2.19, >= 2.19.1)
+ railties (7.0.4.3)
+ actionpack (= 7.0.4.3)
+ activesupport (= 7.0.4.3)
+ method_source
+ rake (>= 12.2)
+ thor (~> 1.0)
+ zeitwerk (~> 2.5)
+ rake (13.0.6)
+ rest-client (2.1.0)
+ http-accept (>= 1.7.0, < 2.0)
+ http-cookie (>= 1.0.2, < 2.0)
+ mime-types (>= 1.16, < 4.0)
+ netrc (~> 0.8)
+ simplecov (0.22.0)
+ docile (~> 1.1)
+ simplecov-html (~> 0.11)
+ simplecov_json_formatter (~> 0.1)
+ simplecov-html (0.12.3)
+ simplecov_json_formatter (0.1.4)
+ sprockets (3.7.2)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-rails (3.4.2)
+ actionpack (>= 5.2)
+ activesupport (>= 5.2)
+ sprockets (>= 3.0.0)
+ sync (0.5.0)
+ term-ansicolor (1.7.1)
+ tins (~> 1.0)
+ thor (1.2.1)
+ tilt (2.1.0)
+ timeout (0.3.2)
+ tins (1.32.1)
+ sync
+ typescript-node (1.6.2)
+ typescript-src (~> 1.6.2)
+ typescript-src (1.6.2.0)
+ tzinfo (2.0.6)
+ concurrent-ruby (~> 1.0)
+ unf (0.1.4)
+ unf_ext
+ unf_ext (0.0.8.2)
+ websocket-driver (0.7.5)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.5)
+ zeitwerk (2.6.7)
+
+PLATFORMS
+ x86_64-darwin-21
+ x86_64-darwin-22
+
+DEPENDENCIES
+ coveralls
+ minitest-power_assert
+ rails (>= 4.0)
+ simplecov
+ sprockets (~> 3)
+ sprockets-rails (> 2.0)
+ typescript-rails!
+ tzinfo-data
+
+BUNDLED WITH
+ 2.4.10
diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js
new file mode 100644
index 0000000..b16e53d
--- /dev/null
+++ b/app/assets/config/manifest.js
@@ -0,0 +1,3 @@
+//= link_tree ../images
+//= link_directory ../javascripts .js
+//= link_directory ../stylesheets .css
diff --git a/lib/typescript/rails/compiler.rb b/lib/typescript/rails/compiler.rb
index 093b311..3c6cc5e 100644
--- a/lib/typescript/rails/compiler.rb
+++ b/lib/typescript/rails/compiler.rb
@@ -2,10 +2,10 @@
require 'typescript-node'
module Typescript::Rails::Compiler
- class << self
- # @!scope class
- cattr_accessor :default_options
+ # @!scope class
+ self.cattr_accessor(:default_options)
+ class << self
# Replace relative paths specified in /// with absolute paths.
#
# @param [String] ts_path Source .ts path
@@ -18,7 +18,7 @@ def replace_relative_references(ts_path, source)
# Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
# So we go the long way around.
(source.each_line.map do |l|
- if l.starts_with?('///') && !(m = %r!^///\s*\s*!.match(l)).nil?
+ if l.start_with?('///') && !(m = %r!^///\s*\s*!.match(l)).nil?
matched_path = m.captures.compact[0]
l = l.sub(matched_path, File.join(escaped_dir, matched_path))
end
@@ -35,7 +35,7 @@ def get_all_reference_paths(path, source, visited_paths=Set.new, &block)
visited_paths << path
source ||= File.read(path)
source.each_line do |l|
- if l.starts_with?('///') && !(m = %r!^///\s*\s*!.match(l)).nil?
+ if l.start_with?('///') && !(m = %r!^///\s*\s*!.match(l)).nil?
matched_path = m.captures.compact[0]
abs_matched_path = File.expand_path(matched_path, File.dirname(path))
unless visited_paths.include? abs_matched_path
diff --git a/test/assets_test.rb b/test/assets_test.rb
index 23b28b6..e551230 100644
--- a/test/assets_test.rb
+++ b/test/assets_test.rb
@@ -35,12 +35,13 @@ def assets
@app.assets
end
- test 'typescript.js is included in Sprockets environment' do
- assert { assets["typescript"].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
- assert { assets["typescript"].source.include?('var ts;') }
- end
+ # Run all tests in one block to avoid error from calling @app.initialize! multiple times
+ test 'generates assets successfully' do
+ # typescript.js is included in Sprockets environment
+ assert { assets['typescript'].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
+ assert { assets['typescript'].source.include?('var ts;') }
- test 'assets .js.ts is compiled from TypeScript to JavaScript' do
+ # 'assets .js.ts is compiled from TypeScript to JavaScript'
assert { assets['javascripts/hello.js'].present? }
assert { assets['javascripts/hello.js'].source.include?('var log_to_console = function (x) {') }
assert { assets['javascripts/hello.js'].source.include?('var s = "Hello, world!";') }
diff --git a/test/template_handler_test.rb b/test/template_handler_test.rb
index b0aef0f..6b9d7f4 100644
--- a/test/template_handler_test.rb
+++ b/test/template_handler_test.rb
@@ -31,25 +31,25 @@ def source
test 'typescript views are served as javascript' do
get '/site/index.js'
- assert_match /var x = 5;\s*/,
+ assert_match (/var x = 5;\s*/),
source
end
test ' to other .ts file works' do
get '/site/ref1_2.js'
- assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
+ assert_match (/var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/),
source
end
test ' to other .d.ts file works' do
get '/site/ref2_2.js'
- assert_match /f\(1, 2\);\s*/,
+ assert_match (/f\(1, 2\);\s*/),
source
end
test ' to multiple .ts files works' do
get '/site/ref3_1.js'
- assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
+ assert_match (/var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/),
source
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 7306cb5..c9905e9 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -3,10 +3,10 @@
require 'coveralls'
require 'simplecov'
-SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
-]
+])
SimpleCov.start do
add_filter '.bundle/'
end
@@ -27,4 +27,4 @@ def copy_routes
FileUtils.mkdir_p(destination)
FileUtils.cp routes, destination
-end
\ No newline at end of file
+end