diff --git a/.gitignore b/.gitignore index 378bf22..d10c33a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.txt -prototype.rb +unversioned diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000..82351bc --- /dev/null +++ b/.rvmrc @@ -0,0 +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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..39a07c0 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' +gem 'sinatra' +gem 'foreman' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..6a17e9a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,21 @@ +GEM + remote: https://rubygems.org/ + specs: + foreman (0.46.0) + thor (>= 0.13.6) + rack (1.4.1) + rack-protection (1.2.0) + rack + sinatra (1.3.2) + rack (~> 1.3, >= 1.3.6) + rack-protection (~> 1.2) + tilt (~> 1.3, >= 1.3.3) + thor (0.15.2) + tilt (1.3.3) + +PLATFORMS + ruby + +DEPENDENCIES + foreman + sinatra diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..6738c53 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +coffee: script/coffee_watcher +dev_web_server: script/dev_web_server diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..228685c --- /dev/null +++ b/Rakefile @@ -0,0 +1,17 @@ +task :default do + system("foreman start") +end + +task :spec do + if File.exists?("/Users") + system("open run_specs.html") + else + puts "Open 'run_specs.html' to run the specs." + end +end + +task :release do + cmd = "cp lib/macruby-docs.js lib/macruby-docs.stable.js" + puts "Running: #{cmd}" + system(cmd) +end diff --git a/src/declaration.coffee b/lib/macruby-docs.coffee similarity index 51% rename from src/declaration.coffee rename to lib/macruby-docs.coffee index 7d9692e..4696968 100644 --- a/src/declaration.coffee +++ b/lib/macruby-docs.coffee @@ -47,3 +47,36 @@ class Declaration [ value, type ] = arg.match(pattern)[1..2].reverse() [ "#{key}: #{value}", type ] +class DocRenderer + constructor: (@declaration) -> + + render: -> + "text" + +if !window.in_tests + addJQuery = (callback) -> + script = document.createElement("script") + script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js") + + addScriptToPage = -> + script = document.createElement("script") + script.textContent = "(" + callback.toString() + ")();" + document.body.appendChild(script) + + script.addEventListener 'load', addScriptToPage, false + document.body.appendChild(script) + + main = -> + $.noConflict() + check = -> + try + className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0] + jQuery.each jQuery(".declaration", window.parent.frames[0].document), (i, element) -> + content = element.innerHTML + if content.indexOf("MacRuby") == -1 + element.innerHTML = element.innerHTML + "

MacRuby
" + new DocRenderer(content).render() + catch err + console.log(err) + + setInterval(check, 3000) + addJQuery(main) diff --git a/src/declaration.js b/lib/macruby-docs.js similarity index 53% rename from src/declaration.js rename to lib/macruby-docs.js index b71a0e0..149e9ab 100644 --- a/src/declaration.js +++ b/lib/macruby-docs.js @@ -1,4 +1,4 @@ -var Declaration; +var Declaration, DocRenderer, addJQuery, main; Declaration = (function() { function Declaration(declaration) { this.declaration = declaration; @@ -51,4 +51,48 @@ Declaration = (function() { } }; return Declaration; -})(); \ No newline at end of file +})(); +DocRenderer = (function() { + function DocRenderer(declaration) { + this.declaration = declaration; + } + DocRenderer.prototype.render = function() { + return "text"; + }; + return DocRenderer; +})(); +if (!window.in_tests) { + addJQuery = function(callback) { + var addScriptToPage, script; + script = document.createElement("script"); + script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); + addScriptToPage = function() { + script = document.createElement("script"); + script.textContent = "(" + callback.toString() + ")();"; + return document.body.appendChild(script); + }; + script.addEventListener('load', addScriptToPage, false); + return document.body.appendChild(script); + }; + main = function() { + var check; + $.noConflict(); + check = function() { + var className; + try { + className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0]; + return jQuery.each(jQuery(".declaration", window.parent.frames[0].document), function(i, element) { + var content; + content = element.innerHTML; + if (content.indexOf("MacRuby") === -1) { + return element.innerHTML = element.innerHTML + "

