Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
Own sitemap loader thing
Browse files Browse the repository at this point in the history
  • Loading branch information
paul committed Jul 31, 2012
1 parent 4bfe0c8 commit d15a941
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 71 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -2,6 +2,7 @@ source :rubygems

gem "middleman", "~>3.0.0"
gem "activesupport", "~>3.2.0"
gem "github-markdown"

gem "awesome_print", :require => "ap"
gem "prissy"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -19,6 +19,7 @@ GEM
fattr (2.2.1)
ffi (1.1.0)
fssm (0.2.9)
github-markdown (0.5.0)
haml (3.1.6)
hike (1.2.1)
http_router (0.10.2)
Expand Down Expand Up @@ -116,5 +117,6 @@ PLATFORMS
DEPENDENCIES
activesupport (~> 3.2.0)
awesome_print
github-markdown
middleman (~> 3.0.0)
prissy
48 changes: 1 addition & 47 deletions config.rb
@@ -1,51 +1,5 @@
###
# Compass
###

# Susy grids in Compass
# First: gem install compass-susy-plugin
# require 'susy'

# Change Compass configuration
# compass_config do |config|
# config.output_style = :compact
# end

###
# Page options, layouts, aliases and proxies
###

# Per-page layout changes:
#
# With no layout
# page "/path/to/file.html", :layout => false
#
# With alternative layout
# page "/path/to/file.html", :layout => :otherlayout
#
# A path which all have the same layout
# with_layout :admin do
# page "/admin/*"
# end

# Proxy (fake) files
# page "/this-page-has-no-template.html", :proxy => "/template-file.html" do
# @which_fake_page = "Rendering a fake page with a variable"
# end

###
# Helpers
###

# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes

# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
set :markdown_engine, :github_markup

set :css_dir, 'stylesheets'

Expand Down
53 changes: 43 additions & 10 deletions lib/doc_helpers.rb
Expand Up @@ -10,11 +10,11 @@ def all_pages
end
end

def pages_by_category

def pages_for_toc
pages_by_category = {}
sitemap.resources.group_by { |page| page.data["category"] }.each do |category, pages|
group_by_sorted_category(all_pages).each do |category, pages|
next if category.nil? # Skip pages that don't have "category" metadata
next if category == "."
pages_by_category[category] = sort_pages(pages).select { |p| p.path !~ /index/ }
end

Expand All @@ -24,9 +24,10 @@ def pages_by_category
def pages_for_quick_ref
pages_for_quick_ref = {}

sitemap.resources.group_by { |page| page.data["category"] }.each do |category, pages|
group_by_sorted_category(all_pages).each do |category, pages|
next if category.nil? # Skip pages that don't have "category" metadata
next if category == "summary"
next if category == "summary" # Skip the summary pages in the quick reference
next if category == "."
pages_for_quick_ref[category] = sort_pages(pages).select { |p| p.path !~ /index/ && p.path !~ /representation/ }
end

Expand All @@ -36,32 +37,64 @@ def pages_for_quick_ref

HTTP_METHOD_SORT_ORDER = %w[GET POST PUT PATCH DELETE]

def group_by_sorted_category(pages)
pages_by_category = {}

pages.each do |page|
category = page_category(page)
next if category.nil?
pages_by_category[category] ||= []
pages_by_category[category] << page
end

sorted = pages_by_category.sort_by do |key, value|
key..to_s == "summary" ? -1 : key
end

Hash[sorted]
end


def sort_pages(pages)
pages.sort_by do |page|
[ page.data["category"],
if page.path =~ /index/
filepath, filename = File.split(page.path)
category = filepath.split(File::Separator).last

# First, order by category
res = [ category,
if filename =~ /index/
# Index always comes first
-10

elsif page.path =~ /representation/
elsif filename =~ /representation/
# Representation comes next
-5

elsif page.data["sort_order"]
# If the page metadata specifies a sort order, do that
page.data["sort_order"]

else
# Otherwise, guess by url length and http method
elsif page.data["endpoint"]
# url length and http method
endpoint = page.data["endpoint"].length
method = HTTP_METHOD_SORT_ORDER.index(page.data["method"] || page.data["methods"].first)

endpoint * 10 + method

else
# Otherwise, alphabetic by filename
filename.to_i
end
]

p res
res

end
end

def page_category(page)
File.split(page.path).first.split(File::Separator).last
end
end

56 changes: 55 additions & 1 deletion lib/doctaur.rb
Expand Up @@ -7,6 +7,12 @@ def registered(app)
template_extensions :doctaur => :html
end

app.after_configuration do
sitemap.register_resource_list_manipulator(:representations,
Doctaur::RepresentationManipulator.new(self),
false)
end

app.helpers Doctaur::Helpers
end
alias included registered
Expand Down Expand Up @@ -36,6 +42,53 @@ def represent(name, options = {}, &block)

end

class RepresentationManipulator

def initialize(app)
@app = app
end

def manipulate_resource_list(resources)
resources.each do |resource|
resource.extend PageExtensions

if resource.source_file =~ /doctaur$/
resource.extend RepresentationResource
end

category = File.split(resource.path).first.split(File::Separator).last
resource.add_metadata(page: {category: category}) if category
end
end
end

module PageExtensions
def title
data["title"]
end

def anchor
data["title"].underscore
end

def category
# foo/bar/baz.html.mkd #-> "bar"
data["category"] || File.split(path).first.split(File::Separator).last
end
end

module RepresentationResource

def title
"Representation"
end

def anchor
"#{category}_representation"
end

end

class Representation
attr_reader :name

Expand Down Expand Up @@ -79,7 +132,8 @@ def locals
:name => name,
:attributes => attributes,
:links => links,
:example => example
:example => example,
:anchor => anchor
}
end

