# Improvement: SiteMapper - working ideas as a possible RoR's

**URL:** <https://www.ruby-forum.com/t/improvement-sitemapper-working-ideas-as-a-possible-rors/64564>\
**Category:** Rails\
**Created:** [August 9, 2006, 11:38pm UTC](https://www.ruby-forum.com/t/improvement-sitemapper-working-ideas-as-a-possible-rors/64564 "2006-08-09T23:38:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_SSISO-8859-2SQ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Jan\_SSISO-8859-2SQ](https://www.ruby-forum.com/u/Jan_SSISO-8859-2SQ)\
**Post date:** [August 9, 2006, 11:38pm UTC](https://www.ruby-forum.com/t/improvement-sitemapper-working-ideas-as-a-possible-rors/64564/1 "2006-08-09T23:38:35Z")

</div>

Hello,

I’ve done potencial replacement for RoR’s routing mechanism.

It just works as an independent class so you can try bundled examples  
withou installing anything else. I didn’t integrated it into Rails (as  
a plugin?) because I don’t know if anyone would appreciate it etc.

## SiteMapper features:

1. uses regexp mask to get variables from url and the same regexp mask  
to  
create new url.

2. Automatically finds the best route (=\> create the best url) in  
dependence on passed variables.

3. Define a site structure at once with the mapping, that’s because  
it’s called SiteMapper.

4. Moreover you can determine languages from url.

5. You can dump it instead of caching generated ruby code.

6. The class is only 8,3KB with comments.

## A real example:

mapper = SiteMapper.new

# firstly define the map and site structure…

mapper.add( :gallery ) do |level1|  
level1.add( :mammals ) do |level2|  
level2.route( ‘gallery/mammals’,  
:controller=\>‘gallery’,  
:type=\>‘mammals’  
)  
level1.add( :insect ) do |level2|  
level2.route( ‘gallery/insect’,  
:controller=\>‘gallery’,  
:type=\>‘insect’  
)  
level2.add( :description ) do |level3|  
level3.route( [‘gallery/insect/(.\*?).html’, :insect\_name],  
:controller=\>‘gallery’,  
:action=\>‘show’  
)  
end  
end  
end

# then you can recognize an url to a ceratin route

route = mapper.recognize( ‘/gallery/insect/135.html’ )  
puts route.parameters.join( ', ’ ) # output: insect\_name  
puts route.navigation.join( ’ -\> ') # output: gallery -\> insect -\>  
description

# and create new url using automatic selection of the best route

puts mapper.url\_for(  
:controller=\>‘gallery’,  
:action=\>‘show’,  
:insect\_name=\>‘567’  
) # output: /gallery/insect/567.html (= the last route used )

# or let just the recognized route generate the new url

puts route.url\_for( :insect\_name=\>‘567’ )

* * *

I think the url parameters can be inherrited from upper levels, too.

I’d like to receive your comments 🙂

Jan Molic

---

<div class="post-metadata">

**Author:** ![Jan\_SSISO-8859-2SQ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Jan\_SSISO-8859-2SQ](https://www.ruby-forum.com/u/Jan_SSISO-8859-2SQ)\
**Post date:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/improvement-sitemapper-working-ideas-as-a-possible-rors/64564/2 "2006-08-15T14:18:36Z")

</div>

Hi~

On Aug 9, 2006, at 2:14 PM, Jan MoliÄ wrote:

> SiteMapper features:  
> it’s called SiteMapper.
> 
> level1.add( :insect ) do |level2|  
> end
> 
> * * *
> 
> I think the url parameters can be inherrited from upper levels, too.
> 
> I’d like to receive your comments 🙂
> 
> Jan Molic

```
If you can link us to the code then we could try it out and give

```

feedback. Is it released somewhere?

Cheers-  
-Ezra
