forked from jeremyevans/roda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add work in progress for basic website
- Loading branch information
1 parent
bc20db0
commit 20fdeed
Showing
9 changed files
with
333 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/roda-*.gem | ||
/rdoc | ||
/coverage | ||
/www/public/*.html | ||
/www/public/rdoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Roda<%= " - #{title.capitalize}" unless title == 'index' %></title> | ||
<link href='http://fonts.googleapis.com/css?family=Italianno' rel='stylesheet' type='text/css'> | ||
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="css/roda.css"> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-default" role="navigation"> | ||
<div class="container"> | ||
<a class="navbar-brand" href="index.html">Roda</a> | ||
<ul class="nav navbar-nav"> | ||
<li><a href="why.html">Why</a></li> | ||
<li><a href="documentation.html">Documentation</a></li> | ||
<li><a href="development.html">Development</a></li> | ||
</ul> | ||
</div> | ||
</nav> | ||
<div class="container" id="content"> | ||
<%= content %> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
require 'erb' | ||
require './lib/roda' | ||
Dir.chdir(File.dirname(__FILE__)) | ||
erb = ERB.new(File.read('layout.erb')) | ||
Dir['pages/*.erb'].each do |page| | ||
public_loc = "#{page.gsub(/\Apages\//, 'public/').sub('.erb', '.html')}" | ||
content = ERB.new(File.read(page)).result(binding) | ||
title = File.basename(page.sub('.erb', '')) | ||
File.open(public_loc, 'wb'){|f| f.write(erb.result(binding))} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h2>Development</h2> | ||
|
||
<p>Roda is a new web framework under active development. You can join in on the discussions, ask questions, suggest features, and discuss Sequel in general by joining our Google Group - <a href='http://groups.google.com/group/ruby-roda'>ruby-roda</a> or our <a href='irc://irc.freenode.net/roda'>IRC channel</a>.</p> | ||
|
||
<h3>Reporting Bugs</h3> | ||
|
||
<p>To report a bug in Roda, use <a href="https://github.com/jeremyevans/roda/issues">GitHub Issues</a>. If you aren't sure if something is a bug, post a question on the <a href='http://groups.google.com/group/ruby-roda'>Google Group</a> or ask on <a href='irc://irc.freenode.net/roda'>IRC</a>. Note that GitHub Issues should not be used to ask questions about how to use Roda, use the Google Group or IRC for that.</p> | ||
|
||
<h3>Source Code</h3> | ||
|
||
<p>The master source code repository is <a href="https://github.com/jeremyevans/roda">jeremyevans/roda on GitHub</a>.</p> | ||
|
||
<h3>Submitting Patches</h3> | ||
|
||
<p>The easiest way to contribute is to use git, post the changes to a public repository, and send a pull request, either via GitHub, the Google Group, or IRC. Posting patches to the bug tracker or the Google Group works fine as well.</p> | ||
|
||
<h3>License</h3> | ||
|
||
<p>Roda is distributed under the <a href="rdoc/files/MIT-LICENSE.html">MIT License</a>. Patches are assumed to be submitted under the same license as Roda.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<h1>Documentation for Roda (v<%= Roda::RodaVersion %>)</h1> | ||
|
||
<h2><a href="rdoc/files/README_rdoc.html">README</a> (Introduction to Roda, start here if new)</h2> | ||
|
||
<h2><a href="rdoc/index.html">RDoc</a> (frames)</h2> | ||
|
||
<p>Here are direct links to the most important pages:</p> | ||
|
||
<ul> | ||
<li><a href="rdoc/classes/Roda.html">Roda</a> (main class)</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Base/ClassMethods.html">Roda ClassMethods</a></li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Base/InstanceMethods.html">Roda InstanceMethods</a></li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Base/RequestMethods.html">Roda RequestMethods</a></li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Base/ResponseMethods.html">Roda ResponseMethods</a></li> | ||
</ul> | ||
|
||
<h2>Plugins</h2> | ||
|
||
<p>Plugins are a very important part of Roda, since by design Roda is designed to have a very small core.</p> | ||
|
||
<h3>Plugins that Ship with Roda</h3> | ||
|
||
<ul> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/AllVerbs.html">all_verbs</a>: Adds request routing methods for all http verbs.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/DefaultHeaders.html">default_headers</a>: Allows modifying the default headers for responses.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/ErrorHandler.html">error_handler</a>: Adds ability to automatically handle errors raised by the application.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Flash.html">flash</a>: Adds flash handling, using <a href="https://github.com/SFEley/sinatra-flash">sinatra-flash</a>.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/H.html">h</a>: Adds h method for html escaping.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Halt.html">halt</a>: Augments request halt method for support for setting response status and/or response body.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/HeaderMatchers.html">header_matchers</a>: Adds matchers for hostname, accept, or presence of arbitrary headers.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Hooks.html">hooks</a>: Adds before/after hook methods.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/IndifferentParams.html">indifferent_params</a>: Adds params method for indifferent parameters.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Middleware.html">middleware</a>: Allows the Roda app to be used as middleware by another app.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/MultiRoute.html">multi_route</a>: Allows for multiple named route blocks that can be dispatched to inside main route block.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/NotFound.html">not_found</a>: Adds not_found method for handling responses not otherwise handled by a route.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Pass.html">pass</a>: Adds pass method for skipping the current matching route block as if it didn't match.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Render.html">render</a>: Adds render method for rendering templates, using <a href="https://github.com/rtomayko/tilt">tilt</a>.</li> | ||
<li><a href="rdoc/classes/Roda/RodaPlugins/Streaming.html">streaming</a>: Adds ability to stream responses.</li> | ||
</ul> | ||
|
||
<h3>External Plugins</h3> | ||
|
||
<p>These projects ship external plugins for Roda:</p> | ||
|
||
<ul> | ||
<li><a href="https://github.com/jeremyevans/autoforme">autoforme</a>: Adds autoforme method for automatic creation of administrative front-end for Sequel models.</li> | ||
<li><a href="https://github.com/jeremyevans/forme">forme</a>: Adds form method for simple creation of html forms.</li> | ||
</ul> | ||
|
||
<% if false %> | ||
<h2><a href="rdoc/files/CHANGELOG.html">Change Log</a></h2> | ||
|
||
<h2>Release Notes</h2> | ||
<ul> | ||
<% %w'1'.each do |i| %> | ||
<li>Roda <%= i %>:<ul> | ||
<% | ||
lines = [] | ||
Dir["../doc/release_notes/#{i}.*.txt"].map{|f| File.basename(f)}.each do |f| | ||
(lines[f.split('.')[1].to_i/10] ||= []) << f | ||
end | ||
lines.reverse.each do |fs| | ||
%> | ||
<li> | ||
<% fs.sort_by{|f| f.split('.').map{|x| x.to_i}}.reverse.each do |f| %> | ||
<a href="rdoc/files/doc/release_notes/<%= f.gsub('.', '_') %>.html"><%= f.sub(/\.txt$/, '').sub(/(..)\.0$/, '\\1') %></a> | | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ul></li> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
|
||
<h2><a href="rdoc/files/MIT-LICENSE.html">License</a></h2> | ||
|
||
<% if false %> | ||
<h2>Presentations</h2> | ||
|
||
<ul> | ||
</ul> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div id="roda_tree"> | ||
<h1 id="site_title">Roda</h1> | ||
<h2 id="site_subtitle">Routing Tree<br />Web Framework</h2> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<h1>Why Roda?</h1> | ||
|
||
<p>There are already plenty of ruby web frameworks. Why another one? Well, Roda has a very useful combination of features that make web development easy. It's designed to be fast, <acronym title="Don't Repeat Yourself">DRY</acronym>, and correct. It's probably easiest to explain the advantages by comparing it with Sinatra, which it tries to emulate in many respects.</p> | ||
|
||
<h2>Advantages over Sinatra</h2> | ||
|
||
<p>The primary advantage that Roda offers over Sinatra is that it uses a routing tree, while Sinatra uses a simple list of routes. At any point in the routing tree, you can operate on the current route. If your URLs reflect your application architecture, this allows you to have much DRYer code. Let's examine code examples for the a simple app, implemented in both Sinatra and Roda:</p> | ||
|
||
<div class="col-md-6"> | ||
Roda: | ||
<pre><code>require 'roda' | ||
|
||
class App < Roda | ||
plugin :render | ||
|
||
route do |r| | ||
r.get '' do | ||
view :index | ||
end | ||
|
||
r.on 'artist/:id' do |artist_id| | ||
@artist = Artist[artist_id] | ||
|
||
r.is do | ||
r.get do | ||
view :artist | ||
end | ||
|
||
r.post do | ||
@artist.update(params[:artist]) | ||
r.redirect(r.full_path_info) | ||
end | ||
end | ||
|
||
r.on 'album/:number' do |album_number| | ||
@album = @artist.album_with_number(album_number) | ||
|
||
r.is do | ||
r.get do | ||
view :album | ||
end | ||
|
||
r.post do | ||
@album.update(params[:album]) | ||
r.redirect(r.full_path_info) | ||
end | ||
end | ||
|
||
r.on 'track/:track_num' do |track_num| | ||
@track = @album.track_with_number(track_num) | ||
|
||
r.is do | ||
r.get do | ||
view :track | ||
end | ||
|
||
r.post do | ||
@track.update(params[:track]) | ||
r.redirect(r.full_path_info) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
</code></pre> | ||
</div> | ||
|
||
<div class="col-md-6"> | ||
Sinatra: | ||
<pre><code>require 'sinatra/base' | ||
|
||
class App < Sinatra::Base | ||
get '/' do | ||
erb :index | ||
end | ||
|
||
get '/artist/:id' do | ||
@artist = Artist[params[:id]] | ||
erb :artist | ||
end | ||
|
||
post '/artist/:id' do | ||
@artist = Artist[params[:id]] | ||
@artist.update(params[:artist]) | ||
redirect(request.path_info) | ||
end | ||
|
||
get '/artist/:id/album/:number' do | ||
@artist = Artist[params[:id]] | ||
@album = @artist.album_with_number(params[:number]) | ||
erb :album | ||
end | ||
|
||
post '/artist/:id/album/:number' do | ||
@artist = Artist[params[:id]] | ||
@album = @artist.album_with_number(params[:number]) | ||
@album.update(params[:album]) | ||
redirect(request.path_info) | ||
end | ||
|
||
get '/artist/:id/album/:number/track/:track_num' do | ||
@artist = Artist[params[:id]] | ||
@album = @artist.album_with_number(params[:number]) | ||
@track = @album.track_with_number(params[:track_num]) | ||
erb :track | ||
end | ||
|
||
post '/artist/:id/album/:number/track/:track_num' do | ||
@artist = Artist[params[:id]] | ||
@album = @artist.album_with_number(params[:number]) | ||
@track = @album.track_with_number(params[:track_num]) | ||
@track.update(params[:track]) | ||
redirect(request.path_info) | ||
end | ||
end | ||
</code></pre> | ||
</div> | ||
|
||
<p style="clear: both;">While the Roda code is slightly more lines, it should be apparent that it is actually much simpler. Instead of setting the @artist, @album, and/or @track variables in every route that uses them, the variables are set as soon as that branch of the tree is taken, and can be used in all routes under that branch. This is why Roda is called a routing tree web framework. In all but the smallest applications, this usually results in much DRYer and easier to maintain code.</p> | ||
|
||
<p>In addition to being more maintainable, Roda's approach is also much faster in general. This is because Sinatra is doing more work to determine which route to take compared to Roda. Let's say you are going to <span class="path">/artist/1/album/2/track/3</span>. What Sinatra is going to do is check each route in order, comparing the request method and route against the full path of the request, and if it doesn't match, starting again with the next route. With Roda, as soon as part of the route matches, that part does not need to be rechecked every time. Also, the request method is only checked once at the end to determine whether to take get or post as the final branch.</p> | ||
|
||
<p>Another advantage Roda brings over Sinatra is that it has a plugin system modeled on Sequel's. All parts of Roda (class/instance/request/response) can be overridden by plugins and call super to get the default behavior. This includes when plugins are applied to the Roda class itself (affecting all subclasses). Roda has a very small core, and many features that are built-in Sinatra are shipped as plugins in Roda. This way they can easily used if needed, but if you don't use them you don't pay the cost for loading them. Near the top of the Roda example, there is the call to load the render plugin, which adds support for template rendering, as the default Roda code doesn't ship with template support.</p> | ||
|
||
<p>Finally, Roda, being a "tree", is very concerned about pollution. In this case, pollution of the scope in which the route block operates. Roda purposely limits the instance variables, instance methods, and class namespaces available in the route block scope, so that it is very unlikely you will run into conflicts. If you've ever tried to use an instance variable named @request or a model named Response inside a Sinatra::Base subclass, you'll appreciate that Roda attempts to avoid polluting the scope.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
nav.navbar.navbar-default a.navbar-brand, nav.navbar.navbar-default ul.nav > li > a { | ||
color: white; | ||
} | ||
|
||
a.navbar-brand, #site_title, #site_subtitle { | ||
font-family: 'Italianno', cursive; | ||
} | ||
|
||
a.navbar-brand { | ||
padding-top: 20px; | ||
margin-right: 30px; | ||
font-size: 40px; | ||
} | ||
#site_title { | ||
font-size: 192px; | ||
margin-top: 30px; | ||
margin-left: 30px; | ||
} | ||
#site_subtitle { | ||
font-size: 128px; | ||
margin-top: 150px; | ||
margin-left: 30px; | ||
} | ||
|
||
body #content a { | ||
color: #141; | ||
text-decoration: underline; | ||
} | ||
nav.navbar { | ||
background: #141; | ||
} | ||
body{ | ||
background: #cdc; | ||
} | ||
|
||
div#roda_tree { | ||
color: white; | ||
background: url(roda.jpg); | ||
background-size: 100%; | ||
} | ||
|
||
.path { | ||
background: white; | ||
} |