Class: Gollum::SitePage

Inherits:
Page
  • Object
show all
Defined in:
lib/gollum-site/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cname(name) ⇒ Object

Add “.html” extension to page links



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/gollum-site/page.rb', line 4

def self.cname(name)
  cname = name.respond_to?(:gsub)      ?
  name.gsub(%r{[ /<>]}, '-') :
    ''

  # account for anchor links (e.g. Page#anchor)
  if pos = cname.index('#')
    cname[0..(pos-1)] + '.html' + cname[pos..-1]
  else
    cname + '.html'
  end
end

Instance Method Details

#find(cname, version, dir = nil, exact = false) ⇒ Object

Markup uses this method for absent/present class assignment on page links



18
19
20
21
# File 'lib/gollum-site/page.rb', line 18

def find(cname, version, dir = nil, exact = false)
  name = self.class.canonicalize_filename(cname)
  @wiki.site.pages[name.downcase]
end

#formatted_data(&block) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/gollum-site/page.rb', line 89

def formatted_data(&block)
  if @formatted_data.nil?
    SiteLog.debug("Starting page formatting - #{name}")
    @formatted_data = super(&block)
    SiteLog.debug("Finished page formatting - #{name}")
  end
  return @formatted_data
end

#generate(output_path, version) ⇒ Object

Output static HTML of current page



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gollum-site/page.rb', line 42

def generate(output_path, version)
  data = if l = layout()
           SiteLog.debug("Found layout - #{name}")
           SiteLog.debug("Starting page rendering - #{name}")
           rendered = l.render( 'page' => self,
                     'site' => @wiki.site,
                     'wiki' => {'base_path' => @wiki.base_path})
           SiteLog.debug("Finished page rendering - #{name}")
           rendered
         else
           SiteLog.debug("Did not find layout - #{name}")
           formatted_data
         end

  ::File.open(::File.join(output_path, self.class.cname(name)), 'w') do |f|
    f.write(data)
  end
end

#layoutObject

Return layout or nil



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gollum-site/page.rb', line 24

def layout()
  name = '_Layout.html'
  dirs = self.path.split('/')
  dirs.pop
  while !dirs.empty?
    path = dirs.join('/') + '/' + name
    if l = @wiki.site.layouts[path]
      return l
    end
    dirs.pop
  end

  if l = @wiki.site.layouts[name]
    return l
  end
end

#liquifyObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gollum-site/page.rb', line 66

def liquify
  SiteLog.debug("Starting page liquefication - #{name}")
  data = {
    "path" => self.class.cname(name),
    "link" => ::File.join(@wiki.base_path, CGI.escape(self.class.cname(name))),
    "content" => formatted_data,
    "title" => title,
    "format" => format.to_s
  }
  data["author"] = version.author.name rescue nil
  data["date"] = version.authored_date.strftime("%Y-%m-%d %H:%M:%S") rescue nil
  data["footer"] = footer.formatted_data if footer
  data["sidebar"] = sidebar.formatted_data if sidebar
  SiteLog.debug("Finished page liquefication - #{name}")
  return data
end

#populate(blob, path) ⇒ Object



83
84
85
86
87
# File 'lib/gollum-site/page.rb', line 83

def populate(blob, path)
  @blob = blob
  @path = (path + '/' + blob.name)
  self
end

#to_liquidObject

Return data for Liquid template



62
63
64
# File 'lib/gollum-site/page.rb', line 62

def to_liquid
  @to_liquid ||= liquify
end