Sha256: b973c3de0a9238041c99f9c8ae06b5958249c9fdbc3db398dddf9734f0d765e1

Contents?: true

Size: 1.38 KB

Versions: 21

Compression:

Stored size: 1.38 KB

Contents

module Smithy
  module Liquid
    module Filters
      module AssetTag
        def image_tag(input, *args)
          image_options = args_to_options(args)
          controller.view_context.send(:image_tag, input, image_options)
        end

        def image_path(input, *args)
          image_options = args_to_options(args)
          controller.view_context.send(:image_path, input)
        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

          def context
            context = self.instance_variable_get(:@context)
          end

          def controller
            context.registers[:controller]
          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

21 entries across 21 versions & 1 rubygems

Version Path
smithycms-0.8.1 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.7.3 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.7.2 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.7.1 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.7.0 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.10 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.5.99.3 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.9 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.7 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.6 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.5 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.4 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.3 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.5.99.2 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.5.99.1 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.5.99 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.2 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.1 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.5.2 lib/smithy/liquid/filters/asset_tag.rb
smithycms-0.6.0 lib/smithy/liquid/filters/asset_tag.rb