Skip to content

Commit

Permalink
Enhancements and fixes for version 1.2.0
Browse files Browse the repository at this point in the history
* Added Hanna documentation generator.
* The mapping methods works in classic application.
* Updates in documentation.
* All tests have been fixed.
  • Loading branch information
Hallison Batista committed Sep 22, 2009
1 parent 36d320c commit a001d63
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 172 deletions.
4 changes: 3 additions & 1 deletion CHANGES
@@ -1,7 +1,9 @@
= Changes

[1.1.1 - not released]
[1.2.0 - 2009-09-22]
* The mapping methods works in classic application.
* Updates in documentation.
* All tests have been fixed.

[1.1.0 - 2009-08-25]
* Added suffix "/?" in all paths when no arguments.
Expand Down
3 changes: 1 addition & 2 deletions INFO
Expand Up @@ -9,6 +9,5 @@
:email: email@hallisonbatista.com
:homepage: http://sinatra-mapping.rubyforge.org/
:dependencies:
rack: >= 1.0.0
sinatra: >= 0.9.2
sinatra: >= 0.9.1.1

1 change: 1 addition & 0 deletions LICENSE
Expand Up @@ -17,3 +17,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

207 changes: 97 additions & 110 deletions README.rdoc
Expand Up @@ -2,16 +2,17 @@

Map easily URLs in your Web applications.

