Skip to content

Commit 9c916c3

Browse files
committed
Setup dev env (rake starts everything that is needed).
1 parent 009a387 commit 9c916c3

20 files changed

+170
-116
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*.txt
2-
prototype.rb
2+
unversioned

.rvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rvm $(rvm list|grep ruby-1.9.3-p0-patched > /dev/null && echo 'ruby-1.9.3-p0-patched' || echo 'ruby-1.9')@macruby-docs-js --create

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
gem 'sinatra'
3+
gem 'foreman'

Gemfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
foreman (0.46.0)
5+
thor (>= 0.13.6)
6+
rack (1.4.1)
7+
rack-protection (1.2.0)
8+
rack
9+
sinatra (1.3.2)
10+
rack (~> 1.3, >= 1.3.6)
11+
rack-protection (~> 1.2)
12+
tilt (~> 1.3, >= 1.3.3)
13+
thor (0.15.2)
14+
tilt (1.3.3)
15+
16+
PLATFORMS
17+
ruby
18+
19+
DEPENDENCIES
20+
foreman
21+
sinatra

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coffee: script/coffee_watcher
2+
dev_web_server: script/dev_web_server

Rakefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
task :default do
2+
system("foreman start")
3+
end
4+
5+
task :spec do
6+
if File.exists?("/Users")
7+
system("open run_specs.html")
8+
else
9+
puts "Open 'run_specs.html' to run the specs."
10+
end
11+
end
12+
13+
task :release do
14+
cmd = "cp lib/macruby-docs.js lib/macruby-docs.stable.js"
15+
puts "Running: #{cmd}"
16+
system(cmd)
17+
end

src/declaration.coffee renamed to lib/macruby-docs.coffee

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,36 @@ class Declaration
4747
[ value, type ] = arg.match(pattern)[1..2].reverse()
4848
[ "#{key}: #{value}", type ]
4949

50+
class DocRenderer
51+
constructor: (@declaration) ->
52+
53+
render: ->
54+
"text"
55+
56+
if !window.in_tests
57+
addJQuery = (callback) ->
58+
script = document.createElement("script")
59+
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js")
60+
61+
addScriptToPage = ->
62+
script = document.createElement("script")
63+
script.textContent = "(" + callback.toString() + ")();"
64+
document.body.appendChild(script)
65+
66+
script.addEventListener 'load', addScriptToPage, false
67+
document.body.appendChild(script)
68+
69+
main = ->
70+
$.noConflict()
71+
check = ->
72+
try
73+
className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0]
74+
jQuery.each jQuery(".declaration", window.parent.frames[0].document), (i, element) ->
75+
content = element.innerHTML
76+
if content.indexOf("MacRuby") == -1
77+
element.innerHTML = element.innerHTML + "<br/><br/><h5>MacRuby</h5>" + new DocRenderer(content).render()
78+
catch err
79+
console.log(err)
80+
81+
setInterval(check, 3000)
82+
addJQuery(main)

src/declaration.js renamed to lib/macruby-docs.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Declaration;
1+
var Declaration, DocRenderer, addJQuery, main;
22
Declaration = (function() {
33
function Declaration(declaration) {
44
this.declaration = declaration;
@@ -51,4 +51,48 @@ Declaration = (function() {
5151
}
5252
};
5353
return Declaration;
54-
})();
54+
})();
55+
DocRenderer = (function() {
56+
function DocRenderer(declaration) {
57+
this.declaration = declaration;
58+
}
59+
DocRenderer.prototype.render = function() {
60+
return "text";
61+
};
62+
return DocRenderer;
63+
})();
64+
if (!window.in_tests) {
65+
addJQuery = function(callback) {
66+
var addScriptToPage, script;
67+
script = document.createElement("script");
68+
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
69+
addScriptToPage = function() {
70+
script = document.createElement("script");
71+
script.textContent = "(" + callback.toString() + ")();";
72+
return document.body.appendChild(script);
73+
};
74+
script.addEventListener('load', addScriptToPage, false);
75+
return document.body.appendChild(script);
76+
};
77+
main = function() {
78+
var check;
79+
$.noConflict();
80+
check = function() {
81+
var className;
82+
try {
83+
className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0];
84+
return jQuery.each(jQuery(".declaration", window.parent.frames[0].document), function(i, element) {
85+
var content;
86+
content = element.innerHTML;
87+
if (content.indexOf("MacRuby") === -1) {
88+
return element.innerHTML = element.innerHTML + "<br/><br/><h5>MacRuby</h5>" + new DocRenderer(content).render();
89+
}
90+
});
91+
} catch (err) {
92+
return console.log(err);
93+
}
94+
};
95+
return setInterval(check, 3000);
96+
};
97+
addJQuery(main);
98+
}

macruby-docs.user.js

Lines changed: 3 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
2-
// @name Translate Objective-C Docs to MacRuby
2+
// @name MacRuby Docs JS - Adds MacRuby/RubyMotion syntax to Apple's Objective-C/Cocoa docs.
33
// @namespace http://twitter.com/joakimk
4-
// @description Inserts MacRuby / RubyMotion syntax below Obj-c declarations in Apple documentation.
4+
// @description Adds MacRuby/RubyMotion syntax to Apple's Objective-C/Cocoa docs.
55
// @include http://developer.apple.com/library/mac/*
66
// @include https://developer.apple.com/library/mac/*
77
// @version 1.0
@@ -18,108 +18,7 @@
1818
};
1919

