Class: Smartgen::MarkupFile
- Inherits:
-
Object
- Object
- Smartgen::MarkupFile
- Defined in:
- lib/smartgen/markup_file.rb
Overview
A MarkupFile is created for each file that will be generated.
It is also exposed in layouts, as markup_file
variable.
It receives the path
of the file and process it using the first suitable engine, based on the extension of the file.
It can also receive an options hash with indexer options:
MarkupFile.new 'some/path', :indexer => true
Or, if you want to pass options for the Indexer:
MarkupFile.new 'some/path', :indexer => { :numbered_index => true }
Instance Attribute Summary collapse
-
#contents ⇒ Object
The contents of the file after processing.
-
#engine ⇒ Object
The engine used to process the file.
-
#extension ⇒ Object
The extension of the file.
-
#filename ⇒ Object
The name of the file, without extension.
-
#indexer ⇒ Object
The indexer instance, if
options[:indexer]
is given. -
#path ⇒ Object
The path of the file.
Class Method Summary collapse
-
.engines ⇒ Object
Returns an array with the supported engines.
-
.register(engine) ⇒ Object
Register an engine to be used when generating files.
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ MarkupFile
constructor
A new instance of MarkupFile.
-
#raw_contents ⇒ Object
The contents of the file before processing.
Constructor Details
#initialize(path, options = {}) ⇒ MarkupFile
Returns a new instance of MarkupFile.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/smartgen/markup_file.rb', line 40 def initialize(path, ={}) @path = path @extension = File.extname(path) @filename = filename_for(path) @engine = engine_for(@extension) || self.class.engines.first @contents = engine.process(raw_contents, [:metadata]) if [:indexer] @indexer = Smartgen::Indexer.new(@contents, [:indexer]) @contents = @indexer.result end end |
Instance Attribute Details
#contents ⇒ Object
The contents of the file after processing.
35 36 37 |
# File 'lib/smartgen/markup_file.rb', line 35 def contents @contents end |
#engine ⇒ Object
The engine used to process the file.
32 33 34 |
# File 'lib/smartgen/markup_file.rb', line 32 def engine @engine end |
#extension ⇒ Object
The extension of the file.
29 30 31 |
# File 'lib/smartgen/markup_file.rb', line 29 def extension @extension end |
#filename ⇒ Object
The name of the file, without extension.
26 27 28 |
# File 'lib/smartgen/markup_file.rb', line 26 def filename @filename end |
#indexer ⇒ Object
The indexer instance, if options[:indexer]
is given
38 39 40 |
# File 'lib/smartgen/markup_file.rb', line 38 def indexer @indexer end |
#path ⇒ Object
The path of the file.
23 24 25 |
# File 'lib/smartgen/markup_file.rb', line 23 def path @path end |
Class Method Details
.engines ⇒ Object
Returns an array with the supported engines.
The priority of the engines is defined by their order in this array. The first ones are the ones with higher priority.
65 66 67 68 69 70 71 |
# File 'lib/smartgen/markup_file.rb', line 65 def engines if @engines.blank? @engines = [Smartgen::Engine::Textile.new, Smartgen::Engine::Markdown.new, Smartgen::Engine::ERB.new] end @engines end |
.register(engine) ⇒ Object
Register an engine to be used when generating files.
The engine will be added with the highest priority.
76 77 78 |
# File 'lib/smartgen/markup_file.rb', line 76 def register(engine) engines.unshift engine.new end |
Instance Method Details
#raw_contents ⇒ Object
The contents of the file before processing.
56 57 58 |
# File 'lib/smartgen/markup_file.rb', line 56 def raw_contents File.read(path) end |