Permalink
Browse files

Add support to fdoc for custom github-links via -github-repo option.

Example usage:
$ fdoc -github-repo bakkdoor/redis.fy lib/redis.fy
  • Loading branch information...
1 parent 6849538 commit ae0d6c92f608d8a52d85e57a5486da7502f765f5 @bakkdoor committed Jun 17, 2012
Showing with 33 additions and 12 deletions.
  1. +22 −9 doc/api/fdoc.js
  2. +11 −3 lib/fdoc.fy
View
@@ -4,12 +4,23 @@
var fancy = {};
window.fancy = fancy;
- /* A function to set the documentation json */
var docs;
- fancy.fdoc = function(_docs) { docs = _docs; }
+ var addGithubLinks = false;
+ var githubRepo;
+
+ /* A function to set the documentation json */
+ fancy.fdoc = function(_addGithubLinks, _githubRepo, _docs) {
+ addGithubLinks = _addGithubLinks;
+ if(_addGithubLinks) {
+ if(_githubRepo) {
+ githubRepo = _githubRepo;
+ }
+ }
+ docs = _docs;
+ }
var github_src = function(file, lines) {
- return "http://github.com/bakkdoor/fancy/blob/master/"+file+"#L"+lines[0]+"-L"+lines[1];
+ return "http://github.com/"+githubRepo+"/blob/master/"+file+"#L"+lines[0]+"-L"+lines[1];
}
@@ -80,12 +91,14 @@
var content = $("<div>").addClass("docs").addClass("ui-widget-content").html(mdoc.doc || "Not documented").appendTo(method);
if(mdoc.file && /\.fy$/.test(mdoc.file)) {
- $("<a>").attr("href", github_src(mdoc.file, mdoc.lines)).
- attr("target", "_blank").
- attr("title", "Source at GitHub").
- append(
- $("<img>").attr("src", "http://static.tumblr.com/vwpvxmx/5Wclbbqbj/github.png")
- ).addClass("github").appendTo(signature)
+ if(addGithubLinks) {
+ $("<a>").attr("href", github_src(mdoc.file, mdoc.lines)).
+ attr("target", "_blank").
+ attr("title", "Source at GitHub").
+ append(
+ $("<img>").attr("src", "octocat.png")
+ ).addClass("github").appendTo(signature)
+ }
}
});
});
View
@@ -35,6 +35,8 @@ class Fancy FDoc {
output_dir = OUTPUT_DIR
with_stdlib = false
+ add_github_links = false
+ github_repo = "bakkdoor/fancy"
OptionParser new: @{
remove_after_parsed: true
@@ -44,6 +46,11 @@ class Fancy FDoc {
output_dir = dir
}
+ with: "-github-repo [repo_url]" doc: "Sets the Github repository to link to method definitions." do: |url| {
+ github_repo = url
+ add_github_links = true
+ }
+
with: "--with-stdlib" doc: "Include Fancy's standard library in generated documentation" do: {
with_stdlib = true
}
@@ -59,6 +66,7 @@ class Fancy FDoc {
if: (output_dir relative_path: "../" == FANCY_ROOT_DIR) then: {
# add stdlib by default when in FANCY_ROOT_DIR
with_stdlib = true
+ add_github_links = true
} else: {
files = Dir list: "#{FANCY_ROOT_DIR}/doc/api/*" . reject: |f| { f =~ /fancy\.jsonp$/ }
FileUtils cp(files, output_dir)
@@ -76,7 +84,7 @@ class Fancy FDoc {
@documented_objects = @documented_objects select_keys: |k| { @objects_to_remove includes?: k . not }
# by now simply produce a apidoc/fancy.jsonp file.
- json = JSON new: @documented_objects
+ json = JSON new: @documented_objects add_github_links: add_github_links github_repo: github_repo
json write: (File expand_path("fancy.jsonp", output_dir))
["Open your browser at " ++ output_dir ++ "index.html ",
@@ -90,7 +98,7 @@ class Fancy FDoc {
read_slots: ['classes, 'methods, 'blocks, 'objects]
- def initialize: documented {
+ def initialize: documented add_github_links: @add_github_links github_repo: @github_repo {
@documented_objects = documented
is_class = |o| { o kind_of?: Module }
@@ -212,7 +220,7 @@ class Fancy FDoc {
def write: filename call: name ("fancy.fdoc") {
map = generate_map
json = to_json: map
- js = "(function() { " ++ name ++ "(" ++ json ++ "); })();"
+ js = "(function() { #{name}(#{@add_github_links}, #{@github_repo inspect}, #{json}); })();"
File open: filename modes: ['write] with: |out| { out print: js }
}

0 comments on commit ae0d6c9

Please sign in to comment.