| Class | Checkout |
| In: |
app/models/checkout.rb
|
| Parent: | ActiveRecord::Base |
| HTML_START_ELEMENT | = | /<html([^\<])*/ |
| html | [RW] | |
| note | [RW] | Note supplied with checkout will be used to create Version.note |
| source_version | [RW] | Version we are checking out |
# File app/models/checkout.rb, line 96
96: def before_validation_on_create
97: logger.info("Before validation on create of checkout for #{self.page.presentation_name}")
98: raise "Versions can only be created in Wiki sites" if !self.site.wiki?
99: raise "Cannot create a checkout, a checkout already exists" if self.page.checkout
100:
101: self.source_version = self.page.current_version if self.source_version.nil?
102:
103: logger.debug("Creating version for checkout")
104: self.version = UserVersion.new(:wiki => self.site, :page => self.page, :user => self.user, :source_version => self.source_version)
105: self.version.rel_path = "#{self.page.rel_path}_EPFWIKI_co.html"
106: File.makedirs(File.dirname(self.version.path))
107: self.version.note = self.note
108: # Method #prepare_for_edit is used to prepare the file for editing in
109: # the HTML editor that runs in the browser:
110: # 1. onload event is removed from the body element
111: # 2. Javascript lib treebrowser.js that chrashes the editor is replaced by a placeholder comment tag
112: # 3. the EPF iframe element is removed
113: # 4. the copyright_tag is replaced by a placeholder tag # DISABLED, didn't work after upgrade of EPF
114: # 5. head tag is removed, because this TinyMCE cannot (and should not) manage this (this was BUG 96 - Doubling meta-tags)
115: #
116: # See also #Page.before_create
117: #--
118: # TODO step 4 does not seem to work anymore with current version of OpenUP (EPF)
119: # TODO move to version as part of checkout
120: #++
121: h = self.html # TODO is this right? document this
122: h = self.source_version.html if h.blank?
123: h = h.gsub(Page::BODY_TAG_PATTERN, '<body>') # 1
124: h = h.gsub(Page::TREEBROWSER_PATTERN, Page::TREEBROWSER_PLACEHOLDER) # 2
125: #html = html.gsub(COPYRIGHT_PATTERN, COPYRIGHT_PLACEHOLDER) # 4
126: h = h.gsub(Page::HEAD_PATTERN, '') # 5
127: self.version.html = h
128: end
# File app/models/checkout.rb, line 47
47: def checkin(user, h = nil)
48: logger.info("Checkin of version #{self.version.path}")
49: raise 'Cannot checkin, checked is not owned by user' if user != self.user && !user.cadmin?
50: h = self.version.html if h.nil?
51:
52: # reset current attribute if set on a version
53: cv = self.page.current_version
54: if !cv.nil? && cv.current
55: cv.current = false
56: cv.save!
57: end
58: Notification.find_or_create(self.page, self.user, Page.name)
59: old_path = self.version.path
60: self.version.version = self.page.max_version_no + 1
61: self.version.rel_path = "#{self.page.rel_path}_EPFWIKI_v#{self.version.version}.html"
62: logger.info("Moving version file from #{old_path} to #{self.version.path}")
63: File.move(old_path, self.version.path)
64: self.version.save!
65:
66: # Correct head tag of version file
67: # TODO rename HEAD_PATTERN -> HEAD_REGEXP
68: unless h.index(Page::HEAD_PATTERN).nil?
69: logger.info("Head element found, replacing it with head element of original page")
70: h = h.gsub(Page::HEAD_PATTERN, self.page.head_tag)
71: else
72: unless h.index(HTML_START_ELEMENT).nil?
73: logger.info("HTML element found, adding a head element to it")
74: h = h.gsub(HTML_START_ELEMENT, HTML_START_ELEMENT.match(h)[0] + self.page.head_tag)
75: else
76: logger.info("No head or html element found, adding head element and letting tidy do the rest")
77: h = self.page.head_tag + h
78: end
79: end
80: logger.info("Removing EPF Wiki Javascript library includes")
81: h = h.gsub(Page::PAGE_HEAD_SNIPPET_PATTERN,'') if h.index(Page::PAGE_HEAD_SNIPPET_PATTERN)
82: self.version.html = h
83:
84: # copy version to page and enhance
85: self.page.html = self.version.html
86: Page.enhance_file(self.page.path)
87: h= self.page.html
88: h = h.gsub(Page::BODY_TAG_PATTERN, self.page.body_tag ) if self.page.body_tag
89: h = h.gsub(Page::TREEBROWSER_PLACEHOLDER, self.page.treebrowser_tag) if self.page.treebrowser_tag
90: h = h.gsub(Page::COPYRIGHT_PLACEHOLDER, self.page.copyright_tag) if self.page.copyright_tag
91: self.page.html = h
92: # TODO set title equal to pageTitle?
93: self.destroy
94: end
# File app/models/checkout.rb, line 40
40: def undo
41: logger.info("Undo of checkout #{self.id}")
42: self.version.destroy
43: self.page.destroy if self.page.versions.size == 0 # If no versions remain, this must be a new page, so we also remove the page
44: self.destroy
45: end