MacRuby
" + new DocRenderer(content).render(); + } + }); + } catch (err) { + return console.log(err); + } + }; + return setInterval(check, 3000); + }; + addJQuery(main); +} \ No newline at end of file diff --git a/macruby-docs.user.js b/macruby-docs.user.js index b52b806..72c7762 100644 --- a/macruby-docs.user.js +++ b/macruby-docs.user.js @@ -1,7 +1,7 @@ // ==UserScript== -// @name Translate Objective-C Docs to MacRuby +// @name MacRuby Docs JS - Adds MacRuby/RubyMotion syntax to Apple's Objective-C/Cocoa docs. // @namespace http://twitter.com/joakimk -// @description Inserts MacRuby / RubyMotion syntax below Obj-c declarations in Apple documentation. +// @description Adds MacRuby/RubyMotion syntax to Apple's Objective-C/Cocoa docs. // @include http://developer.apple.com/library/mac/* // @include https://developer.apple.com/library/mac/* // @version 1.0 @@ -18,108 +18,7 @@ }; var load_latest = function() { - //require("https://raw.github.com/joakimk/macruby-docs-js/master/dist/latest.js"); -//// -////////// - -function addJQuery(callback) { - var script = document.createElement("script"); - script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); - script.addEventListener('load', function() { - var script = document.createElement("script"); - script.textContent = "(" + callback.toString() + ")();"; - document.body.appendChild(script); - }, false); - document.body.appendChild(script); -} - -function main() { - $.noConflict() - //alert("There are " + $('a').length + " links on this page."); - - function check() - { -var Declaration; -Declaration = (function() { - function Declaration(declaration) { - this.declaration = declaration; - } - Declaration.prototype.returnType = function() { - var pattern; - pattern = /.\((.+?)\)/; - return this.declaration.match(pattern)[1]; - }; - Declaration.prototype.methodName = function() { - var pattern; - pattern = /.+?\)(.+?):/; - return this.declaration.match(pattern)[1]; - }; - Declaration.prototype.isInstanceMethod = function() { - var pattern; - pattern = /-.+/; - return !!this.declaration.match(pattern); - }; - Declaration.prototype.parameters = function() { - var parameter, parameters, pattern, _i, _len, _results; - pattern = /.+?:(.+)/; - parameters = this.declaration.match(pattern)[1].replace(new RegExp(" \\*", "g"), "#*").split(' '); - parameters = (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = parameters.length; _i < _len; _i++) { - parameter = parameters[_i]; - _results.push(parameter.replace('#*', ' *')); - } - return _results; - })(); - _results = []; - for (_i = 0, _len = parameters.length; _i < _len; _i++) { - parameter = parameters[_i]; - _results.push(this.mapParameter(parameter)); - } - return _results; - }; - Declaration.prototype.mapParameter = function(parameter) { - var arg, key, pattern, type, value, _ref, _ref2; - if (parameter[0] === "(") { - pattern = /\((.+?)\)(.+)/; - return parameter.match(pattern).slice(1, 3).reverse(); - } else { - pattern = /\((.+?)\)(.+)/; - _ref = parameter.split(':'), key = _ref[0], arg = _ref[1]; - _ref2 = arg.match(pattern).slice(1, 3).reverse(), value = _ref2[0], type = _ref2[1]; - return ["" + key + ": " + value, type]; - } - }; - return Declaration; -})(); - - try { - className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0]; - jQuery.each(jQuery(".declaration", window.parent.frames[0].document), function(i, element) { - content = element.innerHTML; - if(content.indexOf("MacRuby") == -1) { - dec = new Declaration(element.textContent) - try { - element.innerHTML = element.innerHTML + "

