Refactoring page creation code [dm1]

This commit is contained in:
Alexey Verkhovsky 2005-05-12 01:07:24 +00:00
parent f6a3b88693
commit 9abb4f575a
5 changed files with 29 additions and 34 deletions

View file

@ -10,11 +10,10 @@ class Page
attr_reader :name, :web
attr_accessor :revisions
def initialize(web, name, content, created_at, author)
def initialize(web, name)
raise 'nil web' if web.nil?
raise 'nil name' if name.nil?
@web, @name, @revisions = web, name, []
revise(content, created_at, author)
end
def revise(content, created_at, author)
@ -43,6 +42,9 @@ class Page
self.revisions.last.clear_display_cache
@web.refresh_pages_with_references(@name) if @revisions.length == 1
self
end
def rollback(revision_number, created_at, author_ip = nil)

View file

@ -44,10 +44,12 @@ class Web
def max_upload_size() @max_upload_size || 100; end
def wiki() @wiki ||= WikiService.instance; end
def add_page(page)
@pages[page.name] = page
end
def add_page(name, content, created_at, author)
page = Page.new(self, name)
@pages[page.name] = page
page.revise(content, created_at, author)
end
def address=(the_address)
if the_address != CGI.escape(the_address)
raise Instiki::ValidationError.new('Web name should contain only valid URI characters')

View file

@ -58,13 +58,11 @@ module AbstractWikiService
def revise_page(web_address, page_name, content, revised_on, author)
page = read_page(web_address, page_name)
page.revise(content, revised_on, author)
page
end
def rollback_page(web_address, page_name, revision_number, created_at, author_id = nil)
page = read_page(web_address, page_name)
page.rollback(revision_number, created_at, author_id)
page
end
def setup(password, web_name, web_address)
@ -105,9 +103,7 @@ module AbstractWikiService
end
def write_page(web_address, page_name, content, written_on, author)
page = Page.new(@webs[web_address], page_name, content, written_on, author)
@webs[web_address].add_page(page)
page
@webs[web_address].add_page(page_name, content, written_on, author)
end
def storage_path