Module: Geri::PagesHelper

Included in:
Admin::EditorController
Defined in:
app/helpers/geri/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#editable(name, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/geri/pages_helper.rb', line 31

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
      (: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

#geri_sanitize(content) ⇒ Object



13
14
15
16
17
18
# File 'app/helpers/geri/pages_helper.rb', line 13

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


8
9
10
11
# File 'app/helpers/geri/pages_helper.rb', line 8

def link_to_with_active(name, options = {}, html_options = {}, &block)
  html_options[:class] = html_options[:class] ? html_options[:class] + ' active' : 'active' if current_page?(options)
  link_to name, options, html_options, &block
end

#meta_tagsObject



20
21
22
23
24
25
# File 'app/helpers/geri/pages_helper.rb', line 20

def meta_tags
  concat((:meta, '', name: :copyright,   content: @metadata[:copyright]))          if @metadata[:copyright]
  concat((:meta, '', name: :description, content: @metadata[:description]))        if @metadata[:description]
  concat((:meta, '', name: :keywords,    content: @metadata[:keywords].join(','))) if @metadata[:keywords]
  concat((:meta, '', name: :robots,      content: @metadata[:robots]))             if @metadata[:robots]
end

#site_nameObject



27
28
29
# File 'app/helpers/geri/pages_helper.rb', line 27

def site_name
  Geri::Config.site_name
end

#titleObject



4
5
6
# File 'app/helpers/geri/pages_helper.rb', line 4

def title
  @metadata[:title]
end