Expand Down
4 changes: 2 additions & 2 deletions source/_toc.html.haml
Expand Up @@ -2,12 +2,12 @@
%h1 Table of Contents

%ul.categories
- pages_by_category.each do |category, pages|
- pages_for_toc.each do |category, pages|
%li.category
= link_to category.titlecase, "##{category}"

- unless pages.empty?
%ul.pages
- pages.each do |page|
%li.page
= link_to page.data["title"], "##{page.data["title"].underscore.gsub(' ', '_')}"
= link_to page.title, "##{page.anchor}"
7 changes: 7 additions & 0 deletions source/index.html.haml
Expand Up @@ -5,3 +5,10 @@ category: summary

%h1 GitHub API

This describes the resources that make up the official GitHub API v3. If
you have any problems or requests please contact
[support](mailto:support@github.com?subject=APIv3).

View the [API Changelog](/v3/changelog) for information on existing and
planned changes to the API.

120 changes: 120 additions & 0 deletions source/summary/libraries.mkd
@@ -0,0 +1,120 @@
---
sort_order: 5
title: Libraries
---

# Libraries

Libraries for accessing the GitHub API from your favorite language.

## ActionScript

* [ActionScript GitHub API][as3]

[as3]: https://github.com/cbrammer/api-github-as3

## Clojure

* [Tentacles][tentacles]

[tentacles]: https://github.com/Raynes/tentacles

## CSharp

* [CSharp GitHub API][csharp]

[csharp]: https://github.com/sgrassie/csharp-github-api

## Erlang

* [Erlang GitHub API][erlang]

[erlang]: https://github.com/onlyshk/erlang-github-api

## Haskell

* [Haskell GitHub API][haskell]

[haskell]: https://github.com/dmnpignaud/haskell-github-api

## Java

The [GitHub Java API](https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core) library
is part of the [GitHub Mylyn Connector](https://github.com/eclipse/egit-github) and aims to support the entire
GitHub v3 API. Builds are available in [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22org.eclipse.egit.github.core%22).

## Javascript

* [Node-GitHub][ajaxorg-node-github]
* [NodeJS GitHub library][octonode]
* [gh3 client-side API v3 wrapper][gh3]

[ajaxorg-node-github]: https://github.com/ajaxorg/node-github
[octonode]: https://github.com/pksunkara/octonode
[gh3]: https://github.com/k33g/gh3

## Objective-C

* [UAGithubEngine][uagithubengine]

[uagithubengine]: http://github.com/owainhunt/uagithubengine

## Perl

* [Pithub][pithub-github] ([CPAN][pithub-cpan])
* [Net::Github][net-github-github] ([CPAN][net-github-cpan])

[net-github-github]: https://github.com/fayland/perl-net-github
[net-github-cpan]: http://search.cpan.org/~fayland/Net-GitHub-0.30/lib/Net/GitHub.pm
[pithub-github]: https://github.com/plu/Pithub
[pithub-cpan]: http://metacpan.org/module/Pithub

## PHP

* [GitHub API][github-api]
* [PHP GitHub API][php-github-api]
* [GitHub Kohana Module][kohana]

[github-api]: https://github.com/yiiext/github-api
[php-github-api]: https://github.com/ornicar/php-github-api
[kohana]: https://github.com/acoulton/github_v3_api

## Python

* [PyGithub][jacquev6_pygithub]
* [Pygithub3][pygithub3-api]
* [libsaas][libsaas]
* [github3.py][github3py]
* [sanction][sanction]
* [agithub][agithub]

[jacquev6_pygithub]: https://github.com/jacquev6/PyGithub
[pygithub3-api]: https://github.com/copitux/python-github3
[libsaas]: https://github.com/ducksboard/libsaas
[github3py]: https://github.com/sigmavirus24/github3.py
[sanction]: https://github.com/demianbrecht/sanction
[agithub]: https://github.com/jpaugh64/agithub "Agnostic Github"

## Ruby

* [Octokit][octokit]
* [GitHub API Gem][ghapi]
* [Octocat Herder][herder]
* [GitHub v3 API][ruby1]
* [GitHub API Client][ruby2]
* [Ghee][ghee]

[octokit]: https://github.com/pengwynn/octokit
[herder]: https://github.com/jhelwig/octocat_herder
[ghapi]: https://github.com/peter-murach/github
[ruby1]: https://github.com/jwilger/github-v3-api
[ruby2]: https://github.com/okonski/github-api-client
[ghee]: https://github.com/rauhryan/ghee

## Scala

* [Dispatch GitHub][scala]

[scala]: https://github.com/andreazevedo/dispatch-github


0 comments on commit d15a941

Please sign in to comment.