Sha256: fa856214884c3e78217f0bb1217918e11bfae4ba7cf89d35a5aa33cc594dc06a

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

module Skyline::PagesHelper  
  
  # 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<FormBuidler> :: The formbuilder to place this select in.
  # options<Hash>     :: 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
  # --
  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
  
  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
  
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
skylinecms-3.1.0 app/helpers/skyline/pages_helper.rb
westarete-skylinecms-3.0.8.20100329 app/helpers/skyline/pages_helper.rb
westarete-skylinecms-3.0.8.20100330 app/helpers/skyline/pages_helper.rb
skylinecms-3.0.8 app/helpers/skyline/pages_helper.rb
skylinecms-3.0.7 app/helpers/skyline/pages_helper.rb