Sha256: 9ddb65311e7b39e5af6253ce688620056b80beadce18aae8b5522071b314c846
Contents?: true
Size: 1.04 KB
Versions: 6
Compression:
Stored size: 1.04 KB
Contents
module Smithy module Liquid module Filters module AssetTag def image_tag(input, *args) image_options = inline_options(args_to_options(args)) "<img src=\"#{input}\" #{image_options}>" end protected # Convert an array of properties ('key:value') into a hash # Ex: ['width:50', 'height:100'] => { :width => '50', :height => '100' } def args_to_options(*args) options = {} args.flatten.each do |a| if (a =~ /^(.*):(.*)$/) options[$1.to_sym] = $2 end end options end # Write options (Hash) into a string according to the following pattern: # <key1>="<value1>", <key2>="<value2", ...etc def inline_options(options = {}) return '' if options.empty? (options.stringify_keys.sort.to_a.collect { |a, b| "#{a}=\"#{b}\"" }).join(' ') << ' ' end end ::Liquid::Template.register_filter(AssetTag) end end end
Version data entries
6 entries across 6 versions & 1 rubygems