module Locomotive::Steam::Liquid::Filters::Base

Public Instance Methods

absolute_url(url) click to toggle source
# File lib/locomotive/steam/liquid/filters/base.rb, line 7
def absolute_url(url)
  url =~ Locomotive::Steam::IsHTTP ? url : URI.join(@context['base_url'], url).to_s
end

Protected Instance Methods

any_asset_url(input, extension = nil, folder = nil) click to toggle source
# File lib/locomotive/steam/liquid/filters/base.rb, line 38
def any_asset_url(input, extension = nil, folder = nil)
  return '' if input.nil?

  if input =~ /^https?:/
    input
  else
    uri = input.starts_with?('/') ? URI(input) : URI(asset_url(folder.blank? ? input : "#{folder}/#{input}"))
    uri.path = "#{uri.path}#{extension}" unless extension.blank? || uri.path.ends_with?(extension)
    uri.to_s
  end
end
args_to_options(*args) click to toggle source

Convert an array of properties ('key:value') into a hash Ex: ['width:50', 'height:100'] => { width: '50', height: '100' }

# File lib/locomotive/steam/liquid/filters/base.rb, line 15
def args_to_options(*args)
  options = {}
  args.flatten.each do |a|
    if (a =~ /^(.*):(.*)$/)
      options[$1.to_sym] = $2
    end
  end
  options
end
asset_url(path) click to toggle source
# File lib/locomotive/steam/liquid/filters/base.rb, line 50
def asset_url(path)
  @context.registers[:services].theme_asset_url.build(path)
end
get_url_from_asset(input) click to toggle source

Get the url to be used in html tags such as image_tag, flash_tag, …etc input: url (String) OR asset drop

# File lib/locomotive/steam/liquid/filters/base.rb, line 34
def get_url_from_asset(input)
  input.respond_to?(:url) ? input.url : input
end
inline_options(options = {}) click to toggle source

Write options (Hash) into a string according to the following pattern: <key1>=“<value1>”, <key2>=“<value2”, …etc

# File lib/locomotive/steam/liquid/filters/base.rb, line 27
def inline_options(options = {})
  return '' if options.empty?
  (options.stringify_keys.sort.to_a.collect { |a, b| "#{a}=\"#{b}\"" }).join(' ') << ' '
end