Move toc calling code out of app; put in Page.toc_data
Page stores the formatted document parsed by Nokogiri
This commit is contained in:
@@ -112,17 +112,8 @@ module Precious
|
|||||||
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||||
@name = "Preview"
|
@name = "Preview"
|
||||||
@page = wiki.preview_page(@name, params[:content], params[:format])
|
@page = wiki.preview_page(@name, params[:content], params[:format])
|
||||||
@content = @page.formatted_data do
|
@content = @page.formatted_data
|
||||||
|doc|
|
@toc_content = @page.toc_data
|
||||||
# Insert anchors for table of contents
|
|
||||||
toc = Gollum::Toc.new doc
|
|
||||||
if (toc_content = toc.generate)
|
|
||||||
toc.insert_anchors
|
|
||||||
@toc_content = toc_content.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML)
|
|
||||||
else
|
|
||||||
@toc_content = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@editable = false
|
@editable = false
|
||||||
mustache :page
|
mustache :page
|
||||||
end
|
end
|
||||||
@@ -207,17 +198,9 @@ module Precious
|
|||||||
@page = page
|
@page = page
|
||||||
@name = name
|
@name = name
|
||||||
@editable = true
|
@editable = true
|
||||||
@content = page.formatted_data do
|
@content = page.formatted_data
|
||||||
|doc|
|
@toc_content = page.toc_data
|
||||||
# Insert anchors for table of contents
|
|
||||||
toc = Gollum::Toc.new doc
|
|
||||||
if (toc_content = toc.generate)
|
|
||||||
toc.insert_anchors
|
|
||||||
@toc_content = toc_content.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML)
|
|
||||||
else
|
|
||||||
@toc_content = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
mustache :page
|
mustache :page
|
||||||
elsif file = wiki.file(name)
|
elsif file = wiki.file(name)
|
||||||
content_type file.mime_type
|
content_type file.mime_type
|
||||||
|
|||||||
+18
-1
@@ -164,7 +164,24 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the String data.
|
# Returns the String data.
|
||||||
def formatted_data(encoding = nil, &block)
|
def formatted_data(encoding = nil, &block)
|
||||||
@blob && markup_class.render(historical?, encoding, &block)
|
@blob && markup_class.render(historical?, encoding) do |doc|
|
||||||
|
@doc = doc
|
||||||
|
yield doc if block_given?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: The table of contents of the page.
|
||||||
|
#
|
||||||
|
# formatted_data - page already marked up in html.
|
||||||
|
#
|
||||||
|
# Returns the String data.
|
||||||
|
def toc_data()
|
||||||
|
formatted_data if @doc == nil
|
||||||
|
toc = Toc.new(@doc)
|
||||||
|
if (toc_content = toc.generate)
|
||||||
|
toc.insert_anchors
|
||||||
|
toc.generate.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: The format of the page.
|
# Public: The format of the page.
|
||||||
|
|||||||
Reference in New Issue
Block a user