Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Nov 21, 2008
0 parents commit 67dd0e8
Show file tree
Hide file tree
Showing 210 changed files with 46,226 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
@@ -0,0 +1,19 @@
.DS_Store
log/*
tmp/*
TAGS
*~
.#*
schema/schema.rb
schema/*_structure.sql
schema/*.sqlite3
schema/*.sqlite
schema/*.db
*.sqlite
*.sqlite3
*.db
src/*
.hgignore
.hg/*
.svn/*
gems/gems
35 changes: 35 additions & 0 deletions Rakefile
@@ -0,0 +1,35 @@
require 'rubygems'
require 'rake/rdoctask'

require 'merb-core'
require 'merb-core/tasks/merb'

include FileUtils

# Load the basic runtime dependencies; this will include
# any plugins and therefore plugin rake tasks.
init_env = ENV['MERB_ENV'] || 'rake'
Merb.load_dependencies(:environment => init_env)

# Get Merb plugins and dependencies
Merb::Plugins.rakefiles.each { |r| require r }

# Load any app level custom rakefile extensions from lib/tasks
tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks")
rake_files = Dir["#{tasks_path}/*.rake"]
rake_files.each{|rake_file| load rake_file }

desc "Start runner environment"
task :merb_env do
Merb.start_environment(:environment => init_env, :adapter => 'runner')
end

require 'spec/rake/spectask'
require 'merb-core/test/tasks/spectasks'
desc 'Default: run spec examples'
task :default => 'spec'

##############################################################################
# ADD YOUR CUSTOM TASKS IN /lib/tasks
# NAME YOUR RAKE FILES file_name.rake
##############################################################################
5 changes: 5 additions & 0 deletions app/controllers/application.rb
@@ -0,0 +1,5 @@
require "ruby-debug"

class Application < Merb::Controller

end
13 changes: 13 additions & 0 deletions app/controllers/exceptions.rb
@@ -0,0 +1,13 @@
class Exceptions < Merb::Controller

# handle NotFound exceptions (404)
def not_found
render :format => :html
end

# handle NotAcceptable exceptions (406)
def not_acceptable
render :format => :html
end

end
17 changes: 17 additions & 0 deletions app/controllers/klasses.rb
@@ -0,0 +1,17 @@
class Klasses < Application
cache :index, :show

# ...and remember, everything returned from an action
# goes to the client...
def index
@klasses = Doc::Class.all(:types => ["Class"])
display @klasses
end

def show(name)
@klass = Doc::Class.get(name)
@methods = @klass.all_methods
display @klass
end

end
5 changes: 5 additions & 0 deletions app/helpers/global_helpers.rb
@@ -0,0 +1,5 @@
module Merb
module GlobalHelpers
# helpers defined here available to all views.
end
end
5 changes: 5 additions & 0 deletions app/helpers/klass_helper.rb
@@ -0,0 +1,5 @@
module Merb
module KlassHelper

end
end # Merb
74 changes: 74 additions & 0 deletions app/models/doc/class.rb
@@ -0,0 +1,74 @@
module Doc
class Class
include Describe

def self.any?(opts = {})
!!get_all(opts).first
end

def self.all(opts = {})
get_all(opts).map {|k| new(k, opts[:api] || "public")}
end

private
def self.get_all(opts)
opts[:api] ||= "public"
opts[:types] ||= %w(Class Module)
search = opts[:name] ? "[name='#{opts[:name]}']" : ""
search << (opts[:api] ? ":contains(':api: #{opts[:api]}')" : "")
ret = DOC_XML.css(opts[:types].map {|name| "#{name}#{search}"}.join(", "))
end

public
def self.get(name, api = "public")
node = get_all(:name => name, :api => api).first
node && new(node, api)
end

attr_reader :api, :included_modules, :name, :node,
:description, :superclass

def initialize(node, api)
@node, @api, @name = node, api, node["name"]
desc = node.xpath("./description")[0]
@description = desc && tweak_links(desc.text)

superclass = node.css("superclass a").first
@superclass = superclass && superclass.text
@superclass = nil if @name == @superclass

@included_modules =
node.css("included-module-list included-module").
map {|mod| mod.get_attribute("name")}
end

def inspect
"#<Doc Class: #{@node.get_attribute("name")} api=#{@api.inspect}>"
end

def ancestors
@included_modules + (@superclass ? [@superclass] : [])
end

def method_list
lists = @node.css("method-list")
search = @api ? "method:contains(':api: #{@api}')" : "method"
lists.inject({}) do |accum, list|
method_list = list.css(search).map {|meth| Doc::Method.new(meth, self.name) }
(accum[list.get_attribute("category")] ||= []).push *method_list
accum
end
end

def all_methods
ancestors.inject(method_list) do |accum, mod|
result = Doc::Class.get(mod)
result && result.all_methods.each do |k,v|
accum[k].push *v
end
accum
end
end

end
end
19 changes: 19 additions & 0 deletions app/models/doc/describe.rb
@@ -0,0 +1,19 @@
module Doc
module Describe
def tweak_links(desc)
desc = Nokogiri::HTML(desc)
desc.css("a[href]").each do |node|
href = node["href"]
if href =~ /#(M\d{6})/
node["href"] = "/klasses/#{Doc::Method.by_id($1).klass}##{$1}"
elsif href =~ /#(.*)/ && Doc::Class.any?(:name => $1)
node["href"] = "/klasses/#{$1}"
else
txt = Nokogiri::XML::Text.new(node.inner_html, desc)
node.replace(txt)
end
end
desc.css("body")[0].inner_html
end
end
end
42 changes: 42 additions & 0 deletions app/models/doc/method.rb
@@ -0,0 +1,42 @@
module Doc
class Method
include Describe

attr_reader :name, :type, :category, :from,
:ident, :params, :description, :source_code

def self.by_id(id)
new(DOC_XML.css("[id='#{id}']")[0])
end

def initialize(node, from = nil)
@node = node
@from = klass
attrs = @node.attributes
@name = attrs["name"]
@type = attrs["type"]
@category = attrs["category"]
@ident = attrs["id"]
@params = @node.css("parameters").first.text
@source_code =
@node.css("source-code-listing").first.to_s.
match(/<source-code-listing>(.*)<\/source-code-listing>/m)[1].strip
end

def klass
@node.xpath("../../..")[0].attributes["name"]
end

def inspect
"#<#{name.inspect} params=#{@params.inspect} from=#{@from.inspect}>"
end

def description
@description ||= begin
desc = @node.css("description").text
tweak_links(desc)
end
end

end
end
63 changes: 63 additions & 0 deletions app/views/exceptions/not_acceptable.html.erb
@@ -0,0 +1,63 @@
<div id="container">
<div id="header-container">
<img src="/images/merb.jpg" />
<!-- <h1>Mongrel + Erb</h1> -->
<h2>pocket rocket web framework</h2>
<hr />
</div>

<div id="left-container">
<h3>Exception:</h3>
<p><%= request.exceptions.first.message %></p>
</div>

<div id="main-container">
<h3>Why am I seeing this page?</h3>
<p>Merb couldn't find an appropriate content_type to return,
based on what you said was available via provides() and
what the client requested.</p>

<h3>How to add a mime-type</h3>
<pre><code>
Merb.add_mime_type :pdf, :to_pdf, %w[application/pdf], &quot;Content-Encoding&quot; =&gt; &quot;gzip&quot;
</code></pre>
<h3>What this means is:</h3>
<ul>
<li>Add a mime-type for :pdf</li>
<li>Register the method for converting objects to PDF as <code>#to_pdf</code>.</li>
<li>Register the incoming mime-type "Accept" header as <code>application/pdf</code>.</li>
<li>Specify a new header for PDF types so it will set <code>Content-Encoding</code> to gzip.</li>
</ul>

<h3>You can then do:</h3>
<pre><code>
class Foo &lt; Application
provides :pdf
end
</code></pre>

<h3>Where can I find help?</h3>
<p>If you have any questions or if you can't figure something out, please take a
look at our <a href="http://merbivore.com/"> project page</a>,
feel free to come chat at irc.freenode.net, channel #merb,
or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
on Google Groups.</p>

<h3>What if I've found a bug?</h3>
<p>If you want to file a bug or make your own contribution to Merb,
feel free to register and create a ticket at our
<a href="http://merb.lighthouseapp.com/">project development page</a>
on Lighthouse.</p>

<h3>How do I edit this page?</h3>
<p>You can change what people see when this happens by editing <tt>app/views/exceptions/not_acceptable.html.erb</tt>.</p>

</div>

<div id="footer-container">
<hr />
<div class="left"></div>
<div class="right">&copy; 2008 the merb dev team</div>
<p>&nbsp;</p>
</div>
</div>
47 changes: 47 additions & 0 deletions app/views/exceptions/not_found.html.erb
@@ -0,0 +1,47 @@
<div id="container">
<div id="header-container">
<img src="/images/merb.jpg" />
<!-- <h1>Mongrel + Erb</h1> -->
<h2>pocket rocket web framework</h2>
<hr />
</div>

<div id="left-container">
<h3>Exception:</h3>
<p><%= request.exceptions.first.message %></p>
</div>

<div id="main-container">
<h3>Welcome to Merb!</h3>
<p>Merb is a light-weight MVC framework written in Ruby. We hope you enjoy it.</p>

<h3>Where can I find help?</h3>
<p>If you have any questions or if you can't figure something out, please take a
look at our <a href="http://merbivore.com/"> project page</a>,
feel free to come chat at irc.freenode.net, channel #merb,
or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
on Google Groups.</p>

<h3>What if I've found a bug?</h3>
<p>If you want to file a bug or make your own contribution to Merb,
feel free to register and create a ticket at our
<a href="http://merb.lighthouseapp.com/">project development page</a>
on Lighthouse.</p>

<h3>How do I edit this page?</h3>
<p>You're seeing this page because you need to edit the following files:
<ul>
<li>config/router.rb <strong><em>(recommended)</em></strong></li>
<li>app/views/exceptions/not_found.html.erb <strong><em>(recommended)</em></strong></li>
<li>app/views/layout/application.html.erb <strong><em>(change this layout)</em></strong></li>
</ul>
</p>
</div>

<div id="footer-container">
<hr />
<div class="left"></div>
<div class="right">&copy; 2008 the merb dev team</div>
<p>&nbsp;</p>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/klasses/index.html.haml
@@ -0,0 +1,3 @@
%ul
- @klasses.each do |klass|
%li= link_to(klass.name, resource(klass))
28 changes: 28 additions & 0 deletions app/views/klasses/show.html.haml
@@ -0,0 +1,28 @@
.sidebar
- @methods.each do |type, list|
%h2= type
%ul.method-list
- list.sort_by {|i| i.name }.each do |meth|
%li{:class => meth.from != @klass.name ? "inherit" : nil}
= link_to meth.name, "##{meth.ident}"

.main
%h1= @klass.name
- if @klass.description
%h2
Class Documentation
.desc= @klass.description

- @methods.each do |type, list|
- next if list.empty?
%h2== #{type} Methods
- list.sort_by {|i| i.name}.each do |meth|
%div.method-details{:id => meth.ident}
%p.from= link_to(meth.from, "/klasses/#{meth.from}")
%p{:class => meth.from != @klass.name ? "inherit" : nil}
== #{meth.name}#{meth.params}

.desc
= meth.description
= link_to "Show source", "#", :class => "source"
%pre.source= meth.source_code

0 comments on commit 67dd0e8

Please sign in to comment.