Module: Skyline::PagesHelper

Defined in:
app/helpers/skyline/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#renderable_templates_select(object, form, options = {}) ⇒ Object

Renders a label and selectbox for the sectionable_type passed in, it doesn't render anything if there is only one template.

Parameters

st<String,Symbol>

The sectionable type

form

The formbuilder to place this select in.

options

See options

Options

:label<String,false> :: Use another label or false for no label

Returns

String

The label and the selectbox

nil

Nil if there is nothing to render

--



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/skyline/pages_helper.rb', line 18

def renderable_templates_select(object, form, options = {})
  raise "@renderable_scope not available" unless @renderable_scope
  
  return nil if @renderable_scope.templates_for(object).size <= 1
  
  options.reverse_merge! :label => Skyline::Section.human_attribute_name("template")
  
  out = []
  if options[:label]
    out << form.label(:template, options[:label]) 
    out << ": "
  end
  out << form.select(:template, templates_for_select(object) )
  out.join
end

#templates_for_select(object) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'app/helpers/skyline/pages_helper.rb', line 34

def templates_for_select(object)
  raise "@renderable_scope not available" unless @renderable_scope
  
  scope = [:templates]
  scope += object.class.name.sub(/^Skyline::/,"").underscore.split("/").map(&:to_sym)
  templates = @renderable_scope.templates_for(object).dup
  templates = (["default"] + templates) if templates.delete("default")
  templates.map {|tmpl| [t(tmpl,:scope => scope, :default => tmpl),tmpl]  }
end