0
class Site < ActiveRecord::Base
0
@@theme_path = Pathname.new(RAILS_ROOT) + 'themes'
0
cattr_reader :theme_path
0
- PERMALINK_OPTIONS = { 'year' => '\d{4}', 'month' => '\d{1,2}', 'day' => '\d{1,2}', 'permalink' => '[\w\-]+', 'id' => '\d+' }
0
- PERMALINK_VAR = /^:([a-z]+)$/
0
cattr_accessor :multi_sites_enabled
0
@@ -130,30 +128,12 @@ class Site < ActiveRecord::Base
0
[:attachments, :templates, :resources].each { |m| delegate m, :to => :theme }
0
def permalink_regex(refresh = false)
0
- if refresh || @permalink_regex.nil?
0
- @permalink_variables = []
0
- r = permalink_style.split('/').inject [] do |s, piece|
0
- if piece =~ PERMALINK_VAR
0
- @permalink_variables << $1.to_sym
0
- s << "(#{PERMALINK_OPTIONS[$1]})"
0
- @permalink_regex = Regexp.new("^#{r.join('\/')}(\/comments(\/(\\d+))?)?$")
0
+ @permalink_regex, @permalink_variables = Mephisto::Dispatcher.build_permalink_regex_with(permalink_style) if refresh || @permalink_regex.nil?
0
def permalink_for(article)
0
- old_published = article.published_at
0
- article.published_at ||= Time.now.utc
0
- permalink_style.split('/').inject [''] do |s, piece|
0
- s << (piece =~ PERMALINK_VAR && PERMALINK_OPTIONS.keys.include?($1) ? article.send($1).to_s : piece)
0
- article.published_at = old_published
0
+ Mephisto::Dispatcher.build_permalink_with(permalink_style, article)
0
def search_url(query, page = nil)
0
@@ -187,8 +167,12 @@ class Site < ActiveRecord::Base
0
+ def permalink_variable_format?(var)
0
+ Mephisto::Dispatcher.variable_format?(var)
0
def permalink_variable?(var)
0
-
var =~ PERMALINK_VAR && PERMALINK_OPTIONS.keys.include?(var)
0
+
Mephisto::Dispatcher.variable?(var)
0
def check_permalink_style
0
@@ -197,7 +181,7 @@ class Site < ActiveRecord::Base
0
pieces = permalink_style.split('/')
0
errors.add :permalink_style, 'cannot have blank paths' if pieces.any?(&:blank?)
0
- errors.add :permalink_style, "cannot contain '#{
$1}' variable" if p =~ PERMALINK_VAR && !PERMALINK_OPTIONS.keys.include?($1)
0
+ errors.add :permalink_style, "cannot contain '#{
p}' variable" unless p.blank? || permalink_variable_format?(p).nil? || permalink_variable?(p)
0
unless pieces.include?(':id') || pieces.include?(':permalink')
0
errors.add :permalink_style, "must contain either :permalink or :id"
Comments
No one has commented yet.