Skip to content

Commit 4289f0d

Browse files
authored
Merge pull request #1 from es6-rails/es6_js_extension_for_assets_and_views
Adds .es6.js extensions for assets and views
2 parents 13df85e + c72afde commit 4289f0d

18 files changed

+311
-63
lines changed

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ gem 'jbuilder', '~> 2.0'
2121
# bundle exec rake doc:rails generates the API under doc/api.
2222
gem 'sdoc', '~> 0.4.0', group: :doc
2323

24-
gem 'es6-rails' #, path: "../es6-rails"
24+
gem 'es6-rails', '0.3.5'
25+
# gem 'es6-rails' , path: "../es6-rails"
26+
# gem 'es6-rails', :git => "[email protected]:razorcd/es6-rails.git", :branch => "master"
2527

2628
# Use ActiveModel has_secure_password
2729
# gem 'bcrypt', '~> 3.1.7'

Gemfile.lock

+68-56
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ GEM
3636
minitest (~> 5.1)
3737
thread_safe (~> 0.3, >= 0.3.4)
3838
tzinfo (~> 1.1)
39-
addressable (2.4.0)
40-
arel (6.0.3)
39+
addressable (2.5.2)
40+
public_suffix (>= 2.0.2, < 4.0)
41+
arel (6.0.4)
4142
babel-source (5.8.35)
4243
babel-transpiler (0.7.0)
4344
babel-source (>= 4.0, < 6)
4445
execjs (~> 2.0)
45-
binding_of_caller (0.7.2)
46+
binding_of_caller (0.8.0)
4647
debug_inspector (>= 0.0.1)
47-
builder (3.2.2)
48-
byebug (9.0.5)
48+
builder (3.2.3)
49+
byebug (10.0.2)
4950
capybara (2.7.1)
5051
addressable
5152
mime-types (>= 1.16)
@@ -62,43 +63,47 @@ GEM
6263
coffee-script (2.4.1)
6364
coffee-script-source
6465
execjs
65-
coffee-script-source (1.10.0)
66-
concurrent-ruby (1.0.2)
67-
debug_inspector (0.0.2)
68-
diff-lcs (1.2.5)
66+
coffee-script-source (1.12.2)
67+
concurrent-ruby (1.1.4)
68+
crass (1.0.4)
69+
debug_inspector (0.0.3)
70+
diff-lcs (1.3)
6971
erubis (2.7.0)
70-
es6-rails (0.2.0)
72+
es6-rails (0.3.5)
7173
babel-transpiler (~> 0.7, >= 0.7.0)
7274
rails (>= 4.0, < 5.0)
7375
sprockets (~> 3.0, >= 3.0.0)
7476
sprockets-es6 (~> 0.8, >= 0.8.1)
7577
execjs (2.7.0)
76-
globalid (0.3.6)
77-
activesupport (>= 4.1.0)
78-
i18n (0.7.0)
79-
jbuilder (2.5.0)
80-
activesupport (>= 3.0.0, < 5.1)
81-
multi_json (~> 1.2)
82-
jquery-rails (4.1.1)
78+
ffi (1.9.25)
79+
globalid (0.4.1)
80+
activesupport (>= 4.2.0)
81+
i18n (0.9.5)
82+
concurrent-ruby (~> 1.0)
83+
jbuilder (2.8.0)
84+
activesupport (>= 4.2.0)
85+
multi_json (>= 1.2)
86+
jquery-rails (4.3.3)
8387
rails-dom-testing (>= 1, < 3)
8488
railties (>= 4.2.0)
8589
thor (>= 0.14, < 2.0)
86-
json (1.8.3)
87-
loofah (2.0.3)
90+
json (1.8.6)
91+
loofah (2.2.3)
92+
crass (~> 1.0.2)
8893
nokogiri (>= 1.5.9)
89-
mail (2.6.4)
90-
mime-types (>= 1.16, < 4)
91-
mime-types (3.1)
94+
mail (2.7.1)
95+
mini_mime (>= 0.1.1)
96+
mime-types (3.2.2)
9297
mime-types-data (~> 3.2015)
93-
mime-types-data (3.2016.0521)
94-
mini_portile2 (2.1.0)
95-
minitest (5.9.0)
96-
multi_json (1.12.1)
97-
nokogiri (1.6.8)
98-
mini_portile2 (~> 2.1.0)
99-
pkg-config (~> 1.1.7)
100-
pkg-config (1.1.7)
101-
rack (1.6.4)
98+
mime-types-data (3.2018.0812)
99+
mini_mime (1.0.1)
100+
mini_portile2 (2.4.0)
101+
minitest (5.11.3)
102+
multi_json (1.13.1)
103+
nokogiri (1.9.1)
104+
mini_portile2 (~> 2.4.0)
105+
public_suffix (3.0.3)
106+
rack (1.6.11)
102107
rack-test (0.6.3)
103108
rack (>= 1.0)
104109
rails (4.2.4)
@@ -114,20 +119,22 @@ GEM
114119
sprockets-rails
115120
rails-deprecated_sanitizer (1.0.3)
116121
activesupport (>= 4.2.0.alpha)
117-
rails-dom-testing (1.0.7)
118-
activesupport (>= 4.2.0.beta, < 5.0)
119-
nokogiri (~> 1.6.0)
122+
rails-dom-testing (1.0.9)
123+
activesupport (>= 4.2.0, < 5.0)
124+
nokogiri (~> 1.6)
120125
rails-deprecated_sanitizer (>= 1.0.1)
121-
rails-html-sanitizer (1.0.3)
122-
loofah (~> 2.0)
126+
rails-html-sanitizer (1.0.4)
127+
loofah (~> 2.2, >= 2.2.2)
123128
railties (4.2.4)
124129
actionpack (= 4.2.4)
125130
activesupport (= 4.2.4)
126131
rake (>= 0.8.7)
127132
thor (>= 0.18.1, < 2.0)
128-
rake (11.2.2)
129-
rdoc (4.2.2)
130-
json (~> 1.4)
133+
rake (12.3.2)
134+
rb-fsevent (0.10.3)
135+
rb-inotify (0.10.0)
136+
ffi (~> 1.0)
137+
rdoc (4.3.0)
131138
rspec-core (3.4.4)
132139
rspec-support (~> 3.4.0)
133140
rspec-expectations (3.4.0)
@@ -145,42 +152,47 @@ GEM
145152
rspec-mocks (~> 3.4.0)
146153
rspec-support (~> 3.4.0)
147154
rspec-support (3.4.1)
148-
sass (3.4.22)
149-
sass-rails (5.0.4)
150-
railties (>= 4.0.0, < 5.0)
155+
sass (3.7.2)
156+
sass-listen (~> 4.0.0)
157+
sass-listen (4.0.0)
158+
rb-fsevent (~> 0.9, >= 0.9.4)
159+
rb-inotify (~> 0.9, >= 0.9.7)
160+
sass-rails (5.0.7)
161+
railties (>= 4.0.0, < 6)
151162
sass (~> 3.1)
152163
sprockets (>= 2.8, < 4.0)
153164
sprockets-rails (>= 2.0, < 4.0)
154165
tilt (>= 1.1, < 3)
155-
sdoc (0.4.1)
166+
sdoc (0.4.2)
156167
json (~> 1.7, >= 1.7.7)
157168
rdoc (~> 4.0)
158-
spring (1.7.1)
159-
sprockets (3.6.0)
169+
spring (2.0.2)
170+
activesupport (>= 4.2)
171+
sprockets (3.7.2)
160172
concurrent-ruby (~> 1.0)
161173
rack (> 1, < 3)
162-
sprockets-es6 (0.9.0)
174+
sprockets-es6 (0.9.2)
163175
babel-source (>= 5.8.11)
164176
babel-transpiler
165177
sprockets (>= 3.0.0)
166-
sprockets-rails (3.0.4)
178+
sprockets-rails (3.2.1)
167179
actionpack (>= 4.0)
168180
activesupport (>= 4.0)
169181
sprockets (>= 3.0.0)
170-
sqlite3 (1.3.11)
171-
thor (0.19.1)
172-
thread_safe (0.3.5)
173-
tilt (2.0.5)
174-
tzinfo (1.2.2)
182+
sqlite3 (1.3.13)
183+
thor (0.20.3)
184+
thread_safe (0.3.6)
185+
tilt (2.0.9)
186+
tzinfo (1.2.5)
175187
thread_safe (~> 0.1)
176-
uglifier (3.0.0)
188+
uglifier (4.1.20)
177189
execjs (>= 0.3.0, < 3)
178190
web-console (2.3.0)
179191
activemodel (>= 4.0)
180192
binding_of_caller (>= 0.7.2)
181193
railties (>= 4.0)
182194
sprockets-rails (>= 2.0, < 4.0)
183-
xpath (2.0.0)
195+
xpath (2.1.0)
184196
nokogiri (~> 1.3)
185197

