Class: Flott::Cache::Page
- Inherits:
-
Object
- Object
- Flott::Cache::Page
- Defined in:
- lib/flott/cache.rb
Overview
A Page object that encapsulates a compiled template.
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the compiled template or nil if the template hasn’t been compiled.
Instance Method Summary collapse
-
#changed? ⇒ Boolean
If the file at path has changed this method returns true.
-
#compile ⇒ Object
Compile the file at path with a Flott instance and return it.
-
#initialize(cache, path) ⇒ Page
constructor
Creates a Page object for the template that can be found at path path.
-
#rootpath ⇒ Object
Returns the path to this page, with the prepended rootdir of the Cache instance of this page.
Constructor Details
#initialize(cache, path) ⇒ Page
Creates a Page object for the template that can be found at path path.
7 8 9 10 11 |
# File 'lib/flott/cache.rb', line 7 def initialize(cache, path) @cache = cache @path = path compile end |
Instance Attribute Details
#template ⇒ Object (readonly)
Returns the compiled template or nil if the template hasn’t been compiled.
15 16 17 |
# File 'lib/flott/cache.rb', line 15 def template @template end |
Instance Method Details
#changed? ⇒ Boolean
If the file at path has changed this method returns true. It always returns true, if the attribute reload_time is set to a value < 0. If reload_time is set to a value >= 0, it will return true only after reload_time seconds (before that time has passed nil is returned), even if the file has changed.
23 24 25 26 27 28 29 |
# File 'lib/flott/cache.rb', line 23 def changed? return true if @cache.reload_time and @cache.reload_time < 0 if @cache.reload_time and Time.now - @template.mtime < @cache.reload_time return end @template.mtime != @mtime end |
#compile ⇒ Object
Compile the file at path with a Flott instance and return it. This implies that the template attribute is set to the return value for later reuse without compiling.
40 41 42 43 44 45 |
# File 'lib/flott/cache.rb', line 40 def compile @template = Flott.compile(File.read(rootpath), File.dirname(rootpath), @cache.rootdir, rootpath) @template.page_cache = @cache @mtime = @template.mtime @template end |
#rootpath ⇒ Object
Returns the path to this page, with the prepended rootdir of the Cache instance of this page.
33 34 35 |
# File 'lib/flott/cache.rb', line 33 def rootpath File.join(@cache.rootdir, @path) end |