diff --git a/CHANGELOG b/CHANGELOG index 718d30a..8ce9128 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +- version: 2.0.3 (alpha) + - staugaard: Added import and export of pages in admin controller + +- version: 2.0.2 (alpha) + - staugaard: Added "unloadable" to ComatoseController (problems with ActsAsAuthenticated-integration similar to http://tinyurl.com/6caz5r) + - version: 2.0.1 (alpha) - Merged changes from andreas (http://github.com/andreas)... - andreas: Fixed comatose:admin:customize raketask (seems plugin_path was wrong, and made use of mkdir_p to avoid "File exists"-errors.) diff --git a/comatose.gemspec b/comatose.gemspec index 71f3193..5f80a8a 100644 --- a/comatose.gemspec +++ b/comatose.gemspec @@ -1,8 +1,8 @@ # Generated on Tue May 20 20:13:12 -0500 2008 Gem::Specification.new do |s| s.name = "comatose" - s.version = "2.0.2" - s.date = "2008-09-15" # 2008-05-20 + s.version = "2.0.3" + s.date = "2008-10-10" # 2008-05-20 s.summary = "Micro CMS designed for being embedded into existing Rails applications" s.email = "matt@elucidata.net" s.rubyforge_project = 'comatose' diff --git a/lib/comatose_admin_controller.rb b/lib/comatose_admin_controller.rb index 42af3d2..c30d580 100644 --- a/lib/comatose_admin_controller.rb +++ b/lib/comatose_admin_controller.rb @@ -140,6 +140,16 @@ def generate_page_cache redirect_to :controller=>self.controller_name, :action=>'index' end + def export + send_data(page_to_hash(ComatosePage.root).to_yaml, :disposition => 'inline', :type => 'text/yaml', :filename => "comatose-pages.yml") + end + + def import + data = YAML::load(params[:import_file]) + hash_to_page_tree(data, ComatosePage.root) + flash[:notice] = "Pages Imported Successfully" + redirect_to :controller=>self.controller_name, :action=>'index' + end protected @@ -345,5 +355,32 @@ def runtime_mode=(mode) end end + private + + def page_to_hash(page) + data = page.attributes.clone + # Pull out the specific, or unnecessary fields + %w(id parent_id updated_on author position version created_on full_path).each {|key| data.delete(key)} + if !page.children.empty? + data['children'] = [] + page.children.each do |child| + data['children'] << page_to_hash(child) + end + end + data + end + def hash_to_page_tree(hsh, page) + child_ary = hsh.delete 'children' + page.update_attributes(hsh) + page.save + child_ary.each do |child_hsh| + if child_pg = page.children.find_by_slug( child_hsh['slug'] ) + hash_to_page_tree( child_hsh, child_pg ) + else + hash_to_page_tree( child_hsh, page.children.create ) + end + end if child_ary + end + end diff --git a/views/comatose_admin/index.html.erb b/views/comatose_admin/index.html.erb index cc7563e..ca7440c 100644 --- a/views/comatose_admin/index.html.erb +++ b/views/comatose_admin/index.html.erb @@ -1,4 +1,11 @@
+ <% form_tag(url_for(:action => 'import'), :multipart => true, :style => 'display: none;', :id => 'import_form') do %> + <%= file_field_tag 'import_file' %> + <%= submit_tag 'Import' %> + <% end %> + + <%= link_to 'Import', '#', :id => 'import_link2', :onclick => "$('import_form').setStyle({display: 'inline'}); this.hide();" %> + <%= link_to 'Export', :controller=>controller.controller_name, :action=>'export' %> <%= link_to 'Clear Page Cache', :controller=>controller.controller_name, :action=>'expire_page_cache' %>