class Smeagol::Settings

Wiki settings.

TODO: Would it be possible/prudent to move all this into controller?

Constants

FILE

The name of the settings file. TODO: Rename to `_smeagol.yml` ?

PARTIALS

Default template includes directory.

SITE_PATH

Default site stage directory.

SYNC_SCRIPT

Default sync command.

Attributes

author[RW]

Primary author/maintainer of site.

date_format[RW]

TODO: I hate this. Make's me want to switch to Liquid templates.

Hurry up with Mustache 2.0 already!
description[RW]

Detailed description of site.

exclude[RW]

Files to exclude that would otherwise be included.

future[RW]

Include posts with future dates? By default all posts dated in the future are omitted.

include[RW]

Files to include that would not otherwise be included. A good example is `.htaccess` becuase dot files are excluded by default.

index[RW]

Page to use as site index. The default is `Home`. A non-wiki page can be used as well, such as `index.html` (well, duh!).

mathjax[RW]

Support the use of mathjax? Default is `true`.

menu[RW]

Menu that can be used in site template.

Note this will probably be deprecated as it is easy enough to add a menu to your site's custom page template.

Examples

menu:
- title: Blog
  href: /
- title: Projects
  href: /Projects/
- title: Tools
  href: /Tools/
- title: Reads
  href: /Reads/
partials[RW]

Where to find template partials. This is the location that Mustache uses when looking for partials. The default is `_partials`.

ribbon[RW]

Include a GitHub “Fork Me” ribbon in corner of page. Entry should give color and position separated by a space. The resulting ribbon will have a link to `source_url`.

TODO: Rename this `github_forkme` or something like that.

Examples

ribbon: red right

Note this might be deprecated as one can add it by hand to custom page template.

rss[RW]

Boolean flag to produce an rss.xml feed file for blog posts.

site_branch[RW]

Special branch if using silly branch style, e.g. `gh-pages`.

site_origin[RW]

If deployment of a site is done via git, then `site_origin` can be used to setup a Repository instance that can handle pulls and pushes automatically.

Examples

site_origin: git@github.com:trans/trans.github.com.git
site_stage[RW]

Set `site_stage` if the site needs to be staged for deployment. In other words, if the servable files in the wiki need to be copied into a separate directory. This can be set to `true` in which case the default `_site` path will be used, otherwise set it to the path desired.

Non-absolute paths are relative to the wiki's location. Be sure to add this to the wiki's .gitignore file, if it is, and if not prefixed by and underscore, be sure to add it to `exclude` setting as well.

site_sync[RW]

Smeagol uses `rsync` to copy files from the repository to the staging location if given by `site_path`. By default this command is:

"rsync -arv --del --exclude .git* %s/ %s/"

Where the first %s is the repository location and the second is the location specified by the `site_path` setting. If this needs to be different it can be change here. Just be sure to honor the `%s` slots.

If set to `~` (ie. `nil`) then the files will be copied directly to the site_path directory without using rsync.

source_url[RW]

Project's development site, if applicable. e.g. `github.com/trans`

TODO: Rename this field.

tagline[RW]

Single line description of site.

title[RW]

Title of site.

tracking_id[RW]

Google analytics tracking id. Could be used for other such services if custom template is used.

Note this will probably be deprecates because you can add the code snippet easily enough to your custom page template.

url[RW]

Site's URL. If someone wanted to visit your website, this is the link they would follow, e.g. `trans.github.com`

wiki_dir[RW]

Internal: Do not set this in _settings.yml!

wiki_origin[RW]

Gollum wiki's repo uri. e.g. `git@github.com:trans/trans.github.com.wiki.git`

wiki_ref[RW]

The particular tag or reference id to serve. Default is 'master'.

Public Class Methods

load(wiki_dir=nil) click to toggle source

Load settings.

wiki_dir - Local file system location of wiki repo. [String]

Returns settings instance. [Settings]

