Module: Docter::Resource
- Defined in:
- lib/docter/common.rb
Overview
Base class for resources like pages, templates, ToC, and anything else that you can create dynamically, or load from a file. It’s the second usage that’s more interesting: when coming from a file, the resource is created lazily, and you can detect when it is modified and reload it.
A class that inherits from Resource must: a) call #load before using any value obtain from the resource (e.g page title), and b) implement one or more create_from_ methods for each content format it supports (e.g. create_from_textile).
Defined Under Namespace
Modules: Reloadable Classes: Base
Constant Summary collapse
- EXTENSIONS =
Maps various filename extensions to the appropriate format. You only need to use this when the filename extension is not the same as the format, e.g. map ‘.txt’ to :plain, but not necessary to map ‘.textile’.
{ ''=>:plain, '.txt'=>:plain, '.text'=>:plain, '.thtml'=>:textile, '.mhtml'=>:markdown }
Class Method Summary collapse
-
.format_from(filename) ⇒ Object
:call-seq: format_from(filename) => symbol.
Class Method Details
.format_from(filename) ⇒ Object
:call-seq:
format_from(filename) => symbol
Returns the format based on the filename. Basically uses the filename extension, possibly mapped using EXTENSIONS, and returns :plain if the filename has no extension.
47 48 49 50 |
# File 'lib/docter/common.rb', line 47 def format_from(filename) ext = File.extname(filename) EXTENSIONS[ext] || ext[1..-1].to_sym end |