Skip to content

Introduce TypeScript #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exclude:
- lib
- test
- vendor
- tsconfig.json

url: https://www.ruby-lang.org

Expand Down
16 changes: 16 additions & 0 deletions _javascripts_src/examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var Examples = {
names: ['cities', 'greeter', 'i_love_ruby', 'hello_world'],

random: function () {
return Examples.names[Math.floor(Math.random() * Examples.names.length)];
},

choose: function () {
var lang = document.location.pathname.split('/')[1];
var name = Examples.random();

$("#code").load('/' + lang + '/examples/' + name + '/');
}
};

$(document).ready(Examples.choose);
24 changes: 24 additions & 0 deletions _javascripts_src/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var Page = {
SiteLinks: {
highlight: function () {
var current_page = location.pathname;
$("#header div.site-links a:not(.home)").each(function (i) {
if (current_page.indexOf($(this).attr('href')) == 0) {
$(this).addClass('selected');
}
});

$("#home-page-layout #header div.site-links a.home").addClass('selected');
},

menu: function () {
$("#header div.site-links a.menu").on('click touchstart', function (event) {
$(this).closest("div.site-links").toggleClass("open");
event.preventDefault();
});
}
}
};

$(Page.SiteLinks.highlight);
$(Page.SiteLinks.menu);
23 changes: 10 additions & 13 deletions javascripts/examples.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"use strict";
var Examples = {
names: ['cities', 'greeter', 'i_love_ruby', 'hello_world'],

random: function() {
return Examples.names[Math.floor(Math.random() * Examples.names.length)];
},

choose: function() {
var lang = document.location.pathname.split('/')[1];
var name = Examples.random();

$("#code").load('/' + lang + '/examples/' + name + '/');
}
names: ['cities', 'greeter', 'i_love_ruby', 'hello_world'],
random: function () {
return Examples.names[Math.floor(Math.random() * Examples.names.length)];
},
choose: function () {
var lang = document.location.pathname.split('/')[1];
var name = Examples.random();
$("#code").load('/' + lang + '/examples/' + name + '/');
}
};

$(document).ready(Examples.choose);
34 changes: 16 additions & 18 deletions javascripts/page.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
"use strict";
var Page = {
SiteLinks: {
highlight: function() {
var current_page = location.pathname;
$("#header div.site-links a:not(.home)").each(function(i) {
if (current_page.indexOf($(this).attr('href')) == 0) {
$(this).addClass('selected');
SiteLinks: {
highlight: function () {
var current_page = location.pathname;
$("#header div.site-links a:not(.home)").each(function (i) {
if (current_page.indexOf($(this).attr('href')) == 0) {
$(this).addClass('selected');
}
});
$("#home-page-layout #header div.site-links a.home").addClass('selected');
},
menu: function () {
$("#header div.site-links a.menu").on('click touchstart', function (event) {
$(this).closest("div.site-links").toggleClass("open");
event.preventDefault();
});
}
});

$("#home-page-layout #header div.site-links a.home").addClass('selected');
},

menu: function() {
$("#header div.site-links a.menu").on('click touchstart', function(event) {
$(this).closest("div.site-links").toggleClass("open");
event.preventDefault();
});
}
}
};

$(Page.SiteLinks.highlight);
$(Page.SiteLinks.menu);
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"outDir": "./javascripts",

"target": "es5",
"strict": true
},
"include": ["./_javascripts_src/**/*"]
}