# File lib/smeagol/settings.rb, line 28
def self.load(wiki_dir=nil)
  wiki_dir = Dir.pwd unless wiki_dir
  file = File.join(wiki_dir, FILE)
  file = File.expand_path(file)
  if File.exist?(file)
    settings = YAML.load_file(file)
  else
    settings = {}
  end

  settings[:wiki_dir] = wiki_dir

  new(settings)
end
new(settings={}) click to toggle source

Initialize Settings.

settings - Settings hash. [Hash]

# File lib/smeagol/settings.rb, line 48
def initialize(settings={})
  @partials      = PARTIALS
  @index         = 'Home'
  @rss           = true
  @exclude       = []
  @include       = []
  @site          = nil
  @date_format   = "%B %d, %Y"
  @site_stage    = nil
  @site_sync     = SYNC_SCRIPT
  #@static        = false
  @mathjax       = true
  @future        = false

  # TODO: Raise error if no wiki_dir ?
  @wiki_dir = settings[:wiki_dir]

  assign(settings)
end

Public Instance Methods

[](key) click to toggle source

Deprecated: Access settings like a Hash.

# File lib/smeagol/settings.rb, line 69
def [](key)
  __send__(key)
end
assign(settings={}) click to toggle source

Assign settings hash via writer methods.

Returns nothing.

# File lib/smeagol/settings.rb, line 76
def assign(settings={})
  settings.each do |k,v|
    __send__("#{k}=", v) if respond_to?("#{k}=")
  end
end
Also aliased as: update
full_site_path()

Deprecated: Original name for site_path.

Alias for: site_path
site() click to toggle source
# File lib/smeagol/settings.rb, line 119
def site
  {'stage'=>site_stage, 'origin'=>site_origin, 'branch'=>site_branch}
end
site=(entry) click to toggle source

If deployment of a site is done via git or via a staging directory, then `site` can be used to set these.

Examples

site:
  origin: git@github.com:trans/trans.github.com.git
  branch: gh-pages
  path: _site
# File lib/smeagol/settings.rb, line 133
def site=(entry)
  case entry
  when Hash
    self.site_origin = site['origin']
    self.site_branch = site['branch']
    self.site_stage  = site['stage']
    self.site_sync   = site['sync'] if site['sync']
  else
    raise ArgumentError, 'site must be a mapping'
    # TODO: maybe make this smarter in future to guess if single entry is origin or stage.
    #self.site_stage = entry
  end
end
site_path() click to toggle source

Expanded site directory.

If `site_path` is an absolute path it will returned as given, otherwise this will be relative to the location of the wiki.

Returns String of site path.

# File lib/smeagol/settings.rb, line 281
def site_path
  site_path = (TrueClass === site_stage ? SITE_PATH : site_stage || SITE_PATH)

  path = relative?(site_path) ? ::File.join(wiki_dir, site_path) : site_path
  path.chomp('/')  # ensure no trailing path separator
  path
end
Also aliased as: full_site_path
site_repo() click to toggle source

Returns Repository object for git-based deployment site.

# File lib/smeagol/settings.rb, line 295
def site_repo
  @site_repo ||= (
    opts = (site || {}).dup
    opts[:path] = site_path
    Repository.new(opts)
  )
end
update(settings={})

Deprecated: Alias for assign.

Alias for: assign
wiki() click to toggle source
# File lib/smeagol/settings.rb, line 103
def wiki
  {'origin'=>wiki_origin, 'ref'=>wiki_ref}
end
wiki=(entry) click to toggle source
# File lib/smeagol/settings.rb, line 108
def wiki=(entry)
  case entry
  when Hash
    self.wiki_origin = site['origin']
    self.wiki_ref    = site['ref']
  else
    raise ArgumentError, 'wiki must be a mapping'
  end
end

Private Instance Methods

relative?(path) click to toggle source
# File lib/smeagol/settings.rb, line 308
def relative?(path)
  return false if path =~ /^[A-Z]\:/
  return false if path.start_with?(::File::SEPARATOR)
  return false if path.start_with?('/')
  #return false if path.start_with?('.')
  return true
end