White space police
This commit is contained in:
parent
e3752a04dc
commit
ed8e9cfbd8
|
@ -1,22 +1,22 @@
|
||||||
class Web < ActiveRecord::Base
|
class Web < ActiveRecord::Base
|
||||||
has_many :pages, :dependent => :destroy
|
has_many :pages, :dependent => :destroy
|
||||||
has_many :wiki_files, :dependent => :destroy
|
has_many :wiki_files, :dependent => :destroy
|
||||||
|
|
||||||
def wiki
|
def wiki
|
||||||
Wiki.new
|
Wiki.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def settings_changed?(markup, safe_mode, brackets_only)
|
def settings_changed?(markup, safe_mode, brackets_only)
|
||||||
self.markup != markup ||
|
self.markup != markup ||
|
||||||
self.safe_mode != safe_mode ||
|
self.safe_mode != safe_mode ||
|
||||||
self.brackets_only != brackets_only
|
self.brackets_only != brackets_only
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_page(name, content, time, author, renderer)
|
def add_page(name, content, time, author, renderer)
|
||||||
page = page(name) || Page.new(:web => self, :name => name)
|
page = page(name) || Page.new(:web => self, :name => name)
|
||||||
page.revise(content, name, time, author, renderer)
|
page.revise(content, name, time, author, renderer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authors
|
def authors
|
||||||
connection.select_all(
|
connection.select_all(
|
||||||
'SELECT DISTINCT r.author AS author ' +
|
'SELECT DISTINCT r.author AS author ' +
|
||||||
|
@ -24,7 +24,7 @@ class Web < ActiveRecord::Base
|
||||||
'JOIN pages p ON p.id = r.page_id ' +
|
'JOIN pages p ON p.id = r.page_id ' +
|
||||||
'WHERE p.web_id = ' + self.id.to_s +
|
'WHERE p.web_id = ' + self.id.to_s +
|
||||||
' ORDER by 1 '
|
' ORDER by 1 '
|
||||||
).collect { |row| row['author'] }
|
).collect { |row| row['author'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def categories
|
def categories
|
||||||
|
@ -34,7 +34,7 @@ class Web < ActiveRecord::Base
|
||||||
def page(name)
|
def page(name)
|
||||||
pages.first(:conditions => ['name = ?', name])
|
pages.first(:conditions => ['name = ?', name])
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_page
|
def last_page
|
||||||
return Page.first(:order => 'id desc', :conditions => ['web_id = ?', self.id])
|
return Page.first(:order => 'id desc', :conditions => ['web_id = ?', self.id])
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,7 @@ class Web < ActiveRecord::Base
|
||||||
def has_page?(name)
|
def has_page?(name)
|
||||||
Page.count(:conditions => ['web_id = ? AND name = ?', id, name]) > 0
|
Page.count(:conditions => ['web_id = ? AND name = ?', id, name]) > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_redirect_for?(name)
|
def has_redirect_for?(name)
|
||||||
WikiReference.page_that_redirects_for(self, name)
|
WikiReference.page_that_redirects_for(self, name)
|
||||||
end
|
end
|
||||||
|
@ -54,7 +54,7 @@ class Web < ActiveRecord::Base
|
||||||
def has_file?(file_name)
|
def has_file?(file_name)
|
||||||
WikiFile.find_by_file_name(file_name) != nil
|
WikiFile.find_by_file_name(file_name) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_list(sort_order = 'file_name')
|
def file_list(sort_order = 'file_name')
|
||||||
WikiFile.all(:order => sort_order, :conditions => ['web_id = ?', id])
|
WikiFile.all(:order => sort_order, :conditions => ['web_id = ?', id])
|
||||||
end
|
end
|
||||||
|
@ -82,8 +82,7 @@ class Web < ActiveRecord::Base
|
||||||
'FROM revisions r ' +
|
'FROM revisions r ' +
|
||||||
'JOIN pages p ON r.page_id = p.id ' +
|
'JOIN pages p ON r.page_id = p.id ' +
|
||||||
"WHERE p.web_id = #{self.id} " +
|
"WHERE p.web_id = #{self.id} " +
|
||||||
'ORDER by p.name'
|
'ORDER by p.name').inject({}) { |result, row|
|
||||||
).inject({}) { |result, row|
|
|
||||||
author, page_name = row['author'], row['page_name']
|
author, page_name = row['author'], row['page_name']
|
||||||
result[author] = [] unless result.has_key?(author)
|
result[author] = [] unless result.has_key?(author)
|
||||||
result[author] << page_name
|
result[author] << page_name
|
||||||
|
@ -94,23 +93,23 @@ class Web < ActiveRecord::Base
|
||||||
def remove_pages(pages_to_be_removed)
|
def remove_pages(pages_to_be_removed)
|
||||||
pages_to_be_removed.each { |p| p.destroy }
|
pages_to_be_removed.each { |p| p.destroy }
|
||||||
end
|
end
|
||||||
|
|
||||||
def revised_at
|
def revised_at
|
||||||
select.most_recent_revision
|
select.most_recent_revision
|
||||||
end
|
end
|
||||||
|
|
||||||
def select(&condition)
|
def select(&condition)
|
||||||
PageSet.new(self, pages, condition)
|
PageSet.new(self, pages, condition)
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_all
|
def select_all
|
||||||
PageSet.new(self, pages, nil)
|
PageSet.new(self, pages, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
address
|
address
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_files_directory
|
def create_files_directory
|
||||||
return unless allow_uploads == 1
|
return unless allow_uploads == 1
|
||||||
dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0')
|
dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0')
|
||||||
|
@ -148,30 +147,30 @@ class Web < ActiveRecord::Base
|
||||||
def wiki_words
|
def wiki_words
|
||||||
pages.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq
|
pages.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of all the page names on this web
|
# Returns an array of all the page names on this web
|
||||||
def page_names
|
def page_names
|
||||||
pages.map { |p| p.name }
|
pages.map { |p| p.name }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
before_save :sanitize_markup
|
before_save :sanitize_markup
|
||||||
after_save :create_files_directory
|
after_save :create_files_directory
|
||||||
before_validation :validate_address
|
before_validation :validate_address
|
||||||
validates_uniqueness_of :address
|
validates_uniqueness_of :address
|
||||||
validates_length_of :color, :in => 3..6
|
validates_length_of :color, :in => 3..6
|
||||||
|
|
||||||
def sanitize_markup
|
def sanitize_markup
|
||||||
self.markup = markup.to_s
|
self.markup = markup.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_address
|
def validate_address
|
||||||
unless address == CGI.escape(address)
|
unless address == CGI.escape(address)
|
||||||
self.errors.add(:address, 'should contain only valid URI characters')
|
self.errors.add(:address, 'should contain only valid URI characters')
|
||||||
raise Instiki::ValidationError.new("#{self.class.human_attribute_name('address')} #{errors.on(:address)}")
|
raise Instiki::ValidationError.new("#{self.class.human_attribute_name('address')} #{errors.on(:address)}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_web?
|
def default_web?
|
||||||
defined? DEFAULT_WEB and self.address == DEFAULT_WEB
|
defined? DEFAULT_WEB and self.address == DEFAULT_WEB
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue