class TrustyCms::Setup

def load_database_template(filename)

def load_database_template(filename)
  template = nil
  if filename
    name = find_template_in_path(filename)
    unless name
      announce "Invalid template name: #{filename}"
      filename = nil
    else
      template = load_template_file(name)
    end
  end
  unless filename
    templates = find_and_load_templates("#{TRUSTY_CMS_ROOT}/db/templates/*.yml")
    templates.concat find_and_load_templates("#{TRUSTY_CMS_ROOT}/vendor/extensions/**/db/templates/*.yml")
    TrustyCms::Extension.descendants.each do |d|
      templates.concat find_and_load_templates(d.root + '/db/templates/*.yml')
    end
    templates.concat find_and_load_templates("#{Rails.root}/vendor/extensions/**/db/templates/*.yml")
    templates.concat find_and_load_templates("#{Rails.root}/db/templates/*.yml")
    templates.uniq!
    choose do |menu|
      menu.header = "\nSelect a database template"
      menu.prompt = "[1-#{templates.size}]: "
      menu.select_by = :index
      templates.each { |t| menu.choice(t['name']) { template = t } }
    end
  end
  create_records(template)
end