Module: Cmsable::CmsableHelper

Defined in:
app/helpers/cmsable/cmsable_helper.rb

Overview

Cmsable view helpers

Constant Summary collapse

TYPES =
[
  :rich, # CKEditor (default)
  :plain # Nothing fancy
]
DEFAULTS =
{
  readonly: false, # Can edit by default
  type: :rich,      # Use rich text editor by default
  plantext: false,  # No text editor
  tag: nil # What tag to use for contenteditable
}

Instance Method Summary collapse

Instance Method Details

#cms(name_or_model, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/cmsable/cmsable_helper.rb', line 22

def cms(name_or_model, options = {})
  model = get_model name_or_model

  options = DEFAULTS.merge options

  # Fail on unknow types
  type_fail options[:type] unless TYPES.include? options[:type]

  # Skip checking permission if set to readonly or
  # explicit authorisation is passed
  readonly = options.include?(:authorised) || options[:readonly]
  options[:authorised] = authorised?(model) unless readonly

  content = model.send(model.cmsable_body).html_safe
  editable = options[:authorised] && !options[:readonly]

  editable ? show_cmsable(content, model, options) : uncmsable(content, options[:tag])
end

#cmsable_assetsObject



5
6
7
8
# File 'app/helpers/cmsable/cmsable_helper.rb', line 5

def cmsable_assets
  javascript_include_tag('cmsable/application') +
  stylesheet_link_tag('cmsable/application')
end