Permalink
Browse files

Refactoring plain html to content_tag

  • Loading branch information...
1 parent ea01e0c commit 72e9bec09b0f82d449cc0e623b01b7a19b738b93 @kirs kirs committed Jan 21, 2012
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/crummy/standard_renderer.rb
@@ -3,6 +3,7 @@
module Crummy
class StandardRenderer
include ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::OutputSafetyHelper
include ActionView::Helpers::TagHelper unless self.included_modules.include?(ActionView::Helpers::TagHelper)
# Render the list of crumbs as either html or xml
@@ -54,7 +55,7 @@ def render_crumbs(crumbs, options = {})
crumb_string = crumbs.collect do |crumb|
crumb_to_html_list(crumb, options[:links], options[:li_class], options[:active_li_class], options[:first_class], options[:last_class], (crumb == crumbs.first), (crumb == crumbs.last))
end * options[:separator]
- crumb_string = "<ul class=\"#{options[:ul_class]}\" id=\"#{options[:ul_id]}\">" + crumb_string + "</ul>"
+ crumb_string = content_tag(:ul, raw(crumb_string), :class => options[:ul_class], :id => options[:ul_id])
crumb_string
when :xml
crumbs.collect do |crumb|
@@ -82,12 +83,12 @@ def crumb_to_html_list(crumb, links, li_class, active_li_class, first_class, las
html_classes << last_class if is_last
html_classes << active_li_class unless url && links
html_classes << li_class if !is_first && !is_last && url && links
- url && links ? "<li class=\"#{html_classes.join(' ').strip}\"><a href=\"#{url}\">#{name}</a></li>" : "<li class=\"#{html_classes.join(' ').strip}\"><span>#{name}</span></li>"
+ content_tag(:li, url && links ? link_to(name, url) : content_tag(:span, name), :class => html_classes.join(' ').strip)
end
def crumb_to_xml(crumb, links, separator, is_first, is_last)
name, url = crumb
- url && links ? "<#{separator} href=\"#{url}\">#{name}</#{separator}>" : "<#{separator}>#{name}</#{separator}>"
+ raw content_tag(separator, name, :href => (url && links ? url : nil))
end
end
end

0 comments on commit 72e9bec

Please sign in to comment.