Module: SanteyBlog::ViewHelper

Includes:
ActionView::Helpers
Defined in:
lib/santey_blog/view_helper.rb

Constant Summary collapse

SANITIZER_CONFIG =

HTML sanitizer configuration

{
  :elements => [
      'a', 'b', 'blockquote', 'br', 'hr', 'caption', 'cite', 'code', 'col',
      'colgroup', 'dd', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
      'i', 'img', 'li', 'ol', 'p', 'pre', 'q', 'small', 'strike', 'strong',
      'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'u',
      'ul'],
  :attributes => {
      'a' => ['href', 'title'],
      'blockquote' => ['cite'],
      'col' => ['span', 'width'],
      'colgroup' => ['span', 'width'],
      'img' => ['align', 'alt', 'height', 'src', 'title', 'width'],
      'ol' => ['start', 'type'],
      'q' => ['cite'],
      'table' => ['summary', 'width'],
      'td' => ['abbr', 'axis', 'colspan', 'rowspan', 'width'],
      'th' => ['abbr', 'axis', 'colspan', 'rowspan', 'scope', 'width'],
      'ul' => ['type']
  },
  :add_attributes => {
      'a' => {'rel' => 'nofollow'}
  },
  :protocols => {
      'a' => {'href' => ['ftp', 'http', 'https', 'mailto', :relative]},
      'blockquote' => {'cite' => ['http', 'https', :relative]},
      'img' => {'src' => ['http', 'https', :relative]},
      'q' => {'cite' => ['http', 'https', :relative]}
  }
}

Instance Method Summary collapse

Instance Method Details

#cut_text(text, full_url, length = 500) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/santey_blog/view_helper.rb', line 74

def cut_text text, full_url, length=500
  if(m = /<hr/i.match(text))
    text = Hpricot(text[0..(m.offset(0)[0] - 1)]).to_html
  else
    text = truncate(text.to_s.gsub(/<\/?[^>]*>/, ""), length)
  end
  return text + "#{link_to("Continue reading", full_url, :class=>"continue_reading")}"
end

#dates_path_helper(y = nil, m = nil, d = nil) ⇒ Object



58
59
60
# File 'lib/santey_blog/view_helper.rb', line 58

def dates_path_helper y=nil, m=nil, d=nil
	"/#{Time.parse("#{y || "01"}-#{m || "01"}-#{d || "01"}").strftime("#{"%Y#{"/%m#{"/%d" if d}" if m}" if y}")}"
end

#path_to_content(content) ⇒ Object



51
52
53
54
55
56
# File 'lib/santey_blog/view_helper.rb', line 51

def path_to_content content
  case content.class.name
  when "Post"
    root_url + "#{content.created_at.strftime("%Y/%m/%d")}/#{content.slug}"
  end
end

#posted_at_helper(content) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/santey_blog/view_helper.rb', line 66

def posted_at_helper content
  case content.class.name
  when "Post"
    "<p class='posted_on'>posted on <abbr title='#{content.created_at.strftime("%A, %B %d, %Y %H:%M:%S")}'>
#{content.created_at.strftime("%A, %B %d, %Y")}</abbr></p>"
  end
end

#santey_titleObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/santey_blog/view_helper.rb', line 37

def santey_title
	titles = SanteyBlog.meta_titles
	t = titles[params[:controller].to_sym] ? titles[params[:controller].to_sym][params[:action].to_sym] ? titles[params[:controller].to_sym][params[:action].to_sym] : titles[params[:controller].to_sym][:default] : titles[:default]
  case t
  when /%post_title%/
    t = t.gsub(/%post_title%/, @post.title)
  when /%tag%/
    t = t.gsub(/%tag%/, @tag)
  end
  content_for :title do
    t
  end
end

#tag_path_helper(tag) ⇒ Object



62
63
64
# File 'lib/santey_blog/view_helper.rb', line 62

def tag_path_helper tag
  "/tag/#{tag}"
end