Module: EditableContent::ControllerFunctions

Defined in:
lib/editable_content/controller_helper.rb

Instance Method Summary collapse

Instance Method Details

#getContent(name = "") ⇒ Object

This function retrieves the editable content from the database. If setEditableAuthorization is set to true then a button to launch the editor is prepended to the content.

Each editable field needs will need one editor and they are created with the create_content_editor function in the view file.

Parameters:

name This is the name of the field. This is the same name that will be passed into the create_content_editor function.

Usage:

def index
  @content = getContent("maintext")
end


21
22
23
24
25
26
27
# File 'lib/editable_content/controller_helper.rb', line 21

def getContent(name="")
  text = "<div id=\"ec_edit_frame_#{name}\">" + getInnerContent(name, controller_name(), action_name()) + "</div>"
  if $editable_content_authorization
    text = "<img id=\"ec_edit_button_#{name}\" class=\"edit_icon\" width=\"16\" height=\"16\" src=\"/images/pencil.png\" title=\"Edit this Content\" alt=\"Edit this Content Button\" />" + text
  end
  text.html_safe
end

#processContent(content = nil) ⇒ Object

This function formats the supplied content using the same processor that editable content uses.

Parameters:

content The text to be converted. This expects a textile formated string and returns html formated text suitable for display.

Usage:

def index
  @content = processContent("This is *textile* _text_.")
end


42
43
44
45
46
47
48
# File 'lib/editable_content/controller_helper.rb', line 42

def processContent(content=nil)
  if content
    text = parseContent(content.gsub(/&#39;/, "'"))
  else
    text = "<div class=\"error\">No Content.</div>".html_safe
  end
end

#setEditableAuthorization(permission = false) ⇒ Object

This is used to set up the permissions for the editable content system. This allows you to control who can edit a editable content field.

Parameters:

permission A boolean value. If true the editor is created and enabled, if false the editor is not created.

Usage:

The easiest way to use the permissions system is to use a before_filter in the application_controller, like this:

before_filter proc{ setEditableAuthorization(current_user.is?( :editor )) }

In this example, if the current user is an editor then they can edit fields.



65
66
67
# File 'lib/editable_content/controller_helper.rb', line 65

def setEditableAuthorization(permission = false)
  $editable_content_authorization = permission
end