summaryrefslogtreecommitdiff
path: root/app/models/node.rb
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-03-02 21:23:20 +0100
committerhukl <contact@smyck.org>2009-03-02 21:23:20 +0100
commit0566800f0f22829fcdb14c383a0388b4f1ca60f0 (patch)
tree72f32fc5c3b8e0f4da1b06feca24bfad4c3cbb2e /app/models/node.rb
parentfecf81e546b174ee5a8fb939b234aae2a1cb91b0 (diff)
refactoring of the page cloning and draft creating
Diffstat (limited to 'app/models/node.rb')
-rw-r--r--app/models/node.rb31
1 files changed, 4 insertions, 27 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 2e711cf..7f2bca6 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -59,35 +59,12 @@ class Node < ActiveRecord::Base
59 def create_new_draft user 59 def create_new_draft user
60 empty_page = self.pages.new 60 empty_page = self.pages.new
61 empty_page.user = user 61 empty_page.user = user
62 empty_page.save!
63 62
64 self.draft = empty_page 63 empty_page.clone_attributes_from self.head
65
66 if self.head
67 clone_attributes_to draft
68 end
69 64
65 self.draft = empty_page
70 self.save 66 self.save
71 draft 67 self.draft.reload
72 end
73
74 def clone_attributes_to page
75 page.tag_list = self.head.tag_list.join(", ")
76
77 locale_before = I18n.locale
78
79 I18n.available_locales.each do |l|
80 next if l == :root
81 I18n.locale = l
82 page.title = self.head.title
83 page.abstract = self.head.abstract
84 page.body = self.head.body
85 end
86
87 I18n.locale = locale_before
88
89 page.save
90 page
91 end 68 end
92 69
93 def publish_draft! 70 def publish_draft!
@@ -113,7 +90,7 @@ class Node < ActiveRecord::Base
113 parent.nil? && [slug] || parent.path_to_root.push(slug) 90 parent.nil? && [slug] || parent.path_to_root.push(slug)
114 end 91 end
115 92
116 def update_unique_name 93 def update_unique_name
117 path = self.path_to_root[1..-1] 94 path = self.path_to_root[1..-1]
118 self.unique_name = path.join("/") 95 self.unique_name = path.join("/")
119 self.save 96 self.save