186198
PLATFORMS
@@ -190,7 +202,7 @@ DEPENDENCIES
190202
byebug
191203
capybara-webkit (~> 1.11.1)
192204
coffee-rails (~> 4.1.0)
193-
es6-rails
205+
es6-rails (= 0.3.5)
194206
jbuilder (~> 2.0)
195207
jquery-rails
196208
rails (= 4.2.4)
@@ -203,4 +215,4 @@ DEPENDENCIES
203215
web-console (~> 2.0)
204216

205217
BUNDLED WITH
206-
1.10.6
218+
1.16.6

app/assets/javascripts/asset1.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
document.addEventListener('DOMContentLoaded', function() {
2+
var interval,
3+
i= 0,
4+
button= document.getElementById("asset-js-button"),
5+
element= document.getElementById("asset-js");
6+
7+
if (button) {
8+
button.onclick = function() {
9+
element.innerHTML= "Fibonacci sequence: "
10+
startFibonacci();
11+
}
12+
console.log("Asset vanilla JS ready")
13+
}
14+
15+
function startFibonacci(){
16+
interval = setInterval(function() {
17+
element.innerHTML+= fibonacci(i++) + ", ";
18+
if (i>10) {stopFibonacci()};
19+
}, 1000);
20+
}
21+
22+
function stopFibonacci(){
23+
clearInterval(interval);
24+
element.innerHTML+= " ...";
25+
}
26+
27+
function fibonacci(n=0) {
28+
return n>1 ? fibonacci(n-1)+fibonacci(n-2) : n;
29+
}
30+
}, false);

