Class: DeadSimpleCMS::Rails::ActionView::Presenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/dead_simple_cms/rails/action_view/presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Presenter

Returns a new instance of Presenter.



9
10
11
# File 'lib/dead_simple_cms/rails/action_view/presenter.rb', line 9

def initialize(template)
  __setobj__(template)
end

Instance Method Details

#form(section, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dead_simple_cms/rails/action_view/presenter.rb', line 53

def form(section, options={})
  options.reverse_merge!(:builder => form_builder, :url => {:action => :edit})
  # Options passed to simple_form_for are changed inplace inside gem, see -
  # https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/action_view_extensions/form_helper.rb#L26
  options.reverse_merge!(options[:builder].form_for_options.deep_dup)

  (options[:html] ||= {}).update(:multipart => true) if section.attributes.values.any? { |a| a.input_type == :file }

  send(options[:builder].form_for_method, section, {:as => section.identifier}.update(options)) do |form|
    form.fields_for_group(section, options) + form.actions { form.update + form.preview(section) }
  end
end

#group(group, *args, &block) ⇒ Object

Renders a group into the view.



14
15
16
# File 'lib/dead_simple_cms/rails/action_view/presenter.rb', line 14

def group(group, *args, &block)
  group.render(__getobj__, *args, &block) # pass through the action_view template.
end

#section(section, options = {}) ⇒ Object



49
50
51
# File 'lib/dead_simple_cms/rails/action_view/presenter.rb', line 49

def section(section, options={})
  (:h2, section.label) + form(section, options)
end

#sectionsObject



18
19
20
# File 'lib/dead_simple_cms/rails/action_view/presenter.rb', line 18

def sections
  DeadSimpleCMS.sections.values.map { |section| section(section, options) }.join.html_safe
end

#with_bootstrap_tabs(options = {}) ⇒ Object

Public: Render the dead simple cms with tabs This is coupled with twitter bootstrap. If you are running it, this will work great, otherwise this will be sad. If you don’t have the tabs functionality included, you will have to specify the JS file with :bootstrap_tab_js. twitter.github.com/bootstrap/javascript.html#tabs



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dead_simple_cms/rails/action_view/presenter.rb', line 26

def with_bootstrap_tabs(options={})
  js = javascript_tag("    $(document).ready(function() {\n      var $tabs = $('#section-tabs a') ;\n      $tabs.click(function (e) { e.preventDefault(); $(this).tab('show'); });\n      $(\"#\" + (window.location.hash.replace(\"#\", \"\") || \"\#{DeadSimpleCMS.sections.identifiers[0]}\") + \"-tab\").tab('show');\n    })\n  JAVASCRIPT\n  js << javascript_include_tag(options.delete(:bootstrap_tab_js)) if options[:bootstrap_tab_js]\n  lis = DeadSimpleCMS.sections.values.map do |section|\n    section_id = Util.csserize(section.identifier)\n    content_tag(:li, link_to(section.label, \"#\#{section_id}\", :id => \"\#{section_id}-tab\"))\n  end.join.html_safe\n  tabs = content_tag(:ul, lis, :class => \"nav nav-tabs\", :id => \"section-tabs\")\n  sections = content_tag(:div, :class => \"tab-content\") do\n    DeadSimpleCMS.sections.values.map do |section|\n      content_tag(:div, section(section), :class => \"tab-pane\", :id => Util.csserize(section.identifier))\n    end.join.html_safe\n  end\n\n  js + tabs + sections\nend\n")