Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now has regexp in one place (codes(), in model)

improved helper formatting and validation
  • Loading branch information...
commit f4d4dae065511e6e2ece8aa203eaffb5d1a34268 1 parent 783a1d4
@paulcc paulcc authored
View
17 app/helpers/blog_entries_helper.rb
@@ -1,23 +1,24 @@
module BlogEntriesHelper
# insert links for *nnnnn* codes
- # distributes small thumbnails to left and right
- # attempts to set min height for the BB
- def expand_sku(text)
+ # puts small thumbnails beneath the text (or do by paragraph?)
+ # should this code be in the model? maybe not, since it's a view thing...
+ def expand_sku(entry)
matches = 0
pics = ""
- text.gsub!(/\*([-\w]+)\*/) do |s|
- v = Variant.find_by_sku($1)
+ text = entry.body
+ entry.codes.each do |c|
+ v = Variant.find_by_sku(c)
if v.nil?
- "(deleted product #{$1})"
+ "(invalid product #{c})"
else
matches += 1
p = v.product
pics << link_to((mini_image p), product_path(p), :style => "padding:6px", :title => p.name)
- link_to(p.name, product_path(p))
+ text.gsub! /\*#{c}\*/, link_to(p.name, product_path(p))
end
end
- text + "<br/>" + pics
+ text + "<br/><p>" + pics + "</p>"
end
View
2  app/models/blog_entry.rb
@@ -7,7 +7,7 @@ class BlogEntry < ActiveRecord::Base
validates_presence_of :body
def codes
- self.body.scan(/\*([-\w]+)\*/).flatten.uniq
+ self.body.scan(/\*([^*]+)\*/).flatten.uniq
end
def validate
View
3  app/models/comment.rb
@@ -11,6 +11,7 @@ class Comment < ActiveRecord::Base
named_scope :approved, lambda {|*args| {:conditions => "approved == 't'"}}
named_scope :not_approved, lambda {|*args| {:conditions => "approved != 't'"}}
named_scope :lifo_order, lambda {|*args| {:order => "created_at DESC"}}
+ named_scope :date_order, lambda {|*args| {:order => "created_at ASC"}}
def self.latest ## keep?
find(:all, :order => "created_at DESC", :limit => 3) # use lifo?
@@ -18,7 +19,7 @@ def self.latest ## keep?
# check basic format of URIs, AND expand all non-blank uris to canonical form
def validate
- unless self.uri.nil?
+ unless self.uri.blank?
self.uri = "http://#{self.uri}" unless URI.parse(self.uri).absolute?
end
rescue
Please sign in to comment.
Something went wrong with that request. Please try again.