2020
var load_latest = function() {
21-
//require("https://raw.github.com/joakimk/macruby-docs-js/master/dist/latest.js");
22-
////
23-
//////////
24-
25-
function addJQuery(callback) {
26-
var script = document.createElement("script");
27-
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
28-
script.addEventListener('load', function() {
29-
var script = document.createElement("script");
30-
script.textContent = "(" + callback.toString() + ")();";
31-
document.body.appendChild(script);
32-
}, false);
33-
document.body.appendChild(script);
34-
}
35-
36-
function main() {
37-
$.noConflict()
38-
//alert("There are " + $('a').length + " links on this page.");
39-
40-
function check()
41-
{
42-
var Declaration;
43-
Declaration = (function() {
44-
function Declaration(declaration) {
45-
this.declaration = declaration;
46-
}
47-
Declaration.prototype.returnType = function() {
48-
var pattern;
49-
pattern = /.\((.+?)\)/;
50-
return this.declaration.match(pattern)[1];
51-
};
52-
Declaration.prototype.methodName = function() {
53-
var pattern;
54-
pattern = /.+?\)(.+?):/;
55-
return this.declaration.match(pattern)[1];
56-
};
57-
Declaration.prototype.isInstanceMethod = function() {
58-
var pattern;
59-
pattern = /-.+/;
60-
return !!this.declaration.match(pattern);
61-
};
62-
Declaration.prototype.parameters = function() {
63-
var parameter, parameters, pattern, _i, _len, _results;
64-
pattern = /.+?:(.+)/;
65-
parameters = this.declaration.match(pattern)[1].replace(new RegExp(" \\*", "g"), "#*").split(' ');
66-
parameters = (function() {
67-
var _i, _len, _results;
68-
_results = [];
69-
for (_i = 0, _len = parameters.length; _i < _len; _i++) {
70-
parameter = parameters[_i];
71-
_results.push(parameter.replace('#*', ' *'));
72-
}
73-
return _results;
74-
})();
75-
_results = [];
76-
for (_i = 0, _len = parameters.length; _i < _len; _i++) {
77-
parameter = parameters[_i];
78-
_results.push(this.mapParameter(parameter));
79-
}
80-
return _results;
81-
};
82-
Declaration.prototype.mapParameter = function(parameter) {
83-
var arg, key, pattern, type, value, _ref, _ref2;
84-
if (parameter[0] === "(") {
85-
pattern = /\((.+?)\)(.+)/;
86-
return parameter.match(pattern).slice(1, 3).reverse();
87-
} else {
88-
pattern = /\((.+?)\)(.+)/;
89-
_ref = parameter.split(':'), key = _ref[0], arg = _ref[1];
90-
_ref2 = arg.match(pattern).slice(1, 3).reverse(), value = _ref2[0], type = _ref2[1];
91-
return ["" + key + ": " + value, type];
92-
}
93-
};
94-
return Declaration;
95-
})();
96-
97-
try {
98-
className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0];
99-
jQuery.each(jQuery(".declaration", window.parent.frames[0].document), function(i, element) {
100-
content = element.innerHTML;
101-
if(content.indexOf("MacRuby") == -1) {
102-
dec = new Declaration(element.textContent)
103-
try {
104-
element.innerHTML = element.innerHTML + "<br/><br/><h5>MacRuby:</h5>" + className + dec.methodName();
105-
}
106-
catch(err2) {
107-
}
108-
}
109-
});
110-
}
111-
catch(err) {
112-
console.log(err)
113-
}
114-
}
115-
116-
setInterval(check, 3000);
117-
}
118-
119-
// load jQuery and execute the main function
120-
addJQuery(main);
121-
//////////
122-
21+
require("https://raw.github.com/joakimk/macruby-docs-js/master/lib/macruby-docs.stable.js");
12322
};
12423

12524
load_latest();

SpecRunner.html renamed to run_specs.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
<head>
55
<title>Jasmine Spec Runner</title>
66

7-
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0.rc3/jasmine_favicon.png">
8-
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0.rc3/jasmine.css">
9-
<script type="text/javascript" src="lib/jasmine-1.2.0.rc3/jasmine.js"></script>
10-
<script type="text/javascript" src="lib/jasmine-1.2.0.rc3/jasmine-html.js"></script>
7+
<link rel="shortcut icon" type="image/png" href="tools/jasmine-1.2.0.rc3/jasmine_favicon.png">
8+
<link rel="stylesheet" type="text/css" href="tools/jasmine-1.2.0.rc3/jasmine.css">
9+
<script type="text/javascript" src="tools/jasmine-1.2.0.rc3/jasmine.js"></script>
10+
<script type="text/javascript" src="tools/jasmine-1.2.0.rc3/jasmine-html.js"></script>
1111

1212
<!-- include source files here... -->
13-
<script type="text/javascript" src="src/declaration.js"></script>
13+
<script type="text/javascript">
14+
window.in_tests = true;
15+
</script>
16+
<script type="text/javascript" src="lib/macruby-docs.js"></script>
1417

1518
<!-- include spec files here... -->
16-
<script type="text/javascript" src="spec/declaration_spec.js"></script>
19+
<script type="text/javascript" src="spec/macruby-docs.js"></script>
1720

1821
<script type="text/javascript">
1922
(function() {
@@ -40,9 +43,6 @@
4043
function execJasmine() {
4144
jasmineEnv.execute();
4245
}
43-
44-
setTimeout("window.location.reload()", 500)
45-
4646
})();
4747
</script>
4848

0 commit comments

Comments
 (0)