Module: Staticpress::Route
- Extended by:
- Helpers
- Defined in:
- lib/staticpress/route.rb
Defined Under Namespace
Classes: RegexStub
Constant Summary
collapse
- REGEX_STUBS =
{
:asset_type => RegexStub.new(:string, /(?<asset_type>fonts|images|scripts|styles)/),
:date => RegexStub.new(:date, /(?<date>\d{4}-\d{2}-\d{2})/),
:year => RegexStub.new(:string, /(?<year>\d{4})/),
:month => RegexStub.new(:string, /(?<month>\d{2})/),
:day => RegexStub.new(:string, /(?<day>\d{2})/),
:slug => RegexStub.new(:string, /(?<slug>[0-9a-z\-_\.\/]*)/),
:title => RegexStub.new(:string, /(?<title>[0-9a-z\-_]*)/),
:name => RegexStub.new(:string, /(?<name>[0-9a-z\-_]*)/),
:number => RegexStub.new(:integer, /(?<number>\d+)/),
:theme => RegexStub.new(:string, /(?<theme>[0-9a-z\-_]*)/)
}
Class Method Summary
collapse
Methods included from Helpers
config, extensionless_basename, extensionless_path, hash_from_array, hash_from_match_data, paginate, settings, spider_map, titleize
Class Method Details
20
21
22
23
24
|
# File 'lib/staticpress/route.rb', line 20
def self.(pattern, url_path)
if match = regex_for_pattern(pattern).match(url_path)
hash_from_match_data match
end
end
|
.regex_for_pattern(pattern) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/staticpress/route.rb', line 26
def self.regex_for_pattern(pattern)
regex = REGEX_STUBS.inject("^#{pattern}$") do |snip, (key, value)|
snip.gsub /:#{key}/, value.regex.source
end
Regexp.new regex
end
|
.route_options(title) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/staticpress/route.rb', line 34
def self.route_options(title)
t = Time.now.utc
{
:date => "#{t.year}-#{'%02d' % t.month}-#{'%02d' % t.day}",
:year => t.year,
:month => '%02d' % t.month,
:day => '%02d' % t.day,
:title => title
}
end
|