Module: Dugway::Filters::UrlFilters

Defined in:
lib/dugway/liquid/filters/url_filters.rb

Instance Method Summary collapse

Instance Method Details

#constrain(url = nil, width = 0, height = 0) ⇒ Object

To get max_w-100 Eg product.primary_image | product_image_url | constrain : ‘100’ To get max_h-100 Eg product.primary_image | product_image_url | constrain : ‘-’, ‘100’ To get max_h-100+max_w-100 Eg product.primary_image | product_image_url | constrain : ‘100’, ‘100’



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dugway/liquid/filters/url_filters.rb', line 17

def constrain(url = nil, width = 0, height = 0)
  if url
    parsed_url = URI.parse(url)
    path_parts = parsed_url.path.split('/')

    width = width.to_i
    height = height.to_i

    path_parts.slice(-2).tap do |size|
      unless width == 0 && height == 0
        size.gsub!(/(max_w-)\d+/) do |match|
          width == 0 ? '' : "#{ $1 }#{ width }"
        end

        size.gsub!(/(max_h-)\d+/) do |match|
          height == 0 ? '' : "#{ $1 }#{ height }"
        end

        size.gsub!(/\+/, '') if width == 0 || height == 0
      end
    end

    parsed_url.path = path_parts.join('/')
    parsed_url.to_s
  end
end


4
5
6
7
8
9
# File 'lib/dugway/liquid/filters/url_filters.rb', line 4

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)
   :a, text, options
end

#product_image_url(image = nil, size = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/dugway/liquid/filters/url_filters.rb', line 44

def product_image_url(image = nil, size = nil)
  width, height = legacy_size_for(size)

  if image.blank?
    image_url_hash('http://images.cdn.bigcartel.com/missing/-/missing.png', height, width)
  else
    image_url_hash(image['url'], height, width)
  end
end

#theme_css_url(theme) ⇒ Object



64
65
66
# File 'lib/dugway/liquid/filters/url_filters.rb', line 64

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

#theme_font_url(filename) ⇒ Object



72
73
74
# File 'lib/dugway/liquid/filters/url_filters.rb', line 72

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

#theme_image_url(filename) ⇒ Object



68
69
70
# File 'lib/dugway/liquid/filters/url_filters.rb', line 68

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

#theme_js_url(name) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/dugway/liquid/filters/url_filters.rb', line 54

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