Module: Stic::Readable
Overview
Stic::Readable
Include this module for blobs that have a source file. It provides methods for reading and storing the source file.
Attributes collapse
-
#name ⇒ String
readonly
The blob file name.
-
#path ⇒ Path
readonly
The virtual path to this file including file name.
-
#source ⇒ Path
readonly
The full path to source file.
Construction collapse
-
#initialize(opts = {}) ⇒ Object
Initialize new file blob object.
Accessors collapse
-
#content ⇒ String
Return file content.
-
#render ⇒ String
Return final output as string.
-
#source_path ⇒ Path
Return full source path.
Actions collapse
-
#read ⇒ String
Read and return raw content.
Instance Attribute Details
#name ⇒ String (readonly)
33 34 35 |
# File 'lib/stic/readable.rb', line 33 def name @name end |
#path ⇒ Path (readonly)
The virtual path to this file including file name. This path represents the target in the generated output.
The path will be used to derive the #url_template.
25 26 27 |
# File 'lib/stic/readable.rb', line 25 def path @path end |
#source ⇒ Path (readonly)
The full path to source file.
16 17 18 |
# File 'lib/stic/readable.rb', line 16 def source @source end |
Instance Method Details
#content ⇒ String
Return file content.
This method caches file content and should be favored over #read.
83 84 85 |
# File 'lib/stic/readable.rb', line 83 def content @content ||= read end |
#initialize(opts = {}) ⇒ Object
Initialize new file blob object.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/stic/readable.rb', line 45 def initialize(opts = {}) super source = opts.delete(:source) { raise ::ArgumentError.new 'Argument `:source` required.' } path = opts.delete(:path) { source } @source = Path(source). @path = Path(path).as_relative @name = opts.delete(:name) || @path.name end |
#read ⇒ String
Read and return raw content.
It directly read the content from file every time called and should be avoided in favor of #content.
It can be overridden by subclasses implementing special input reading behavior.
99 100 101 |
# File 'lib/stic/readable.rb', line 99 def read source_path.read end |
#render ⇒ String
Return final output as string.
On file blob this will just returned the unchanged #content.
72 73 74 |
# File 'lib/stic/readable.rb', line 72 def render content end |
#source_path ⇒ Path
Return full source path.
62 63 64 |
# File 'lib/stic/readable.rb', line 62 def source_path source end |