Sha256: 4e44c4fcf73afc2a3861570d43267548e2c04d6c982adac36c4419eda8085989

Contents?: true

Size: 1.71 KB

Versions: 15

Compression:

Stored size: 1.71 KB

Contents

module Dugway
  module Filters
    module UrlFilters
      def link_to(item, *args)
        options = link_args_to_options(args)
        text = options.delete(:text) || h(item['name'])
        options = { :title => "View #{ text }", :href => item['url'] }.merge(options)
        content_tag :a, text, options
      end

      def constrain(url = nil, width = '-', height = '-')
        return unless url
        uri = URI.parse(url)
        query = Rack::Utils.parse_nested_query uri.query
        query.update('w' => width, 'h' => height)
        query.delete_if { |k,v| v.nil? || v == '-' }
        uri.query = query.to_query
        uri.to_s
      end

      def product_image_url(image = nil, size = nil)
        url = image ? image['url'] : 'http://images.bigcartel.com/missing.png'
        size = legacy_size_for(size)
        constrain url, size, size
      end

      def theme_js_url(name)
        if name.is_a?(Drops::ThemeDrop)
          '/theme.js'
        elsif name == 'api'
          'http://cache0.bigcartel.com/api/5/api.usd.js'
        else
          name
        end
      end

      def theme_css_url(theme)
        '/theme.css'
      end

      def theme_image_url(filename)
        "/images/#{ filename }"
      end

      def theme_font_url(filename)
        "/fonts/#{ filename }"
      end

      private

      def link_args_to_options(args)
        options = {}

        [:text, :title, :id, :class, :rel].zip(args) { |key, value|
          options[key] = h(value)  unless value.nil?
        }

        options
      end

      def legacy_size_for(size)
        case size
        when 'large'  then 300
        when 'medium' then 175
        when 'thumb'  then 75
        else 1000
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dugway-1.0.14 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.13 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.12 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.10 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.9 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.8 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.7 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.6 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.5 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.4 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.3 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.2 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.1 lib/dugway/liquid/filters/url_filters.rb
dugway-1.0.0 lib/dugway/liquid/filters/url_filters.rb
dugway-0.12.3 lib/dugway/liquid/filters/url_filters.rb