The Rails Way
The previous implementation, in Revision 541, was ugly. This is better.
This commit is contained in:
parent
5506f87f17
commit
954bcb52c2
|
@ -72,6 +72,10 @@ class Page < ActiveRecord::Base
|
|||
wiki_references.select { |ref| ref.wiki_word? }.map { |ref| ref.referenced_name }
|
||||
end
|
||||
|
||||
def categories
|
||||
wiki_references.select { |ref| ref.category? }.map { |ref| ref.referenced_name }
|
||||
end
|
||||
|
||||
def linked_from
|
||||
web.select.pages_that_link_to(name)
|
||||
end
|
||||
|
|
|
@ -81,16 +81,6 @@ class WikiReference < ActiveRecord::Base
|
|||
row['name'].as_utf8 if row
|
||||
end
|
||||
|
||||
def self.page_categories(web, page_name)
|
||||
query =
|
||||
"SELECT referenced_name FROM wiki_references JOIN pages " +
|
||||
"ON wiki_references.page_id = pages.id " +
|
||||
"WHERE pages.name = ? " +
|
||||
"AND wiki_references.link_type = '#{CATEGORY}' " +
|
||||
"AND pages.web_id = '#{web.id}'"
|
||||
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['referenced_name'].as_utf8 }
|
||||
end
|
||||
|
||||
def self.pages_in_category(web, category)
|
||||
query =
|
||||
"SELECT name FROM pages JOIN wiki_references " +
|
||||
|
@ -142,4 +132,8 @@ class WikiReference < ActiveRecord::Base
|
|||
link_type == WANTED_FILE
|
||||
end
|
||||
|
||||
def category?
|
||||
link_type == CATEGORY
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -69,8 +69,7 @@ function cleanAuthorName() {
|
|||
}
|
||||
|
||||
document.forms["editForm"].elements["content"].focus();
|
||||
<%- if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) and
|
||||
!WikiReference.page_categories(@web, @page.name).include?('S5-slideshow') -%>
|
||||
<%- if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) and !@page.categories.include?('S5-slideshow') -%>
|
||||
addS5button('<%= CGI.escapeHTML(@page.name) %>');
|
||||
<%- end -%>
|
||||
//--><!]]>
|
||||
|
|
Loading…
Reference in a new issue