module MasterView module Directives # creates a image_tag. # if path is specified in attr_value then it will be used exactly as listed, otherwise if attr_value is empty # then masterview will attempt to find the public/images in the string and infer the path from what follows. # otherwise it will simply use the src path. # If both width and height attr values are specified then it will build the :size option from them. # Other html attributes will be passed into image_tag options. class ImageTag < MasterView::DirectiveBase # /public\/images\/(.*)/ IMAGE_SRC_EXTRACT_REGEX = MasterView::ConfigSettings.template_asset_base_ref_pattern[:images] metadata :priority => :default, :category => 'asset', :description => 'Replaces the element using the Rails image_tag helper.', :element_usage => 'img' attr_arg :src attr_arg :options, :append_element_attrs => [:common_html] event :element do if (@src.nil? or @src.empty?) and src_attr = element_attrs[:src] if match = IMAGE_SRC_EXTRACT_REGEX.match(src_attr) @src = match[1] else @src = src_attr end end @src = quote(@src) unless @src.nil? render erb_content('image_tag', :src, :options) end end end end