lib/tasks/pages_tree.rake
# Recursively creates pages from a root
Recursively creates pages from a root
Recursively creates pages from a root
def create_page(page, lang, parent_id=0)
    p = Page.new :title => page['title'],
                 :pretty_url => page['pretty_url'],
                 :filename => page['filename'],
                 :lang => lang,
                 :parent_id => parent_id
    p.go_to_first_child = page['options']['go_to_first_child'] if page['options'] && page['options']['go_to_first_child']
    p.override_url = page['options']['override_url'] if page['options'] && page['options']['override_url']
    p.meta_title = page['options']['meta_title'] if page['options'] && page['options']['meta_title']
    p.meta_keywords = page['options']['meta_keywords'] if page['options'] && page['options']['meta_keywords']
    p.meta_description = page['options']['meta_description'] if page['options'] && page['options']['meta_description']
    p.layout_name = page['options']['layout_name'] if page['options'] && page['options']['layout_name']
    if p.save
      draw_tree(p)
      create_file(p.filename) if !p.filename.blank?
      if !page['children'].blank?
        page['children'].each_with_index do |child, index|
          create_page(child, lang, p.id)
        end   
      end
    else
      puts "========================== Error creating page \'#{p.title}\' =========================="
      p.errors.map {|e| puts e}
    end
  end
def create_page ( page , lang , parent_id = 0 ) p = Page . new :title => page [ 'title' ] , :pretty_url => page [ 'pretty_url' ] , :filename => page [ 'filename' ] , :lang => lang , :parent_id => parent_id p . go_to_first_child = page [ 'options' ] [ 'go_to_first_child' ] if page [ 'options' ] && page [ 'options' ] [ 'go_to_first_child' ] p . override_url = page [ 'options' ] [ 'override_url' ] if page [ 'options' ] && page [ 'options' ] [ 'override_url' ] p . meta_title = page [ 'options' ] [ 'meta_title' ] if page [ 'options' ] && page [ 'options' ] [ 'meta_title' ] p . meta_keywords = page [ 'options' ] [ 'meta_keywords' ] if page [ 'options' ] && page [ 'options' ] [ 'meta_keywords' ] p . meta_description = page [ 'options' ] [ 'meta_description' ] if page [ 'options' ] && page [ 'options' ] [ 'meta_description' ] p . layout_name = page [ 'options' ] [ 'layout_name' ] if page [ 'options' ] && page [ 'options' ] [ 'layout_name' ] if p . save draw_tree ( p ) create_file ( p . filename ) if ! p . filename . blank? if ! page [ 'children' ] . blank? page [ 'children' ] . each_with_index do | child , index | create_page ( child , lang , p . id ) end end else puts "========================== Error creating page \'#{p.title}\' ==========================" p . errors . map { | e | puts e } end end
Recursively creates pages from a root
Recursively creates pages from a root
# Options #Starts recursion
page
<not_specific>
lang
<not_specific>
parent_id
<not_specific>