Module: StaticBlocks::SnippetsHelper

Defined in:
lib/static_blocks/helpers.rb

Instance Method Summary collapse

Instance Method Details

#snippet_for(title, default = nil) ⇒ Object Also known as: s



3
4
5
6
7
8
9
10
11
12
# File 'lib/static_blocks/helpers.rb', line 3

def snippet_for(title, default = nil)
  Rails.cache.fetch("snippet::"+I18n.locale.to_s+"::"+title.to_s) do
    snippet = Snippet.published.find_by_title(title.to_s)
    if snippet
      snippet.content
    else
      "Snippet for #{title.to_s} missing"
    end
  end
end

#snippet_published?(title) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/static_blocks/helpers.rb', line 14

def snippet_published?(title)
  Rails.cache.fetch("snippet::"+I18n.locale.to_s+"::"+title.to_s) do
    Snippet.published.find_by_title(title.to_s) || false
  end
end