Class: Smeagol::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/smeagol/settings.rb

Overview

TODO:

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

Wiki settings.

Constant Summary collapse

FILE =
TODO:

Rename to ‘_smeagol.yml` ?

The name of the settings file.

"_settings.yml"
PARTIALS =

Default template includes directory.

'_partials'
SITE_PATH =

Default site stage directory.

'_site'
SYNC_SCRIPT =

Default sync command.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Settings

Initialize Settings.

Parameters:

  • settings (defaults to: {})

    Settings hash. [Hash]



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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

Instance Attribute Details

#authorObject

Primary author/maintainer of site.



227
228
229
# File 'lib/smeagol/settings.rb', line 227

def author
  @author
end

#date_formatObject

TODO: I hate this. Make’s me want to switch to Liquid templates. Hurry up with Mustache 2.0 already!



215
216
217
# File 'lib/smeagol/settings.rb', line 215

def date_format
  @date_format
end

#descriptionObject

Detailed description of site.



224
225
226
# File 'lib/smeagol/settings.rb', line 224

def description
  @description
end

#excludeObject

Files to exclude that would otherwise be included.



201
202
203
# File 'lib/smeagol/settings.rb', line 201

def exclude
  @exclude
end

#futureObject

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



205
206
207
# File 'lib/smeagol/settings.rb', line 205

def future
  @future
end

#includeObject

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



198
199
200
# File 'lib/smeagol/settings.rb', line 198

def include
  @include
end

#indexObject

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!).



191
192
193
# File 'lib/smeagol/settings.rb', line 191

def index
  @index
end

#mathjaxObject

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



208
209
210
# File 'lib/smeagol/settings.rb', line 208

def mathjax
  @mathjax
end

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/


246
247
248
# File 'lib/smeagol/settings.rb', line 246

def menu
  @menu
end

#partialsObject

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



187
188
189
# File 'lib/smeagol/settings.rb', line 187

def partials
  @partials
end

#ribbonObject

TODO:

Rename this ‘github_forkme` or something like that.

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

Examples:

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


267
268
269
# File 'lib/smeagol/settings.rb', line 267

def ribbon
  @ribbon
end

#rssObject

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



194
195
196
# File 'lib/smeagol/settings.rb', line 194

def rss
  @rss
end

#site_branchObject

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



157
158
159
# File 'lib/smeagol/settings.rb', line 157

def site_branch
  @site_branch
end

#site_originObject

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: [email protected]:trans/trans.github.com.git


154
155
156
# File 'lib/smeagol/settings.rb', line 154

def site_origin
  @site_origin
end

#site_stageObject

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.



169
170
171
# File 'lib/smeagol/settings.rb', line 169

def site_stage
  @site_stage
end

#site_syncObject

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.



183
184
185
# File 'lib/smeagol/settings.rb', line 183

def site_sync
  @site_sync
end

#source_urlObject

TODO:

Rename this field.

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



273
274
275
# File 'lib/smeagol/settings.rb', line 273

def source_url
  @source_url
end

#taglineObject

Single line description of site.



221
222
223
# File 'lib/smeagol/settings.rb', line 221

def tagline
  @tagline
end

#titleObject

Title of site.



218
219
220
# File 'lib/smeagol/settings.rb', line 218

def title
  @title
end

#tracking_idObject

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.



253
254
255
# File 'lib/smeagol/settings.rb', line 253

def tracking_id
  @tracking_id
end

#urlObject

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



97
98
99
# File 'lib/smeagol/settings.rb', line 97

def url
  @url
end

#wiki_dirObject

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.

Do not set this in _settings.yml!



86
87
88
# File 'lib/smeagol/settings.rb', line 86

def wiki_dir
  @wiki_dir
end

#wiki_originObject

Gollum wiki’s repo uri. e.g. ‘[email protected]:trans/trans.github.com.wiki.git`



90
91
92
# File 'lib/smeagol/settings.rb', line 90

def wiki_origin
  @wiki_origin
end

#wiki_refObject

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



93
94
95
# File 'lib/smeagol/settings.rb', line 93

def wiki_ref
  @wiki_ref
end

Class Method Details

.load(wiki_dir = nil) ⇒ Settings

Load settings.

Parameters:

  • wiki_dir (defaults to: nil)

    Local file system location of wiki repo. [String]

Returns:

  • (Settings)

    Returns settings instance.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

Instance Method Details

#[](key) ⇒ Object

Deprecated.

Do not use this in new code, and replace it when updating old code.

Access settings like a Hash.



69
70
71
# File 'lib/smeagol/settings.rb', line 69

def [](key)
  __send__(key)
end

#assign(settings = {}) ⇒ void Also known as: update

This method returns an undefined value.

Assign settings hash via writer methods.



76
77
78
79
80
# File 'lib/smeagol/settings.rb', line 76

def assign(settings={})
  settings.each do |k,v|
    __send__("#{k}=", v) if respond_to?("#{k}=")
  end
end

#relative?(path) ⇒ Boolean (private)

Returns:

  • (Boolean)


308
309
310
311
312
313
314
# 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

#siteObject



119
120
121
# File 'lib/smeagol/settings.rb', line 119

def site
  {'stage'=>site_stage, 'origin'=>site_origin, 'branch'=>site_branch}
end

#site=(entry) ⇒ Object

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: [email protected]:trans/trans.github.com.git
  branch: gh-pages
  path: _site


133
134
135
136
137
138
139
140
141
142
143
144
145
# 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_pathString Also known as: full_site_path

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.



281
282
283
284
285
286
287
# 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

#site_repoObject

Returns Repository object for git-based deployment site.



295
296
297
298
299
300
301
# File 'lib/smeagol/settings.rb', line 295

def site_repo
  @site_repo ||= (
    opts = (site || {}).dup
    opts[:path] = site_path
    Repository.new(opts)
  )
end

#wikiObject



103
104
105
# File 'lib/smeagol/settings.rb', line 103

def wiki
  {'origin'=>wiki_origin, 'ref'=>wiki_ref}
end

#wiki=(entry) ⇒ Object



108
109
110
111
112
113
114
115
116
# 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