Sha256: 1132c26085526f5df5868f1b0a04b6e255c412c38b09c3b297c6df0cf529e56e
Contents?: true
Size: 1.78 KB
Versions: 22
Compression:
Stored size: 1.78 KB
Contents
module Scrivito class AttributeValueRenderer < Struct.new(:view) def render(value, type) method_name = "render_as_#{type}" respond_to?(method_name) ? public_send(method_name, value) : value end def render_as_date(date) if date html_escape(localize(date)) end end def render_as_enum(enum) enum.to_s end def render_as_html(html) if html cms_routing = CmsRouting.new(view.request, view, view.scrivito_engine) cms_routing.convert_links(html).html_safe end end def render_as_link(link) if link link_to(link.display_title, scrivito_path(link)) end end def render_as_linklist(linklist) if linklist.any? content_tag(:ul) do capture do linklist.each do |link| concat content_tag(:li) { render_as_link(link) } end end end end end def render_as_multienum(multienum) render_as_stringlist(multienum) end def render_as_reference(reference) reference.try(:description_for_editor) end def render_as_referencelist(referencelist) if referencelist.any? content_tag(:ul) do capture do referencelist.each do |reference| concat content_tag(:li) { render_as_reference(reference) } end end end end end def render_as_string(string) string.is_a?(HtmlString) ? render_as_html(string) : html_escape(string) end def render_as_stringlist(stringlist) stringlist.join(', ') end private delegate :capture, :concat, :content_tag, :localize, :link_to, :scrivito_path, to: :view def html_escape(string) ERB::Util.html_escape(string) end end end
Version data entries
22 entries across 22 versions & 1 rubygems