[Opda-develop] OPDA/app/controllers/admin categories_controller.rb, 1.1, 1.2
Brought to you by:
digitalpodcast
|
From: Alex N. <dig...@us...> - 2006-07-17 05:14:12
|
Update of /cvsroot/opda/OPDA/app/controllers/admin In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11815/app/controllers/admin Modified Files: categories_controller.rb Log Message: added ability to set up categories Index: categories_controller.rb =================================================================== RCS file: /cvsroot/opda/OPDA/app/controllers/admin/categories_controller.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** categories_controller.rb 24 Jun 2006 07:12:24 -0000 1.1 --- categories_controller.rb 17 Jul 2006 05:14:09 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- class Admin::CategoriesController < ApplicationController layout "layouts/admin" + require 'yaml' def index list *************** *** 46,48 **** --- 47,82 ---- redirect_to :action => 'list' end + + def category_setup + begin + xml = "" + xml = REXML::Document.new(File.open('config/opda/itunes_categories.xml')) + rescue => error + text = "file not found" + end + + @xml= parse(xml.elements['opml/body'], 0) + + end + + def parse(xml, parent_id) + gothere="" + begin + xml.elements.each('outline') { |el| + @category = Category.new(:parent_id => parent_id) + if (el.elements.size != 0) + @category.title = el.attributes["text"] + @category.reload if @category.save + parse(el, @category.id) + else + @category.title = el.attributes["text"] + @category.save + gothere ="yes" + end + } + rescue => error + text = "parser error" + end + return gothere + end end |