Module: CmsFilters

Defined in:
app/liquid/filters/cms_filters.rb

Defined Under Namespace

Modules: Protected

Instance Method Summary collapse

Instance Method Details

#asset_url(name) ⇒ Object



106
107
108
109
110
111
112
113
# File 'app/liquid/filters/cms_filters.rb', line 106

def asset_url(name)
  asset = @context.registers[:context].assets.find_by_asset_file_name name
  if asset
    asset.asset.url
  else
    raise Liquid::Error, "'#{name}' asset not found."
  end
end

#assign_to(value, name) ⇒ Object



81
82
83
84
# File 'app/liquid/filters/cms_filters.rb', line 81

def assign_to(value, name)
  @context[name] = value
  nil
end

#component_url(path) ⇒ Object



115
116
117
118
# File 'app/liquid/filters/cms_filters.rb', line 115

def component_url(path)
  context = @context.registers[:context]
  "/" + Cms::Component.base_path(context).join(path).to_s
end

#image_tag(url, title = nil, size = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'app/liquid/filters/cms_filters.rb', line 67

def image_tag(url, title = nil, size = nil)
  return '' if url.blank?

  Protected.config = @context.registers[:controller]

  options = title.present? ? {:title => title, :alt => title} : {}
  options[:size] = size if size.present?
  Protected.image_tag url, options
end

#json(value) ⇒ Object



35
36
37
# File 'app/liquid/filters/cms_filters.rb', line 35

def json(value)
  value.to_json 
end


77
78
79
# File 'app/liquid/filters/cms_filters.rb', line 77

def link_to(url, text = nil)
  Protected.link_to text, url
end

#money(value, precision = 0) ⇒ Object



31
32
33
# File 'app/liquid/filters/cms_filters.rb', line 31

def money(value, precision = 0)
  Protected.number_to_currency value, :precision => precision
end

#page_url(name) ⇒ Object



97
98
99
100
101
102
103
104
# File 'app/liquid/filters/cms_filters.rb', line 97

def page_url(name)
  page = @context.registers[:context].pages.find_by_name name
  if page && page.url.present?
    page.url
  else
    raise Liquid::Error, "'#{name}' page not found."
  end
end

#paginate_collection(collection, limit, page) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'app/liquid/filters/cms_filters.rb', line 86

def paginate_collection(collection, limit, page)
  res = collection.paginate :page => page, :per_page => limit rescue WillPaginate::InvalidPage raise Liquid::SyntaxError, $!.message
  @context['paginate'] = {
    'total_pages' => res.total_pages,
    'current_page' => res.current_page,
    'previous_page' => res.previous_page,
    'next_page' => res.next_page,
  }
  res
end

#script_tag(url) ⇒ Object



55
56
57
58
# File 'app/liquid/filters/cms_filters.rb', line 55

def script_tag(url)
  Protected.config = @context.registers[:controller]
  Protected.javascript_include_tag url
end

#stylesheet_tag(url) ⇒ Object



60
61
62
63
64
65
# File 'app/liquid/filters/cms_filters.rb', line 60

def stylesheet_tag(url)
  return '' if url.blank?

  Protected.config = @context.registers[:controller]
  Protected.stylesheet_link_tag url
end

#textilize(text, with_paragraphs = true) ⇒ Object



47
48
49
50
51
52
53
# File 'app/liquid/filters/cms_filters.rb', line 47

def textilize(text, with_paragraphs = true)
  if with_paragraphs
    Protected.textilize text
  else
    Protected.textilize_without_paragraph text
  end
end

#url_decode(value) ⇒ Object



43
44
45
# File 'app/liquid/filters/cms_filters.rb', line 43

def url_decode(value)
  CGI::unescape(value || '')
end

#url_encode(value) ⇒ Object



39
40
41
# File 'app/liquid/filters/cms_filters.rb', line 39

def url_encode(value)
  CGI::escape(value || '')
end