Sha256: d4a706fbe06593341f0a0fdeb75d4534979fc4964ee54eda3fec4558fd87a428

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Geri
  module Admin::PagesHelper

    def geri_sanitize(content)
      ActionController::Base.helpers.sanitize(content, {
        tags:       %w{ p div strong ol ul li em},
        attributes: %w{ href target }
      })
    end

    def editable(name, &block)
      name    = "#{current_page}_#{name}"
      content = Content.find_by(name: name) && geri_sanitize(Content.find_by(name: name).body)
      content ||= capture(&block)
      if current_user
        content = capture do
          content_tag(:div, contenteditable: true, id: name, class: 'editable') { content }
        end
        unless @ckeditor_loaded
          content << javascript_tag('window.CKEDITOR_BASEPATH = "assets/ckeditor/"')
          content << javascript_include_tag('ckeditor/ckeditor')
          content << javascript_tag('CKEDITOR.disableAutoInline = true')
          @ckeditor_loaded = true
        end
        unless @editor_loaded
          content << stylesheet_link_tag('geri/admin/editor')
          content << javascript_include_tag('geri/admin/editor')
        end
        content << javascript_tag do
          %Q{
            CKEDITOR.inline('#{name}', {
              on: {
                change: function(event) {
                  GERI_EDITOR.update(event.editor.name)
                 }
              }
            })
          }.html_safe
        end
      end
      content
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geri-0.0.1 app/helpers/geri/admin/pages_helper.rb