Class: Homeostasis::Multi
- Inherits:
-
Stasis::Plugin
- Object
- Stasis::Plugin
- Homeostasis::Multi
- Includes:
- Helpers
- Defined in:
- lib/homeostasis.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_render ⇒ Object
- #after_write ⇒ Object
- #before_render ⇒ Object
-
#initialize(stasis) ⇒ Multi
constructor
A new instance of Multi.
Constructor Details
#initialize(stasis) ⇒ Multi
Returns a new instance of Multi.
325 326 327 |
# File 'lib/homeostasis.rb', line 325 def initialize(stasis) @stasis = stasis end |
Class Method Details
.drop_tilt_exts(path) ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/homeostasis.rb', line 360 def self.drop_tilt_exts(path) dirname = File.dirname(path) basename = File.basename(path) exts = Helpers.tilt_exts_for(basename) return path if exts.nil? || exts.length < 1 exts.each do |ext| basename = basename.sub(/\.#{ext}/, '') end File.join(dirname, basename) end |
Instance Method Details
#after_render ⇒ Object
345 346 347 348 349 350 351 352 |
# File 'lib/homeostasis.rb', line 345 def after_render if @tmpfile @stasis.path = Helpers.stasis_path if @stasis.path !~ /^#{@stasis.root}/ Helpers.set_stasis_path(@stasis, nil) @tmpfile.unlink if @tmpfile @tmpfile = nil end end |
#after_write ⇒ Object
354 355 356 357 358 |
# File 'lib/homeostasis.rb', line 354 def after_write return if @stasis.path.nil? || ignore?(@stasis.path) dest = self.class.drop_tilt_exts(@stasis.dest) File.rename(@stasis.dest, dest) if dest != @stasis.dest end |
#before_render ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/homeostasis.rb', line 329 def before_render if @stasis.path && !ignore?(@stasis.path) exts = Helpers.tilt_exts_for(@stasis.path) return if exts.nil? || exts.length < 2 yaml, body = Front.preamble_load(@stasis.path) body ||= Helpers.read(@stasis.path) @tmpfile = Tempfile.new(["temp", ".txt"]) @tmpfile.puts(render_multi(@stasis.path, body, @stasis.action)) @tmpfile.close Helpers.set_stasis_path(@stasis, @stasis.path) @stasis.path = @tmpfile.path end end |