Class: Smeagol::Settings
- Inherits:
-
Object
- Object
- Smeagol::Settings
- Defined in:
- lib/smeagol/settings.rb
Overview
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
-
#author ⇒ Object
Primary author/maintainer of site.
-
#date_format ⇒ Object
TODO: I hate this.
-
#description ⇒ Object
Detailed description of site.
-
#exclude ⇒ Object
Files to exclude that would otherwise be included.
-
#future ⇒ Object
Include posts with future dates? By default all posts dated in the future are omitted.
-
#include ⇒ Object
Files to include that would not otherwise be included.
-
#index ⇒ Object
Page to use as site index.
-
#mathjax ⇒ Object
Support the use of mathjax? Default is ‘true`.
-
#menu ⇒ Object
Menu that can be used in site template.
-
#partials ⇒ Object
Where to find template partials.
-
#ribbon ⇒ Object
Include a GitHub “Fork Me” ribbon in corner of page.
-
#rss ⇒ Object
Boolean flag to produce an rss.xml feed file for blog posts.
-
#site_branch ⇒ Object
Special branch if using silly branch style, e.g.
-
#site_origin ⇒ Object
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.
-
#site_stage ⇒ Object
Set ‘site_stage` if the site needs to be staged for deployment.
-
#site_sync ⇒ Object
Smeagol uses ‘rsync` to copy files from the repository to the staging location if given by `site_path`.
-
#source_url ⇒ Object
Project’s development site, if applicable.
-
#tagline ⇒ Object
Single line description of site.
-
#title ⇒ Object
Title of site.
-
#tracking_id ⇒ Object
Google analytics tracking id.
-
#url ⇒ Object
Site’s URL.
-
#wiki_dir ⇒ Object
private
Do not set this in _settings.yml!.
-
#wiki_origin ⇒ Object
Gollum wiki’s repo uri.
-
#wiki_ref ⇒ Object
The particular tag or reference id to serve.
Class Method Summary collapse
-
.load(wiki_dir = nil) ⇒ Settings
Load settings.
Instance Method Summary collapse
-
#[](key) ⇒ Object
deprecated
Deprecated.
Do not use this in new code, and replace it when updating old code.
-
#assign(settings = {}) ⇒ void
(also: #update)
Assign settings hash via writer methods.
-
#initialize(settings = {}) ⇒ Settings
constructor
Initialize Settings.
- #relative?(path) ⇒ Boolean private
- #site ⇒ Object
-
#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.
-
#site_path ⇒ String
(also: #full_site_path)
Expanded site directory.
-
#site_repo ⇒ Object
Returns Repository object for git-based deployment site.
- #wiki ⇒ Object
- #wiki=(entry) ⇒ Object
Constructor Details
#initialize(settings = {}) ⇒ Settings
Initialize Settings.
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
#author ⇒ Object
Primary author/maintainer of site.
227 228 229 |
# File 'lib/smeagol/settings.rb', line 227 def @author end |
#date_format ⇒ Object
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 |
#description ⇒ Object
Detailed description of site.
224 225 226 |
# File 'lib/smeagol/settings.rb', line 224 def description @description end |
#exclude ⇒ Object
Files to exclude that would otherwise be included.
201 202 203 |
# File 'lib/smeagol/settings.rb', line 201 def exclude @exclude end |
#future ⇒ Object
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 |
#include ⇒ Object
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 |
#index ⇒ Object
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 |
#mathjax ⇒ Object
Support the use of mathjax? Default is ‘true`.
208 209 210 |
# File 'lib/smeagol/settings.rb', line 208 def mathjax @mathjax end |
#menu ⇒ Object
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.
246 247 248 |
# File 'lib/smeagol/settings.rb', line 246 def @menu end |
#partials ⇒ Object
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 |
#ribbon ⇒ Object
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`.
267 268 269 |
# File 'lib/smeagol/settings.rb', line 267 def ribbon @ribbon end |
#rss ⇒ Object
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_branch ⇒ Object
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_origin ⇒ Object
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.
154 155 156 |
# File 'lib/smeagol/settings.rb', line 154 def site_origin @site_origin end |
#site_stage ⇒ Object
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_sync ⇒ Object
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_url ⇒ Object
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 |
#tagline ⇒ Object
Single line description of site.
221 222 223 |
# File 'lib/smeagol/settings.rb', line 221 def tagline @tagline end |
#title ⇒ Object
Title of site.
218 219 220 |
# File 'lib/smeagol/settings.rb', line 218 def title @title end |
#tracking_id ⇒ Object
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 |
#url ⇒ Object
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_dir ⇒ Object
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_origin ⇒ Object
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_ref ⇒ Object
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.
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.(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
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)
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 |
#site ⇒ Object
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.
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_path ⇒ String 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.
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_repo ⇒ Object
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 |
#wiki ⇒ Object
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 |