* {Homepage}[http://sinatra-mapping.rubyforge.org/]
* {Repository}[http://github.com/hallison/sinatra-mapping]
* {Project}[http://rubyforge.org/projects/sinatra-mapping]
* {Documentation}[:link:Sinatra/Mapping.html]
* {Issues}[http://github.com/hallison/sinatra-mapping/issues]

The extension Sinatra::Mapping is a minimal module that is useful for
create map names for {Ruby}[http://www.ruby-lang.org]
{Sinatra}[http://www.sinatrarb.com] web applications.

== Getting start

Install stable version gem from {RubyForge.org}[http://www.rubyforge.org/]:

gem install sinatra-mapping
Expand Down Expand Up @@ -42,127 +43,113 @@ Sinatra implements REST routes:

For improve this routes use extension by registered method in the main
source of application. To better understand, copy and paste the following
example in {Ruby}[http://www.ruby-lang.org] source file +webfoo.rb+:
example in {Ruby}[http://www.ruby-lang.org] source file +weblog.rb+:

#!/usr/bin/env ruby

require 'rubygems'
require 'sinatra'
require 'sinatra/mapping'
require 'sinatra/mapping_helpers'

class Sinatra::Application

register Sinatra::Mapping
helpers Sinatra::MappingHelpers

map :root, "blog" # /blog/
map :entries, "posts" # /blog/posts
map :tags, "labels" # /blog/labels

mapping :entry => "posts/:entry_id", # /blog/posts/id-for-post
:entry_comments => "posts/:entry_id/comments", # /blog/posts/id-for-post/comments
:tagged_entries => "labels/:tag_id/entries" # /blog/labels/id-for-tag/entries

# /blog/
get root_path do
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<ul>
<li>#{link_to title_path(:entries), :entries, :title => title_path(:entries)}</li>
<li>#{link_to title_path(:tags), :tags, :title => title_path(:tags)}</li>
</ul>
end_content
end

# /blog/entries
get entries_path do
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title_path(:entries)}</h2>
<ul>
<li>#{link_to "Testing new entry ...", :entries, "testing-new-entry"}</li>
<li>#{link_to "Testing old entry ...", :entries, "testing-old-entry"}</li>
</ul>
<p>
#{link_to "Back", :root}
</p>
end_content
end

# /blog/labels/tag-id-for-show-content
get tags_path do
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title_path(:tags)}</h2>
<ul>
<li>#{link_to "Ruby", :tags, "ruby", "entries"}</li>
<li>#{link_to "Sinatra", :tags, "sinatra", "entries"}</li>
<li>#{link_to "Mapping", :tags, "mapping", "entries"}</li>
</ul>
<p>
#{link_to "Back", :root}
</p>
end_content
end

# /blog/entries/entry-id-for-show-content
get entry_path do |entry_id|
title = entry_id.gsub('-',' ').capitalize
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title}</h2>
<p>
It works!
</p>
<p>
#{link_to "Back", :root} | #{link_to "Comments", :entries, entry_id, 'comments'}
</p>
end_content
end

# /blog/entries/entry-id-for-show-content/comments
get entry_comments_path do |entry_id|
title = entry_id.gsub('-',' ').capitalize
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title}</h2>
<p>
It works and show comments for "#{title}".
</p>
<p>
#{link_to "Back", :root}
</p>
end_content
end

get tagged_entries_path do |tag_id|
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{tag_id.capitalize}</h2>
<p>
It works and show all entries tagged with "#{tag_id}".
</p>
<p>
#{link_to "Back", :root}
</p>
end_content
end
require 'sinatra/mapping' # only this line for use mapping!

map :root, "blog" # /blog/
map :entries, "posts" # /blog/posts
map :tags, "labels" # /blog/labels

mapping :entry => "posts/:entry_id", # /blog/posts/id-for-post
:entry_comments => "posts/:entry_id/comments", # /blog/posts/id-for-post/comments
:tagged_entries => "labels/:tag_id/entries" # /blog/labels/id-for-tag/entries

# /blog/
get root_path do
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<ul>
<li>#{link_to title_path(:entries), :entries, :title => title_path(:entries)}</li>
<li>#{link_to title_path(:tags), :tags, :title => title_path(:tags)}</li>
</ul>
end_content
end

# /blog/entries
get entries_path do
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title_path(:entries)}</h2>
<ul>
<li>#{link_to "Testing new entry ...", :entries, "testing-new-entry"}</li>
<li>#{link_to "Testing old entry ...", :entries, "testing-old-entry"}</li>
</ul>
<p>
#{link_to "Back", :root}
</p>
end_content
end

Run:
# /blog/labels/tag-id-for-show-content
get tags_path do
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title_path(:tags)}</h2>
<ul>
<li>#{link_to "Ruby", :tags, "ruby", "entries"}</li>
<li>#{link_to "Sinatra", :tags, "sinatra", "entries"}</li>
<li>#{link_to "Mapping", :tags, "mapping", "entries"}</li>
</ul>
<p>
#{link_to "Back", :root}
</p>
end_content
end

$ ruby webfoo.rb -p 3000
# /blog/entries/entry-id-for-show-content
get entry_path do |entry_id|
title = entry_id.gsub('-',' ').capitalize
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title}</h2>
<p>
It works!
</p>
<p>
#{link_to "Back", :root} | #{link_to "Comments", :entries, entry_id, 'comments'}
</p>
end_content
end

Open Web browser http://localhost:3000/blog/ and look ... it works!
# /blog/entries/entry-id-for-show-content/comments
get entry_comments_path do |entry_id|
title = entry_id.gsub('-',' ').capitalize
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{title}</h2>
<p>
It works and show comments for "#{title}".
</p>
<p>
#{link_to "Back", :root}
</p>
end_content
end

get tagged_entries_path do |tag_id|
<<-end_content
<h1>Welcome to Foo Web Application</h1>
<h2>#{tag_id.capitalize}</h2>
<p>
It works and show all entries tagged with "#{tag_id}".
</p>
<p>
#{link_to "Back", :root}
</p>
end_content
end

== More informations
Run:

* See the {changes}[:link:CHANGES.html] for understand the goals of
that release version.
* {License}[:link:LICENSE.html]
$ ruby weblog.rb -p 3000

Open Web browser http://localhost:3000/blog/ and look ... it works!

== Copyright

:include:LICENSE

30 changes: 18 additions & 12 deletions Rakefile
@@ -1,7 +1,12 @@
require 'rdoc'
begin
require 'hanna/rdoctask'
rescue LoadError
require 'rdoc'
require 'rake/rdoctask'
end

require 'rake/testtask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
load 'sinatra-mapping.gemspec'

def current_version(file = "VERSION")
Expand Down Expand Up @@ -48,16 +53,17 @@ Rake::GemPackageTask.new(@spec) do |pkg|
pkg.need_tar_bz2 = true
end

desc "Generate RDoc API documentation."
Rake::RDocTask.new("doc:api") do |rdoc|
rdoc.title = "Sinatra::Mapping - API Documentation"
rdoc.main = "README.rdoc"
rdoc.options = [ '-SHN', '-f', 'darkfish' ]
rdoc.rdoc_dir = 'doc'
rdoc.rdoc_files.include(
"CHANGES",
"LICENSE",
"README.rdoc",
"lib/**/*.rb"
)
rdoc.title = %q{Sinatra::Mapping - API Documentation}
rdoc.main = %q{README.rdoc}
rdoc.options = %w{--line-numbers --show-hash}
rdoc.rdoc_dir = %q{doc/api}
rdoc.rdoc_files.include %w{
CHANGES
LICENSE
README.rdoc
lib/**/*.rb
}
end

4 changes: 2 additions & 2 deletions VERSION
@@ -1,7 +1,7 @@
---
:release:
:date: 2009-08-25
:cycle: Stable release
:major: 1
:minor: 1
:minor: 2
:date: 2009-09-22
:patch: 0

0 comments on commit a001d63

Please sign in to comment.