Class: Smeagol::Views::Post

Inherits:
Page
  • Object
show all
Defined in:
lib/smeagol/views/post.rb

Instance Attribute Summary

Attributes inherited from Base

#file, #version, #wiki

Instance Method Summary collapse

Methods inherited from Page

#author, #commit_date, #content, #date, #footer_content, #footer_format, #has_footer, #has_header, #has_sidebar, #has_toc, #header_content, #header_format, #mathjax, #not_home?, #post?, #post_date, #sidebar_content, #sidebar_format, #summary, #title, #toc_content

Methods inherited from Base

#base_path, #custom_layout, #custom_layout?, #default_layout, #filename, #initialize, #layout, #mathjax, #menu_html, #metadata, #name, #post?, #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

#hrefObject

static href, used when generating static site.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/smeagol/views/post.rb', line 12

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

#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.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/smeagol/views/post.rb', line 33

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