Class: NanDoc::SiteMerge

Inherits:
Object
  • Object
show all
Includes:
Treebis::Capture3, Treebis::DirAsHash
Defined in:
lib/nandoc/support/site-merge.rb

Instance Method Summary collapse

Constructor Details

#initialize(site_creator) ⇒ SiteMerge

Returns a new instance of SiteMerge.



9
10
11
# File 'lib/nandoc/support/site-merge.rb', line 9

def initialize site_creator
  @creator = site_creator
end

Instance Method Details

#site_merge(opts, args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nandoc/support/site-merge.rb', line 12

def site_merge opts, args
  existing_site_path = args.first
  command_abort("it's not exist: #{path}") unless
    File.exist?(existing_site_path)
  # nanoc writes to stdout so we do too, but here we want to write
  # to stderr these notices, and write the diff to stdout
  out, err, diff = capture3 do
    $stdout.puts(
    "#------------------ (this is for the merge hack:) -----------------")
    @tmpdir = empty_tmpdir('ridiculous')
    existing_subset_path = temp_site_subset(existing_site_path)
    generated_site_path  = temp_generated_site opts
    order = [existing_subset_path, generated_site_path]
    order.reverse! if opts[:merge_hack_reverse]
    diff = DiffProxy.diff(order[0], order[1], :relative_to => @tmpdir)
    # you could delete the tempdirs now. we will leave them there
    diff
  end
  fail("hack failed: #{err.inspect}") unless err.empty?
  $stderr.puts out # write out to err here
  $stderr.puts diff.command
  $stderr.puts <<-HERE.gsub(/^ +/,'')
  #---------------- (above is stderr, below is stdout) ------------------
  HERE
  $stdout.puts diff.to_s
  diff
end