Module: ComfortableMexicanSofa::ViewMethods::Helpers

Defined in:
lib/comfortable_mexican_sofa/view_methods.rb

Instance Method Summary collapse

Instance Method Details

#cms_block_content(identifier, blockable = @cms_page) ⇒ Object

Content of a page block. This is how you get content from page:field Example:

cms_block_content(:left_column, CmsPage.first)
cms_block_content(:left_column) # if @cms_page is present


58
59
60
61
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 58

def cms_block_content(identifier, blockable = @cms_page)
  return '' unless tag = ComfortableMexicanSofa::ViewMethods.cms_block_tag(identifier, blockable)
  tag.content
end

#cms_block_content_render(identifier, blockable = @cms_page) ⇒ Object

For those times when we need to render content that shouldn’t be renderable Example: {cms:field} tags



65
66
67
68
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 65

def cms_block_content_render(identifier, blockable = @cms_page)
  return '' unless tag = ComfortableMexicanSofa::ViewMethods.cms_block_tag(identifier, blockable)
  render :inline => ComfortableMexicanSofa::Tag.process_content(blockable, tag.content)
end

#cms_block_render(identifier, blockable = @cms_page) ⇒ Object

Same as cms_block_content but with cms tags expanded



71
72
73
74
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 71

def cms_block_render(identifier, blockable = @cms_page)
  return '' unless tag = ComfortableMexicanSofa::ViewMethods.cms_block_tag(identifier, blockable)
  render :inline => ComfortableMexicanSofa::Tag.process_content(blockable, tag.render)
end

#cms_hook(name, options = {}) ⇒ Object

Injects some content somewhere inside cms admin area



16
17
18
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 16

def cms_hook(name, options = {})
  ComfortableMexicanSofa::ViewHooks.render(name, self, options)
end

#cms_snippet_content(identifier, cms_site = @cms_site, &block) ⇒ Object

Content of a snippet. Examples:

cms_snippet_content(:my_snippet)
<%= cms_snippet_content(:my_snippet) do %>
  Default content can go here.
<% end %>


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 25

def cms_snippet_content(identifier, cms_site = @cms_site, &block)
  unless cms_site
    host, path = request.host.downcase, request.fullpath if respond_to?(:request) && request
    cms_site = Comfy::Cms::Site.find_site(host, path)
  end
  return '' unless cms_site

  snippet = cms_site.snippets.find_by_identifier(identifier)

  if !snippet && block_given?
    snippet = cms_site.snippets.create(
      :identifier => identifier,
      :label      => identifier.to_s.titleize,
      :content    => capture(&block)
    )
  end

  snippet ? snippet.content : ''
end

#cms_snippet_render(identifier, cms_site = @cms_site, &block) ⇒ Object

Same as cms_snippet_content but cms tags will be expanded



46
47
48
49
50
51
52
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 46

def cms_snippet_render(identifier, cms_site = @cms_site, &block)
  return '' unless cms_site
  content = cms_snippet_content(identifier, cms_site, &block)
  render :inline => ComfortableMexicanSofa::Tag.process_content(
    cms_site.pages.build, ComfortableMexicanSofa::Tag.sanitize_irb(content)
  )
end

#comfy_form_for(record, options = {}, &proc) ⇒ Object

Wrapper around ComfortableMexicanSofa::FormBuilder



9
10
11
12
13
# File 'lib/comfortable_mexican_sofa/view_methods.rb', line 9

def comfy_form_for(record, options = {}, &proc)
  options[:builder] = ComfortableMexicanSofa::FormBuilder
  options[:layout] ||= :horizontal
  bootstrap_form_for(record, options, &proc)
end