Skip to content

Commit c509760

Browse files
authored
Merge pull request #1 from NEWROPE/chore/support-for-rails-6.1
[#184611345] Chore / Support for rails 6.1
2 parents 925eb0c + a43bee7 commit c509760

File tree

8 files changed

+239
-19
lines changed

8 files changed

+239
-19
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
.bundle
55
.config
66
.yardoc
7-
Gemfile.lock
87
InstalledFiles
98
_yardoc
109
coverage

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ source 'https://rubygems.org'
44
gemspec
55

66
group :test do
7-
gem 'rails', '~> 4.0'
7+
gem 'rails', '>= 4.0'
8+
gem 'sprockets', '~> 3'
89
gem 'sprockets-rails', '> 2.0'
910
gem 'minitest-power_assert'
1011
gem 'coveralls'

Gemfile.lock

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
PATH
2+
remote: .
3+
specs:
4+
typescript-rails (0.6.2.4)
5+
railties
6+
tilt
7+
typescript-node (>= 1.6.2)
8+
9+
GEM
10+
remote: https://rubygems.org/
11+
specs:
12+
actioncable (7.0.4.3)
13+
actionpack (= 7.0.4.3)
14+
activesupport (= 7.0.4.3)
15+
nio4r (~> 2.0)
16+
websocket-driver (>= 0.6.1)
17+
actionmailbox (7.0.4.3)
18+
actionpack (= 7.0.4.3)
19+
activejob (= 7.0.4.3)
20+
activerecord (= 7.0.4.3)
21+
activestorage (= 7.0.4.3)
22+
activesupport (= 7.0.4.3)
23+
mail (>= 2.7.1)
24+
net-imap
25+
net-pop
26+
net-smtp
27+
actionmailer (7.0.4.3)
28+
actionpack (= 7.0.4.3)
29+
actionview (= 7.0.4.3)
30+
activejob (= 7.0.4.3)
31+
activesupport (= 7.0.4.3)
32+
mail (~> 2.5, >= 2.5.4)
33+
net-imap
34+
net-pop
35+
net-smtp
36+
rails-dom-testing (~> 2.0)
37+
actionpack (7.0.4.3)
38+
actionview (= 7.0.4.3)
39+
activesupport (= 7.0.4.3)
40+
rack (~> 2.0, >= 2.2.0)
41+
rack-test (>= 0.6.3)
42+
rails-dom-testing (~> 2.0)
43+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
44+
actiontext (7.0.4.3)
45+
actionpack (= 7.0.4.3)
46+
activerecord (= 7.0.4.3)
47+
activestorage (= 7.0.4.3)
48+
activesupport (= 7.0.4.3)
49+
globalid (>= 0.6.0)
50+
nokogiri (>= 1.8.5)
51+
actionview (7.0.4.3)
52+
activesupport (= 7.0.4.3)
53+
builder (~> 3.1)
54+
erubi (~> 1.4)
55+
rails-dom-testing (~> 2.0)
56+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
57+
activejob (7.0.4.3)
58+
activesupport (= 7.0.4.3)
59+
globalid (>= 0.3.6)
60+
activemodel (7.0.4.3)
61+
activesupport (= 7.0.4.3)
62+
activerecord (7.0.4.3)
63+
activemodel (= 7.0.4.3)
64+
activesupport (= 7.0.4.3)
65+
activestorage (7.0.4.3)
66+
actionpack (= 7.0.4.3)
67+
activejob (= 7.0.4.3)
68+
activerecord (= 7.0.4.3)
69+
activesupport (= 7.0.4.3)
70+
marcel (~> 1.0)
71+
mini_mime (>= 1.1.0)
72+
activesupport (7.0.4.3)
73+
concurrent-ruby (~> 1.0, >= 1.0.2)
74+
i18n (>= 1.6, < 2)
75+
minitest (>= 5.1)
76+
tzinfo (~> 2.0)
77+
builder (3.2.4)
78+
concurrent-ruby (1.2.2)
79+
coveralls (0.7.1)
80+
multi_json (~> 1.3)
81+
rest-client
82+
simplecov (>= 0.7)
83+
term-ansicolor
84+
thor
85+
crass (1.0.6)
86+
date (3.3.3)
87+
docile (1.4.0)
88+
domain_name (0.5.20190701)
89+
unf (>= 0.0.5, < 1.0.0)
90+
erubi (1.12.0)
91+
globalid (1.1.0)
92+
activesupport (>= 5.0)
93+
http-accept (1.7.0)
94+
http-cookie (1.0.5)
95+
domain_name (~> 0.5)
96+
i18n (1.12.0)
97+
concurrent-ruby (~> 1.0)
98+
loofah (2.20.0)
99+
crass (~> 1.0.2)
100+
nokogiri (>= 1.5.9)
101+
mail (2.8.1)
102+
mini_mime (>= 0.1.1)
103+
net-imap
104+
net-pop
105+
net-smtp
106+
marcel (1.0.2)
107+
method_source (1.0.0)
108+
mime-types (3.4.1)
109+
mime-types-data (~> 3.2015)
110+
mime-types-data (3.2023.0218.1)
111+
mini_mime (1.1.2)
112+
minitest (5.18.0)
113+
minitest-power_assert (0.3.1)
114+
minitest
115+
power_assert (>= 1.1)
116+
multi_json (1.15.0)
117+
net-imap (0.3.4)
118+
date
119+
net-protocol
120+
net-pop (0.1.2)
121+
net-protocol
122+
net-protocol (0.2.1)
123+
timeout
124+
net-smtp (0.3.3)
125+
net-protocol
126+
netrc (0.11.0)
127+
nio4r (2.5.9)
128+
nokogiri (1.14.2-x86_64-darwin)
129+
racc (~> 1.4)
130+
power_assert (2.0.3)
131+
racc (1.6.2)
132+
rack (2.2.6.4)
133+
rack-test (2.1.0)
134+
rack (>= 1.3)
135+
rails (7.0.4.3)
136+
actioncable (= 7.0.4.3)
137+
actionmailbox (= 7.0.4.3)
138+
actionmailer (= 7.0.4.3)
139+
actionpack (= 7.0.4.3)
140+
actiontext (= 7.0.4.3)
141+
actionview (= 7.0.4.3)
142+
activejob (= 7.0.4.3)
143+
activemodel (= 7.0.4.3)
144+
activerecord (= 7.0.4.3)
145+
activestorage (= 7.0.4.3)
146+
activesupport (= 7.0.4.3)
147+
bundler (>= 1.15.0)
148+
railties (= 7.0.4.3)
149+
rails-dom-testing (2.0.3)
150+
activesupport (>= 4.2.0)
151+
nokogiri (>= 1.6)
152+
rails-html-sanitizer (1.5.0)
153+
loofah (~> 2.19, >= 2.19.1)
154+
railties (7.0.4.3)
155+
actionpack (= 7.0.4.3)
156+
activesupport (= 7.0.4.3)
157+
method_source
158+
rake (>= 12.2)
159+
thor (~> 1.0)
160+
zeitwerk (~> 2.5)
161+
rake (13.0.6)
162+
rest-client (2.1.0)
163+
http-accept (>= 1.7.0, < 2.0)
164+
http-cookie (>= 1.0.2, < 2.0)
165+
mime-types (>= 1.16, < 4.0)
166+
netrc (~> 0.8)
167+
simplecov (0.22.0)
168+
docile (~> 1.1)
169+
simplecov-html (~> 0.11)
170+
simplecov_json_formatter (~> 0.1)
171+
simplecov-html (0.12.3)
172+
simplecov_json_formatter (0.1.4)
173+
sprockets (3.7.2)
174+
concurrent-ruby (~> 1.0)
175+
rack (> 1, < 3)
176+
sprockets-rails (3.4.2)
177+
actionpack (>= 5.2)
178+
activesupport (>= 5.2)
179+
sprockets (>= 3.0.0)
180+
sync (0.5.0)
181+
term-ansicolor (1.7.1)
182+
tins (~> 1.0)
183+
thor (1.2.1)
184+
tilt (2.1.0)
185+
timeout (0.3.2)
186+
tins (1.32.1)
187+
sync
188+
typescript-node (1.6.2)
189+
typescript-src (~> 1.6.2)
190+
typescript-src (1.6.2.0)
191+
tzinfo (2.0.6)
192+
concurrent-ruby (~> 1.0)
193+
unf (0.1.4)
194+
unf_ext
195+
unf_ext (0.0.8.2)
196+
websocket-driver (0.7.5)
197+
websocket-extensions (>= 0.1.0)
198+
websocket-extensions (0.1.5)
199+
zeitwerk (2.6.7)
200+
201+
PLATFORMS
202+
x86_64-darwin-21
203+
x86_64-darwin-22
204+
205+
DEPENDENCIES
206+
coveralls
207+
minitest-power_assert
208+
rails (>= 4.0)
209+
simplecov
210+
sprockets (~> 3)
211+
sprockets-rails (> 2.0)
212+
typescript-rails!
213+
tzinfo-data
214+
215+
BUNDLED WITH
216+
2.4.10

app/assets/config/manifest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//= link_tree ../images
2+
//= link_directory ../javascripts .js
3+
//= link_directory ../stylesheets .css

lib/typescript/rails/compiler.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
require 'typescript-node'
33

44
module Typescript::Rails::Compiler
5-
class << self
6-
# @!scope class
7-
cattr_accessor :default_options
5+
# @!scope class
6+
self.cattr_accessor(:default_options)
87

8+
class << self
99
# Replace relative paths specified in /// <reference path="..." /> with absolute paths.
1010
#
1111
# @param [String] ts_path Source .ts path
@@ -18,7 +18,7 @@ def replace_relative_references(ts_path, source)
1818
# Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
1919
# So we go the long way around.
2020
(source.each_line.map do |l|
21-
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
21+
if l.start_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
2222
matched_path = m.captures.compact[0]
2323
l = l.sub(matched_path, File.join(escaped_dir, matched_path))
2424
end
@@ -35,7 +35,7 @@ def get_all_reference_paths(path, source, visited_paths=Set.new, &block)
3535
visited_paths << path
3636
source ||= File.read(path)
3737
source.each_line do |l|
38-
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
38+
if l.start_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
3939
matched_path = m.captures.compact[0]
4040
abs_matched_path = File.expand_path(matched_path, File.dirname(path))
4141
unless visited_paths.include? abs_matched_path

test/assets_test.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ def assets
3535
@app.assets
3636
end
3737

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
38+
# Run all tests in one block to avoid error from calling @app.initialize! multiple times
39+
test 'generates assets successfully' do
40+
# typescript.js is included in Sprockets environment
41+
assert { assets['typescript'].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
42+
assert { assets['typescript'].source.include?('var ts;') }
4243

43-
test 'assets .js.ts is compiled from TypeScript to JavaScript' do
44+
# 'assets .js.ts is compiled from TypeScript to JavaScript'
4445
assert { assets['javascripts/hello.js'].present? }
4546
assert { assets['javascripts/hello.js'].source.include?('var log_to_console = function (x) {') }
4647
assert { assets['javascripts/hello.js'].source.include?('var s = "Hello, world!";') }

test/template_handler_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ def source
3131

3232
test 'typescript views are served as javascript' do
3333
get '/site/index.js'
34-
assert_match /var x = 5;\s*/,
34+
assert_match (/var x = 5;\s*/),
3535
source
3636
end
3737

3838
test '<reference> to other .ts file works' do
3939
get '/site/ref1_2.js'
40-
assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
40+
assert_match (/var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/),
4141
source
4242
end
4343

4444
test '<reference> to other .d.ts file works' do
4545
get '/site/ref2_2.js'
46-
assert_match /f\(1, 2\);\s*/,
46+
assert_match (/f\(1, 2\);\s*/),
4747
source
4848
end
4949

5050
test '<reference> to multiple .ts files works' do
5151
get '/site/ref3_1.js'
52-
assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
52+
assert_match (/var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/),
5353
source
5454
end
5555

test/test_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
require 'coveralls'
44
require 'simplecov'
55

6-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
77
SimpleCov::Formatter::HTMLFormatter,
88
Coveralls::SimpleCov::Formatter
9-
]
9+
])
1010
SimpleCov.start do
1111
add_filter '.bundle/'
1212
end
@@ -27,4 +27,4 @@ def copy_routes
2727

2828
FileUtils.mkdir_p(destination)
2929
FileUtils.cp routes, destination
30-
end
30+
end

0 commit comments

Comments
 (0)