Module: Vanilla::Routing

Included in:
App
Defined in:
lib/vanilla/routing.rb

Constant Summary collapse

ROOT =

i.e. / or nothing

/\A\/?\Z/
SNIP =

i.e. /start, /start.html

/\A\/([\w\-\s]+)(\/|\.(\w+))?\Z/
SNIP_AND_PART =

i.e. /blah/part, /blah/part.raw

/\A\/([\w\-\s]+)\/([\w\-\s]+)(\/|\.(\w+))?\Z/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(path) ⇒ Object

Returns an array of three components;

  • the snip

  • the part

  • the format



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vanilla/routing.rb', line 22

def self.parse(path)
  case CGI.unescape(path)
  when ROOT
    [nil, nil, nil]
  when SNIP
    [$1, nil, $3]
  when SNIP_AND_PART
    [$1, $2, $4]
  else
    []
  end
end

Instance Method Details

#url_to(snip_name, part = nil) ⇒ Object



4
5
6
7
8
9
# File 'lib/vanilla/routing.rb', line 4

def url_to(snip_name, part=nil)
  return "/" if snip_name == config.root_snip && part.nil?
  url = "/#{snip_name.gsub(" ", "+")}"
  url += "/#{part}" if part
  url
end