Permalink
Browse files

Many more improvements

  • Loading branch information...
1 parent cc0f96b commit 640cec9de37c1e83e6510ce98c03ad9344e10815 @wycats committed May 31, 2010
Showing 2,264 changed files with 254,594 additions and 78 deletions.
View
@@ -2,4 +2,5 @@
db/*.sqlite3
log/*.log
tmp/**/*
+*.css
.yardoc
View
28 Gemfile
@@ -1,13 +1,25 @@
source 'http://rubygems.org'
-gem 'rails', '3.0.0.beta3'
-
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
-
-gem 'sqlite3-ruby', :require => 'sqlite3'
-
-gem 'yard'
+path "vendor/rails" do
+ gem 'rails'
+ gem 'actionpack'
+ gem 'activesupport'
+ gem 'actionmailer'
+ gem 'activeresource'
+ gem 'activemodel'
+ gem 'railties'
+end
+
+gem 'sqlite3-ruby'
+
+path "vendor/yard" do
+ gem 'yard', '0.5.5.wycats'
+end
+
+gem 'haml', '~> 3.1.0'
+gem 'compass', '~> 0.11.alpha'
+gem 'coderay'
+gem 'bluecloth'
# Use unicorn as the web server
# gem 'unicorn'
View
@@ -0,0 +1,98 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ arel (0.3.3)
+ activesupport (>= 3.0.0.beta)
+ bluecloth (2.0.7)
+ builder (2.1.2)
+ bundler (0.10.pre)
+ coderay (0.9.3)
+ compass (0.11.alpha.0.845b790)
+ haml (>= 3.0.4)
+ erubis (2.6.5)
+ abstract (>= 1.0.0)
+ haml (3.1.0)
+ i18n (0.4.0)
+ mail (2.2.1)
+ activesupport (>= 2.3.4)
+ mime-types
+ treetop (>= 1.4.5)
+ memcache-client (1.8.3)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.1.0)
+ rack-mount (0.6.3)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rake (0.8.7)
+ sqlite3-ruby (1.2.5)
+ text-format (1.0.0)
+ text-hyphen (~> 1.0.0)
+ text-hyphen (1.0.0)
+ thor (0.13.6)
+ treetop (1.4.7)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.22)
+
+PATH
+ remote: /Users/wycats/Code/rails
+ specs:
+ actionmailer (3.0.0.beta3)
+ actionpack (= 3.0.0.beta3)
+ mail (~> 2.2.1)
+ text-format (~> 1.0.0)
+ actionpack (3.0.0.beta3)
+ activemodel (= 3.0.0.beta3)
+ activesupport (= 3.0.0.beta3)
+ erubis (~> 2.6.5)
+ rack (~> 1.1.0)
+ rack-mount (~> 0.6.3)
+ rack-test (~> 0.5.0)
+ activemodel (3.0.0.beta3)
+ activesupport (= 3.0.0.beta3)
+ activerecord (3.0.0.beta3)
+ activemodel (= 3.0.0.beta3)
+ activesupport (= 3.0.0.beta3)
+ arel (~> 0.3.3)
+ activeresource (3.0.0.beta3)
+ activemodel (= 3.0.0.beta3)
+ activesupport (= 3.0.0.beta3)
+ activesupport (3.0.0.beta3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.0)
+ memcache-client (>= 1.7.5)
+ tzinfo (~> 0.3.16)
+ rails (3.0.0.beta3)
+ actionmailer (= 3.0.0.beta3)
+ actionpack (= 3.0.0.beta3)
+ activerecord (= 3.0.0.beta3)
+ activeresource (= 3.0.0.beta3)
+ activesupport (= 3.0.0.beta3)
+ bundler (>= 0.9.19)
+ railties (= 3.0.0.beta3)
+ railties (3.0.0.beta3)
+ actionpack (= 3.0.0.beta3)
+ activesupport (= 3.0.0.beta3)
+ rake (>= 0.8.3)
+ thor (~> 0.13.6)
+
+PATH
+ remote: /Users/wycats/Code/cool_stuff/yard
+ specs:
+ yard (0.5.5.wycats)
+
+DEPENDENCIES
+ actionmailer!
+ actionpack!
+ activemodel!
+ activeresource!
+ activesupport!
+ bluecloth
+ coderay
+ compass (~> 0.11.alpha)
+ haml (~> 3.1.0)
+ rails!
+ railties!
+ sqlite3-ruby
+ yard (= 0.5.5.wycats)!
@@ -0,0 +1,30 @@
+class MainController < ApplicationController
+ def index
+ klass = RailsDocs::Namespace.new(YARD::Registry.at("ActionController::Base"))
+ @class_methods = klass.public_methods(:class)
+ @instance_methods = klass.public_methods(:instance)
+
+ if params[:name]
+ @method = params[:name]
+ name = YARD::Registry.at(params[:name]).parent.path.gsub(/::ClassMethods$/, '')
+ @module = RailsDocs::Namespace.new(YARD::Registry.at(name))
+ @current_class = current_methods(@class_methods).presence
+ @current_instance = current_methods(@instance_methods).presence
+ end
+ end
+
+private
+
+ def current_methods(list)
+ methods = if @module
+ list.select do |m|
+ m.parent.path =~ /#{@module.yard_object}(::ClassMethods)?/
+ end
+ else
+ list
+ end
+
+ methods.uniq_by {|m| m.name }
+ end
+
+end
@@ -1,2 +1,44 @@
module ApplicationHelper
+ def coderay(text)
+ text.gsub(/\<pre(?:\s+lang="(.+?)"(?:\s+data-caption="(.+?)")?)?\>(.+?)\<\/pre\>/m) do
+ contents = $3.strip
+ content_tag :div, :caption => $2, :class => "code_block" do
+ CodeRay.scan(contents, $1).div(:css => :class).html_safe
+ end
+ end
+ end
+
+ def markdown(text)
+ text.gsub!(/\+([\w]+)\+/, "<code>\\1</code>")
+ text.gsub!(/^\s*(=+)(.*)$/) {|m| ("#" * $1.size) + $2 }
+ text.gsub!(/^\s*(Examples?|Parameters|Usage):?\s*$/, "### \\1")
+ super
+ end
+
+ # Override textilize to syntax highlight code blocks in <pre>
+ # TODO double check xss security of this
+ def code_markdown(text)
+ output, current = "", ""
+ s = StringScanner.new(text)
+
+ while char = s.getch
+ current << char
+ if s.peek(4) == "<pre"
+ output << markdown(current)
+ current = ""
+ code = s.scan_until(%r{</pre>})
+ output << coderay(code)
+ elsif s.peek(2) =~ / /m && current =~ /\n\s*\n\Z/
+ output << markdown(current)
+ current = ""
+ code = s.scan_until(%r{(^(?=[^\s])|\Z)})
+ min_tabs = code.scan(/^ +/).min.size
+ code.gsub!(/^ {#{min_tabs}}/, '')
+ lang = code =~ /^\s*<%/ ? "rhtml" : "ruby"
+ output << coderay(%{<pre lang="#{lang}">\n#{code}\n</pre>})
+ end
+ end
+ output << markdown(current) unless current.blank?
+ output.html_safe
+ end
end
View
@@ -0,0 +1,45 @@
+module MainHelper
+ def tree_link(text, options = {})
+ html_class = ["icon"]
+ html_class << "file" if options[:file]
+ html_class << "open" if options[:open]
+ content_tag(:span, "&nbsp;".html_safe, :class => html_class.join(" ")) <<
+ link_to(text)
+ end
+
+ def overview
+ {"ActionController::Base" =>
+ {
+ "Layouts" => "Layouts",
+ "View Helpers" => "Helpers",
+ "Basic Authentication" => "HttpAuthentication::Basic",
+ "Token Authentication" => "HttpAuthentication::Token",
+ "CSRF Mitigation" => "RequestForgeryProtection",
+ "respond_to and respond_with" => "MimeResponds",
+ "Caching" => "Caching",
+ "Action Caching" => "Caching::Actions",
+ "Fragment Caching" => "Caching::Fragments",
+ "Page Caching" => "Caching::Pages",
+ "Cache Sweeping" => "Caching::Sweeping"
+ }
+ }
+ end
+
+ def display_method_signature(meth)
+ param_meth = meth.is_alias? ? meth.parent.child(meth.parent.aliases[meth]) : meth
+
+ params = param_meth.parameters.map do |name, default|
+ default ? "#{name}=#{default}" : name
+ end.join(", ")
+
+ "## #{meth.name}(#{params})\n\n#{param_meth.docstring}\n".html_safe
+ end
+
+ def class_list
+ render :partial => "method", :collection => @class_methods.uniq_by(&:name)
+ end
+
+ def instance_list
+ render :partial => "method", :collection => @instance_methods.uniq_by(&:name)
+ end
+end
@@ -0,0 +1,39 @@
+module RailsDocs
+ class Namespace
+ def initialize(namespace)
+ @namespace = namespace
+ methods = YARD::RailsHelpers.public_api_methods(@namespace)
+ @methods = methods.sort_by(&:name)
+ end
+
+ def public_methods(desired_scope)
+ result = []
+
+ @methods.each do |method|
+ if method.scope == :class
+ result << method if desired_scope == :class
+ elsif desired_scope == :class
+ result << method if method.parent.path =~ /::ClassMethods$/
+ else
+ result << method unless method.parent.path =~ /::ClassMethods$/
+ end
+ end
+
+ result
+ end
+
+ def title
+ if @namespace.has_tag?(:title)
+ @namespace.tag(:title).text
+ elsif @namespace.has_tag?(:purpose)
+ @namespace.tag(:purpose).text
+ else
+ @namespace.name
+ end
+ end
+
+ def yard_object
+ @namespace
+ end
+ end
+end
@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>RailsApi</title>
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
-</head>
-<body>
-
-<%= yield %>
-
-</body>
-</html>
@@ -0,0 +1,15 @@
+!!!5
+%html
+ %head
+ %title Rails API
+ = stylesheet_link_tag 'screen.css', :media => 'screen, projection'
+ = stylesheet_link_tag 'print.css', :media => 'print'
+ = stylesheet_link_tag 'coderay.css', :media => 'print, screen, projection'
+ /[if IE]
+ = stylesheet_link_tag 'ie.css', :media => 'screen, projection'
+ = javascript_include_tag "jquery", "application"
+ = csrf_meta_tag
+
+ %body
+ #page
+ = yield
@@ -0,0 +1,3 @@
+<% @current_class.each do |method| %>
+<%= display_method_signature(method) %>
+<% end %>
@@ -0,0 +1,8 @@
+<% if @module && !@module.yard_object.docstring.empty? %>
+<div class="section-description">
+<h1><%= @module.title %></h1>
+
+<%= preserve code_markdown(@module.yard_object.docstring.html_safe) %>
+
+</div>
+<% end %>
@@ -0,0 +1,3 @@
+<% @current_instance.each do |method| %>
+<%= display_method_signature(method) %>
+<% end %>
@@ -0,0 +1,5 @@
+%li
+ - if @method == method.path
+ %strong= method.name
+ - else
+ = link_to(method.name, method)
Oops, something went wrong.

0 comments on commit 640cec9

Please sign in to comment.