Class: Yuzu::PreProcessors::InsertContentsPreProcessor
- Inherits:
-
PreProcessor
- Object
- Register
- PreProcessor
- Yuzu::PreProcessors::InsertContentsPreProcessor
- Includes:
- Helpers
- Defined in:
- lib/yuzu/preprocessors/insert_contents.rb
Instance Attribute Summary
Attributes inherited from PreProcessor
Instance Method Summary collapse
- #default(website_file = nil) ⇒ Object
-
#initialize ⇒ InsertContentsPreProcessor
constructor
A new instance of InsertContentsPreProcessor.
-
#insert_file(path) ⇒ String
A raw file insert.
- #replacement(website_file, new_contents = "") ⇒ Object
- #value(website_file) ⇒ Object
Methods inherited from PreProcessor
#match, preprocessors, #process, #regex, registry
Constructor Details
#initialize ⇒ InsertContentsPreProcessor
Returns a new instance of InsertContentsPreProcessor.
8 9 10 11 |
# File 'lib/yuzu/preprocessors/insert_contents.rb', line 8 def initialize @name = :insert_contents @directive = "INSERTCONTENTS" end |
Instance Method Details
#default(website_file = nil) ⇒ Object
13 14 15 |
# File 'lib/yuzu/preprocessors/insert_contents.rb', line 13 def default(website_file=nil) nil end |
#insert_file(path) ⇒ String
A raw file insert. Load the file from disk and insert the contents directly.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yuzu/preprocessors/insert_contents.rb', line 43 def insert_file(path) if path.exists? f = File.open(path.absolute, "r") contents = f.read f.close contents else "" end end |
#replacement(website_file, new_contents = "") ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/yuzu/preprocessors/insert_contents.rb', line 23 def replacement(website_file, new_contents="") # Get the next match. match_path = match(new_contents) raw_path = match_path.nil? ? default(website_file) : match_path file_path = Path.new(raw_path) siteroot = website_file.root file_to_insert = siteroot.find_file_by_path(file_path) if not file_to_insert.nil? "\n" + file_to_insert.prefiltered_contents else insert_file(file_path) end end |