Class: Middleman::Diff::Preview

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-diff/preview.rb

Overview

Preview of the build

Instance Method Summary collapse

Constructor Details

#initialize(app, build_hooks: true, temp_dir: 'tmp') ⇒ void

Generate a preview of the build.

Parameters:

  • app (Middleman::Appliation)

    Middleman application instance

  • build_hooks (Boolean) (defaults to: true)
  • temp_dir (String) (defaults to: 'tmp')

    path to temporary directory



16
17
18
19
20
21
22
# File 'lib/middleman-diff/preview.rb', line 16

def initialize(app, build_hooks: true, temp_dir: 'tmp')
  @app = app
  @build_hooks = build_hooks
  @temp_dir = Pathname.new(temp_dir)

  build_preview
end

Instance Method Details

#disposevoid

This method returns an undefined value.

Clean up any temporary files from the preview.



27
28
29
# File 'lib/middleman-diff/preview.rb', line 27

def dispose
  preview_dir.rmtree if preview_dir.exist?
end

#replace_buildvoid

This method returns an undefined value.

Replace the existing build with the preview.



34
35
36
37
# File 'lib/middleman-diff/preview.rb', line 34

def replace_build
  build_dir.rmtree
  FileUtils.move preview_dir, build_dir
end

#show_diffvoid

This method returns an undefined value.

Output a diff of the existing build and preview.



42
43
44
45
# File 'lib/middleman-diff/preview.rb', line 42

def show_diff
  prefix = %w(git diff --no-index --patch-with-stat --)
  system(*(prefix + [build_dir.to_s, preview_dir.to_s]))
end