Module: Templates::Helper

Defined in:
lib/templates/helper.rb

Instance Method Summary collapse

Instance Method Details

#child_menu_for(page) ⇒ Object

For Radiant before MenuRenderer implemented



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/templates/helper.rb', line 58

def child_menu_for(page)
  children = children_for(page)
  templates = Template.all
  unless children.size == 0 || templates.empty?
    children << templates.unshift(:separator)
    children.flatten!
  end
  return nil if children.size < 2
  children.unshift(children.delete(page.default_child), :separator) if children.include?(page.default_child)
  name_for = proc { |p| (name = p.name.to_name('Page')).blank? ? t('normal_page') : name }
   :ul, :class => 'menu', :id => "allowed_children_#{page.id}" do
    children.map do |child|
      if child == :separator
         :li, nil, :class => 'separator'
      elsif child.is_a?(Template)
         :li, link_to(image('template') + ' ' + child.name, new_admin_page_child_path(page, :template => child), :title => "Add child using #{child.name} Template")
      else
         :li, link_to(name_for[child], new_admin_page_child_path(page, :page_class => child), :title => clean_page_description(child))
      end
    end
  end
end

#page_part_name(index) ⇒ Object



3
4
5
# File 'lib/templates/helper.rb', line 3

def page_part_name(index)
  "page[parts_attributes][#{index}]"
end

#template_part_field(template_part, index, drafts_enabled = false) ⇒ Object



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/templates/helper.rb', line 7

def template_part_field(template_part, index, drafts_enabled = false)
  field_html = []
  if drafts_enabled
    live_part_content = @page.part(template_part.name).try(:content) || '' rescue ''
    live_field_name = "#{page_part_name(index)}[content]"
    live_field_id = "page_parts_#{index}_content"
    # part_content = @page.part(template_part.name).try(:draft_content) || ''
    part_content = @page.part(template_part.name).try(:draft_content) || '' rescue ''
    field_name = "#{page_part_name(index)}[draft_content]"
    field_id = "page_parts_#{index}_draft_content"
    field_html << hidden_field_tag(live_field_name, h(live_part_content), :id => live_field_id)
  else
    part_content = @page.part(template_part.name).try(:content) || '' rescue ''
    field_name = "#{page_part_name(index)}[content]"
    field_id = "page_parts_#{index}_content"
  end

  options = {:class => template_part.part_type.field_class, 
             :style => template_part.part_type.field_styles,
             :id => field_id}.reject{ |k,v| v.blank? }

  case template_part.part_type.field_type
    when "text_area"
      field_html << text_area_tag(field_name, part_content, options)

    when "text_field"
      field_html << text_field_tag(field_name, part_content, options)

    when "radio_button"
      options[:style] = "display:inline;margin-left:1em;"
      options [:style] << template_part.part_type.field_styles if template_part.part_type.field_styles
      field_html << "<span>"
      options[:id] = "#{field_id}_true"
      field_html << "&mdash;" + radio_button_tag(field_name, "true", part_content =~ /true/, options)
      field_html << label_tag("True",nil,:style=>"display:inline;")
      options[:id] = "#{field_id}_false"
      field_html << radio_button_tag(field_name, "false", part_content !~ /true/, options)
      field_html << label_tag("False",nil,:style=>"display:inline;")
      field_html << "</span>"

    when "hidden"
      field_html << hidden_field_tag(field_name, part_content, options)

    when "predefined"
      field_html << hidden_field_tag(field_name, template_part.description, options)
  end

  field_html.join("\n")
end