Class: Smeagol::Views::Page

Inherits:
Base
  • Object
show all
Defined in:
lib/smeagol/views/page.rb

Direct Known Subclasses

Post

Instance Attribute Summary

Attributes inherited from Base

#file, #version, #wiki

Instance Method Summary collapse

Methods inherited from Base

#base_path, #custom_layout, #custom_layout?, #default_layout, #filename, #initialize, #layout, #menu_html, #metadata, #name, #posts, #ribbon_html, #ribbon_url, #settings, #setup_template_path, #source_url, #standard_layout, #tagline, #tracking_id, #wiki_title

Constructor Details

This class inherits a constructor from Smeagol::Views::Base

Instance Method Details

#authorObject

The last author of this page.



31
32
33
# File 'lib/smeagol/views/page.rb', line 31

def author
  page.version.author.name
end

#commit_dateObject

The last edit date of this page.



41
42
43
# File 'lib/smeagol/views/page.rb', line 41

def commit_date
  page.version.authored_date.strftime(settings.date_format)
end

#contentObject

The HTML formatted content of the page.



20
21
22
# File 'lib/smeagol/views/page.rb', line 20

def content
  page.formatted_data
end

#dateObject

The last edit date of this page.



36
37
38
# File 'lib/smeagol/views/page.rb', line 36

def date
   || commit_date
end


117
118
119
# File 'lib/smeagol/views/page.rb', line 117

def footer_content
  has_footer && @footer.formatted_data
end


121
122
123
# File 'lib/smeagol/views/page.rb', line 121

def footer_format
  has_footer && @footer.format.to_s
end


112
113
114
115
# File 'lib/smeagol/views/page.rb', line 112

def has_footer
  @footer = (@page.footer || false) if @footer.nil?
  !!@footer
end

#has_headerObject



99
100
101
102
# File 'lib/smeagol/views/page.rb', line 99

def has_header
  @header = (@page.header || false) if @header.nil?
  !!@header
end

#has_sidebarObject



125
126
127
128
# File 'lib/smeagol/views/page.rb', line 125

def has_sidebar
  @sidebar = (@page.sidebar || false) if @sidebar.nil?
  !!@sidebar
end

#has_tocObject



138
139
140
# File 'lib/smeagol/views/page.rb', line 138

def has_toc
  !@toc_content.nil?
end

#header_contentObject



104
105
106
# File 'lib/smeagol/views/page.rb', line 104

def header_content
  has_header && @header.formatted_data
end

#header_formatObject



108
109
110
# File 'lib/smeagol/views/page.rb', line 108

def header_format
  has_header && @header.format.to_s
end

#hrefObject

static href, used when generating static site.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/smeagol/views/page.rb', line 51

def href
  dir  = ::File.dirname(page.path)
  name = slug(page.filename_stripped)
  ext  = ::File.extname(page.path)

  if dir != '.'
    ::File.join(dir, name, 'index.html')
  else
    if name == settings.index #|| 'Home'
      'index.html'
    else
      ::File.join(name, 'index.html')
    end
  end
end

#mathjaxObject



146
147
148
# File 'lib/smeagol/views/page.rb', line 146

def mathjax
  @mathjax
end

#not_home?Boolean

A flag stating that this is not the home page.

Returns:

  • (Boolean)


46
47
48
# File 'lib/smeagol/views/page.rb', line 46

def not_home?
  page.title != "Home"  # settings.index
end

#post?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/smeagol/views/page.rb', line 95

def post?
  /^(\d\d\d\d-\d\d-\d\d)/.match(filename)
end

#post_dateObject

If the name of the page begins with a date, then it is the “post date” and is taken to be a blog entry, rather then an ordinary static page.



88
89
90
91
92
# File 'lib/smeagol/views/page.rb', line 88

def 
  if md = /^(\d\d\d\d-\d\d-\d\d)/.match(filename)
    Time.parse(md[1]).strftime(settings.date_format)
  end
end


130
131
132
# File 'lib/smeagol/views/page.rb', line 130

def sidebar_content
  has_sidebar && @sidebar.formatted_data
end


134
135
136
# File 'lib/smeagol/views/page.rb', line 134

def sidebar_format
  has_sidebar && @sidebar.format.to_s
end

#slug(name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Support configurable slugs.

Apply slug rules to name.

Returns:

  • (String)

    Returns String Sluggified name.



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/smeagol/views/page.rb', line 72

def slug(name)
  if /^\d\d+\-/ =~ name
    dirs = [] 
    parts = name.split('-')
    while /^\d+$/ =~ parts.first
      dirs << parts.shift             
    end
    dirs << parts.join('-')
    dirs.join('/')
  else
    name
  end
end

#summaryObject



25
26
27
28
# File 'lib/smeagol/views/page.rb', line 25

def summary
  i = content.index('</p>')
  i ? content[0..i+3] : content  # any other way if no i, 5 line limit?
end

#titleObject Also known as: page_title

The title of the page.



12
13
14
# File 'lib/smeagol/views/page.rb', line 12

def title
  page.title
end

#toc_contentObject



142
143
144
# File 'lib/smeagol/views/page.rb', line 142

def toc_content
  @toc_content
end