Module: Geri::PagesHelper

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

Instance Method Summary collapse

Instance Method Details

#current_siteObject



12
13
14
# File 'app/helpers/geri/pages_helper.rb', line 12

def current_site
  Geri::Config.sites[request.host] || Geri::Config.sites[:default]
end

#editable(name, &block) ⇒ Object



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
63
64
65
66
# File 'app/helpers/geri/pages_helper.rb', line 35

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



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

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


16
17
18
19
# File 'app/helpers/geri/pages_helper.rb', line 16

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



28
29
30
31
32
33
# File 'app/helpers/geri/pages_helper.rb', line 28

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



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

def site_name
  current_site.name
end

#titleObject



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

def title
  @metadata[:title]
end