MacRuby:
" + className + dec.methodName(); - } - catch(err2) { - } - } - }); - } - catch(err) { - console.log(err) - } - } - - setInterval(check, 3000); -} - -// load jQuery and execute the main function -addJQuery(main); -////////// - + require("https://raw.github.com/joakimk/macruby-docs-js/master/lib/macruby-docs.stable.js"); }; load_latest(); diff --git a/SpecRunner.html b/run_specs.html similarity index 61% rename from SpecRunner.html rename to run_specs.html index 15966a7..8d219a6 100644 --- a/SpecRunner.html +++ b/run_specs.html @@ -4,16 +4,19 @@ Jasmine Spec Runner - - - - + + + + - + + - + diff --git a/watch_for_changes.sh b/script/coffee_watcher similarity index 100% rename from watch_for_changes.sh rename to script/coffee_watcher diff --git a/script/dev_web_server b/script/dev_web_server new file mode 100755 index 0000000..b3f9d23 --- /dev/null +++ b/script/dev_web_server @@ -0,0 +1,2 @@ +#!/bin/sh +bundle exec ruby tools/dev_web_server.rb diff --git a/spec/declaration_spec.js b/spec/macruby-docs.js similarity index 100% rename from spec/declaration_spec.js rename to spec/macruby-docs.js diff --git a/spec/declaration_spec.coffee b/spec/macruby-docs_spec.coffee similarity index 100% rename from spec/declaration_spec.coffee rename to spec/macruby-docs_spec.coffee diff --git a/tools/dev_web_server.rb b/tools/dev_web_server.rb new file mode 100644 index 0000000..243f4f3 --- /dev/null +++ b/tools/dev_web_server.rb @@ -0,0 +1,7 @@ +require 'sinatra' + +set :port, 55444 + +get "/dev.js" do + send_file "lib/macruby-docs.js" +end diff --git a/lib/jasmine-1.2.0.rc3/MIT.LICENSE b/tools/jasmine-1.2.0.rc3/MIT.LICENSE similarity index 100% rename from lib/jasmine-1.2.0.rc3/MIT.LICENSE rename to tools/jasmine-1.2.0.rc3/MIT.LICENSE diff --git a/lib/jasmine-1.2.0.rc3/jasmine-html.js b/tools/jasmine-1.2.0.rc3/jasmine-html.js similarity index 100% rename from lib/jasmine-1.2.0.rc3/jasmine-html.js rename to tools/jasmine-1.2.0.rc3/jasmine-html.js diff --git a/lib/jasmine-1.2.0.rc3/jasmine.css b/tools/jasmine-1.2.0.rc3/jasmine.css similarity index 100% rename from lib/jasmine-1.2.0.rc3/jasmine.css rename to tools/jasmine-1.2.0.rc3/jasmine.css diff --git a/lib/jasmine-1.2.0.rc3/jasmine.js b/tools/jasmine-1.2.0.rc3/jasmine.js similarity index 100% rename from lib/jasmine-1.2.0.rc3/jasmine.js rename to tools/jasmine-1.2.0.rc3/jasmine.js diff --git a/tools/macruby-docs-dev.user.js b/tools/macruby-docs-dev.user.js new file mode 100644 index 0000000..1be112d --- /dev/null +++ b/tools/macruby-docs-dev.user.js @@ -0,0 +1,25 @@ +// ==UserScript== +// @name MacRuby Docs JS - DEV version. +// @namespace http://twitter.com/joakimk +// @description +// @include http://developer.apple.com/library/mac/* +// @include https://developer.apple.com/library/mac/* +// @version 1.0 +// ==/UserScript== + +(function() { + var head = document.getElementsByTagName("head")[0]; + + var require = function(src) { + var script = document.createElement("script"); + script.setAttribute("language", "javascript"); + script.setAttribute("src", src); + head.appendChild(script); + }; + + var load_latest = function() { + require("http://localhost:55444/dev.js"); + }; + + load_latest(); +})();