Sha256: c993e4c9877267725b66f45b07e06f55a43ac79cc3b3fe8f83e8972f14efab9c
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
module Spontaneous::Media::Image module Renderable attr_accessor :template_params def render(format=:html, params = {}, parent_context = nil) case format when "html", :html to_html(params) else value end end alias_method :render_inline, :render def to_html(attr={}) default_attr = { :src => src, :width => width, :height => height, :alt => "" } default_attr.delete(:width) if (width.nil? || width == 0) default_attr.delete(:height) if (height.nil? || height == 0) if template_params && template_params.length > 0 && template_params[0].is_a?(Hash) attr = template_params[0].merge(attr) end if attr.key?(:width) || attr.key?(:height) default_attr.delete(:width) default_attr.delete(:height) if (attr.key?(:width) && !attr[:width]) || (attr.key?(:height) && !attr[:height]) attr.delete(:width) attr.delete(:height) end end attr = default_attr.merge(attr) params = [] attr.each do |name, value| params << %(#{name}="#{value.to_s.escape_html}") end %(<img #{params.join(' ')} />) end def to_s src end def /(value) return value if self.blank? self end end end
Version data entries
4 entries across 4 versions & 1 rubygems