Class: Liquid::Locomotive::Tags::InlineEditor

Inherits:
Tag
  • Object
show all
Defined in:
lib/locomotive/liquid/tags/inline_editor.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/locomotive/liquid/tags/inline_editor.rb', line 6

def render(context)
  if context.registers[:current_locomotive_account] && context.registers[:inline_editor]

    plugins = 'common/format,common/table,common/list,common/link,common/highlighteditables,common/block,common/undo,common/contenthandler,common/paste,common/commands,common/abbr,common/align,common/horizontalruler,custom/locomotive_media'

    controller = context.registers[:controller]
    controller.instance_variable_set(:@plugins, plugins)

    page = context.registers[:page].to_presenter.as_json_for_html_view
    page['lang'] = context['locale']

    html = <<-HTML
      %meta{ :content => true, :name => 'inline-editor' }

      = stylesheet_link_tag 'aloha/css/aloha.css'
      = javascript_include_tag 'locomotive/aloha', :'data-aloha-plugins' => @plugins

      %script{ :type => 'text/javascript' }
        :plain
          Aloha.ready(function() \{
            window.parent.application_view.set_page(#{controller.view_context.j page.to_json.html_safe});
          \});
    HTML

    Haml::Engine.new(html.gsub(/\n+/, "\n").gsub(/^\s{14}/, ''), :escape_html => true).render(controller.view_context)
  else
    ''
  end
end