app/assets/javascripts/asset.es6 app/assets/javascripts/asset2.es6

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
document.addEventListener('DOMContentLoaded', function(){
2+
console.log("clickerd");
23
let interval,
34
i= 0,
45
button= document.getElementById("asset-es6-button"),

app/assets/javascripts/asset3.es6.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
document.addEventListener('DOMContentLoaded', function(){
2+
let interval,
3+
i= 0,
4+
button= document.getElementById("asset-es6-js-button"),
5+
element= document.getElementById("asset-es6-js");
6+
7+
if (button) {
8+
button.onclick= function(){
9+
element.innerHTML= "Fibonacci sequence: "
10+
startFibonacci();
11+
}
12+
console.log("Asset vanilla ES6 JS ready")
13+
}
14+
15+
function startFibonacci(limit=10){
16+
interval= setInterval(() => {
17+
element.innerHTML+= fibonacci(i++) + ", ";
18+
if (i>10) {stopFibonacci()};
19+
}, 1000);
20+
}
21+
22+
function stopFibonacci(){
23+
clearInterval(interval);
24+
element.innerHTML+= " ...";
25+
}
26+
27+
function fibonacci(n=0) {
28+
return n>1 ? fibonacci(n-1)+fibonacci(n-2) : n;
29+
}
30+
}, false);

app/controllers/example_controller.rb

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ class ExampleController < ApplicationController
22
def index
33
end
44

5+
#.js
6+
def asset_vanilla_js
7+
end
8+
9+
def inline_vanilla_js
10+
end
11+
12+
def remote_vanilla_js
13+
end
14+
15+
#.es6
516
def asset_vanilla_es6
617
end
718

@@ -11,6 +22,14 @@ def inline_vanilla_es6
1122
def remote_vanilla_es6
1223
end
1324

25+
#.es6.js
26+
def asset_vanilla_es6_js
27+
end
28+
29+
#remote scripts:
1430
def remote
1531
end
32+
33+
def remote3
34+
end
1635
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1>Asset vanilla ES6.JS</h1>
2+
<h4>File: app/assets/javascripts/asset.es6.js</h4>
3+
4+
<%= link_to "Execute asset.es6.js", "#", id: "asset-es6-js-button" %>
5+
<br/>
6+
<br/>
7+
<div id="asset-es6-js"></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1>Asset vanilla JS</h1>
2+
<h4>File: app/assets/javascripts/asset.js</h4>
3+
4+
<%= link_to "Execute asset.js", "#", id: "asset-js-button" %>
5+
<br/>
6+
<br/>
7+
<div id="asset-js"></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h1>Inline vanilla JS with ERB</h1>
2+
<h4>File: inline_vanilla_js.html.erb</h4>
3+
<div id="inline-js"></div>
4+
5+
<script>
6+
var interval,
7+
i= 0,
8+
element= document.getElementById("inline-js");
9+
10+
element.innerHTML= "Fibonacci sequence on inline js: "
11+
startFibonacci();
12+
console.log("Inline vanilla .js ready")
13+
14+
function startFibonacci(){
15+
interval= setInterval(function() {
16+
element.innerHTML+= fibonacci(i++) + ", ";
17+
if (i>10) {stopFibonacci()};
18+
}, 1000);
19+
}
20+
21+
function stopFibonacci(){
22+
clearInterval(interval);
23+
element.innerHTML+= " ...";
24+
}
25+
26+
function fibonacci(n=0) {
27+
return n>1 ? fibonacci(n-1)+fibonacci(n-2) : n;
28+
}
29+
</script>

app/views/example/remote.js.es6

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let interval,
22
i= 0,
33
element= document.getElementById("remote-es6");
44

5-
element.innerHTML= "Fibonacci sequence: "
5+
element.innerHTML= "Fibonacci sequence on .es6: "
66
startFibonacci();
77
console.log("Remote vanilla ES6 ready")
88

app/views/example/remote3.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var interval,
2+
i= 0,
3+
element= document.getElementById("remote-js");
4+
5+
element.innerHTML= "Fibonacci sequence on .js: "
6+
startFibonacci();
7+
console.log("Remote vanilla .js ready.")
8+
9+
function startFibonacci() {
10+
interval= setInterval(function() {
11+
element.innerHTML+= fibonacci(i++) + ", ";
12+
if (i>10) {stopFibonacci()};
13+
}, 1000);
14+
}
15+
16+
function stopFibonacci() {
17+
clearInterval(interval);
18+
element.innerHTML+= " ...";
19+
}
20+
21+
function fibonacci(n=0) {
22+
return n>1 ? fibonacci(n-1)+fibonacci(n-2) : n;
23+
}

0 commit comments

Comments
 (0)