class Precious::Views::Page
Constants
- DATE_FORMAT
- DEFAULT_AUTHOR
- VALID_COUNTER_STYLES
Attributes
header[R]
historical[R]
page[R]
preview[R]
version[R]
Public Instance Methods
allow_editing()
click to toggle source
# File lib/gollum/views/page.rb, line 93 def allow_editing @allow_editing end
allow_uploads()
click to toggle source
# File lib/gollum/views/page.rb, line 97 def allow_uploads @allow_uploads end
bar_side()
click to toggle source
# File lib/gollum/views/page.rb, line 135 def bar_side @bar_side.to_s end
body_side()
click to toggle source
# File lib/gollum/views/page.rb, line 139 def body_side @bar_side == :right ? "left" : "right" end
content()
click to toggle source
# File lib/gollum/views/page.rb, line 41 def content content_without_page_header(@content) end
date()
click to toggle source
# File lib/gollum/views/page.rb, line 57 def date date_full.strftime(DATE_FORMAT) end
date_format()
click to toggle source
# File lib/gollum/views/page.rb, line 65 def date_format DATE_FORMAT end
date_full()
click to toggle source
# File lib/gollum/views/page.rb, line 51 def date_full first = @version ? page.version : page.last_version return Time.now unless first first.authored_date end
datetime()
click to toggle source
# File lib/gollum/views/page.rb, line 61 def datetime date_full.utc.iso8601 end
editable()
click to toggle source
# File lib/gollum/views/page.rb, line 73 def editable @editable end
full_url_path()
click to toggle source
# File lib/gollum/views/page.rb, line 180 def full_url_path page_route(@page.escaped_url_path) end
has_header()
click to toggle source
# File lib/gollum/views/page.rb, line 101 def has_header if @header @header.formatted_data.strip.empty? ? false : true else @header = (@page.header || false) !!@header end end
has_toc()
click to toggle source
# File lib/gollum/views/page.rb, line 164 def has_toc !@toc_content.nil? end
header_content()
click to toggle source
# File lib/gollum/views/page.rb, line 110 def header_content has_header && @header.formatted_data end
header_enum?()
click to toggle source
# File lib/gollum/views/page.rb, line 203 def header_enum? !!metadata['header_enum'] end
header_enum_style()
click to toggle source
# File lib/gollum/views/page.rb, line 207 def header_enum_style if header_enum? VALID_COUNTER_STYLES.include?(metadata['header_enum']) ? metadata['header_enum'] : 'decimal' end end
header_format()
click to toggle source
# File lib/gollum/views/page.rb, line 114 def header_format has_header && @header.format.to_s end
history()
click to toggle source
# File lib/gollum/views/page.rb, line 81 def history true end
latest_changes()
click to toggle source
# File lib/gollum/views/page.rb, line 85 def latest_changes true end
left_bar()
click to toggle source
# File lib/gollum/views/page.rb, line 143 def left_bar @bar_side == :left end
metadata()
click to toggle source
Access to embedded metadata.
Returns Hash.
# File lib/gollum/views/page.rb, line 187 def metadata @page.metadata end
noindex()
click to toggle source
# File lib/gollum/views/page.rb, line 69 def noindex @version ? true : false end
overview()
click to toggle source
# File lib/gollum/views/page.rb, line 89 def overview true end
page_header()
click to toggle source
# File lib/gollum/views/page.rb, line 24 def page_header title end
rendered_metadata()
click to toggle source
Access to embedded metadata.
Examples
{{#rendered_metadata}}{{name}}{{/rendered_metadata}}
Returns HTML table.
# File lib/gollum/views/page.rb, line 198 def rendered_metadata return '' unless page.display_metadata? && !metadata.empty? @rendered_metadata ||= table(metadata) end
search()
click to toggle source
# File lib/gollum/views/page.rb, line 77 def search true end
title()
click to toggle source
# File lib/gollum/views/page.rb, line 19 def title h1 = @h1_title ? page_header_from_content(@content) : false h1 || @page.url_path_title # url_path_title is the metadata title if present, otherwise the filename-based title end
toc_content()
click to toggle source
# File lib/gollum/views/page.rb, line 168 def toc_content @toc_content end
use_identicon()
click to toggle source
# File lib/gollum/views/page.rb, line 172 def use_identicon @page.wiki.user_icons == 'identicon' end
Private Instance Methods
build_document(content)
click to toggle source
Wraps page formatted data to Nokogiri::HTML document.
# File lib/gollum/views/page.rb, line 217 def build_document(content) Nokogiri::HTML::fragment(%{<div id="gollum-root">} + content.to_s + %{</div>}, 'UTF-8') end
content_without_page_header(content)
click to toggle source
Returns page content without title if it was extracted.
# File lib/gollum/views/page.rb, line 247 def content_without_page_header(content) doc = build_document(content) if @h1_title title = find_header_node(doc) title.remove unless title.empty? end # .inner_html will cause href escaping on UTF-8 doc.css("div#gollum-root").children.to_xml(Gollum::Markup.to_xml_opts) end
find_header_node(doc)
click to toggle source
Finds header node inside Nokogiri::HTML document.
# File lib/gollum/views/page.rb, line 223 def find_header_node(doc) case @page.format when :asciidoc doc.css("div#gollum-root > h1:first-child") when :pod doc.css("div#gollum-root > a.dummyTopAnchor:first-child + h1") when :rst doc.css("div#gollum-root > div > div > h1:first-child") else doc.css("div#gollum-root > h1:first-child") end end
page_header_from_content(content)
click to toggle source
Extracts title from page if present.
# File lib/gollum/views/page.rb, line 238 def page_header_from_content(content) doc = build_document(content) title = find_header_node(doc).inner_text.strip title = nil if title.empty? title end
table(data)
click to toggle source
# File lib/gollum/views/page.rb, line 257 def table(data) return data.to_s if data.empty? result = "<table>\n" keys = data.respond_to?(:keys) && data.respond_to?(:values) ? data.keys : nil if keys data = data.values result << "<tr>\n" keys.each do |heading| result << "<th>#{CGI.escapeHTML(heading.to_s)}</th>\n" end result << "</tr>\n" end result << "<tr>\n" data.each do |value| result << "<td>" << (value.respond_to?(:each) ? table(value) : CGI.escapeHTML(value.to_s)) << "</td>\n" end result << "</tr>\n</table>\n" end