Class: Homeostasis::Front
- Inherits:
-
Stasis::Plugin
- Object
- Stasis::Plugin
- Homeostasis::Front
- Includes:
- Helpers
- Defined in:
- lib/homeostasis.rb
Class Method Summary collapse
-
._front_key(stasis, filename) ⇒ Object
for other plugins.
-
._front_site ⇒ Object
for other plugins.
- .config(options) ⇒ Object
- .preamble_load(path) ⇒ Object
Instance Method Summary collapse
- #after_render ⇒ Object
- #before_all ⇒ Object
- #before_render ⇒ Object
- #front ⇒ Object
- #front_site ⇒ Object
-
#initialize(stasis) ⇒ Front
constructor
A new instance of Front.
Constructor Details
Class Method Details
._front_key(stasis, filename) ⇒ Object
for other plugins
282 283 284 |
# File 'lib/homeostasis.rb', line 282 def self._front_key(stasis, filename) # for other plugins filename.sub(stasis.root, '')[1..-1] end |
._front_site ⇒ Object
for other plugins
278 279 280 |
# File 'lib/homeostasis.rb', line 278 def self._front_site # for other plugins @@front_site end |
.config(options) ⇒ Object
286 287 288 |
# File 'lib/homeostasis.rb', line 286 def self.config() @@matcher = [:matcher] if [:matcher] end |
.preamble_load(path) ⇒ Object
290 291 292 293 294 295 296 |
# File 'lib/homeostasis.rb', line 290 def self.preamble_load(path) return nil if path.nil? || path !~ @@matcher data = Preamble.load(path) [data., data.content] rescue [{}, Helpers.read(path)] end |
Instance Method Details
#after_render ⇒ Object
261 262 263 264 265 266 267 268 |
# File 'lib/homeostasis.rb', line 261 def after_render if @tmpfile @stasis.path = Helpers.stasis_path if @stasis.path !~ /^#{@stasis.root}/ Helpers.set_stasis_path(@stasis, nil) @tmpfile.unlink @tmpfile = nil end end |
#before_all ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/homeostasis.rb', line 231 def before_all @stasis.paths.each do |path| yaml, body = Front.preamble_load(path) next if yaml.nil? # add special :path key for generated files if !ignore?(path) relative = path[(@stasis.root.length+1)..-1] ext = Tilt.mappings.keys.find { |ext| File.extname(path)[1..-1] == ext } dest = (ext && File.extname(relative) == ".#{ext}") ? relative[0..-1*ext.length-2] : relative yaml[:path] = trailify(Multi.drop_tilt_exts(dest)) end @@front_site[front_key(path)] = FrontHash.from_hash(yaml) end end |
#before_render ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/homeostasis.rb', line 249 def before_render if @stasis.path && @stasis.path =~ @@matcher && !ignore?(@stasis.path) ext = File.basename(@stasis.path).split('.', 2).last yaml, body = Front.preamble_load(@stasis.path) @tmpfile = Tempfile.new(['temp', ".#{ext}"]) @tmpfile.puts(body) @tmpfile.close Helpers.set_stasis_path(@stasis, @stasis.path) @stasis.path = @tmpfile.path end end |
#front ⇒ Object
270 271 272 |
# File 'lib/homeostasis.rb', line 270 def front @@front_site[front_key(Helpers.stasis_path || @stasis.path)] || FrontHash.new end |
#front_site ⇒ Object
274 275 276 |
# File 'lib/homeostasis.rb', line 274 def front_site @@front_site end |