Skip to content
Browse files

Avoid using capturing regexps just to make sure that substitutions wi…

…ll happen.
  • Loading branch information...
1 parent 791682f commit 48b69adb4f228b5c892373d30168ed87dc3ffe0c @Flameeyes committed Feb 17, 2013
Showing with 9 additions and 9 deletions.
  1. +9 −9 lib/transforms.rb
View
18 lib/transforms.rb
@@ -43,27 +43,27 @@ def to_title(item, settings, params)
s = self
# Tags for params
- s = s.gsub('%date%', parse_date(s, params)) if s =~ /(%date%)/
+ s = s.gsub('%date%', parse_date(s, params)) if s =~ /%date%/
s = s.gsub('%search%', params[:q]) if params[:q]
- s = s.gsub('%page%', parse_page(s, params)) if s=~ /(%page%)/
+ s = s.gsub('%page%', parse_page(s, params)) if s=~ /%page%/
# Tags for settings
s = s.gsub('%blog_name%', settings.blog_name)
s = s.gsub('%blog_subtitle%', settings.blog_subtitle)
s = s.gsub('%meta_keywords%', settings.meta_keywords)
# Tags for item
- s = s.gsub('%title%', item.title) if s =~ /(%title)/ and item.respond_to? :title
- s = s.gsub('%excerpt%', item.excerpt_text) if s =~ /(%excerpt%)/ and item.respond_to? :excerpt_text
- s = s.gsub('%description%', item.description) if s =~ /(%description%)/ and item.respond_to? :description
- s = s.gsub('%name%', item.name) if s =~ /(%name%)/ and item.respond_to? :name
- s = s.gsub('%author%', item.name) if s =~ /(%author%)/ and item.respond_to? :name
+ s = s.gsub('%title%', item.title) if s =~ /%title/ and item.respond_to? :title
+ s = s.gsub('%excerpt%', item.excerpt_text) if s =~ /%excerpt%/ and item.respond_to? :excerpt_text
+ s = s.gsub('%description%', item.description) if s =~ /%description%/ and item.respond_to? :description
+ s = s.gsub('%name%', item.name) if s =~ /%name%/ and item.respond_to? :name
+ s = s.gsub('%author%', item.name) if s =~ /%author%/ and item.respond_to? :name
- if s =~ /(%categories%)/ and item.respond_to? :categories
+ if s =~ /%categories%/ and item.respond_to? :categories
s = s.gsub('%categories%', item.categories.map { |c| c.name }.join(", "))
end
- if s =~ /(%tags%)/ and item.respond_to? :tags
+ if s =~ /%tags%/ and item.respond_to? :tags
s = s.gsub('%tags%', item.tags.map { |t| t.display_name }.join(", "))
end

0 comments on commit 48b69ad

Please sign in to comment.
Something went wrong with that request. Please try again.