1
+ require 'ascii_binder/template_renderer'
1
2
require 'asciidoctor'
2
3
require 'asciidoctor/cli'
3
4
require 'asciidoctor-diagram'
@@ -18,6 +19,10 @@ def self.source_dir
18
19
@source_dir ||= `git rev-parse --show-toplevel` . chomp
19
20
end
20
21
22
+ def self . set_source_dir ( source_dir )
23
+ @source_dir = source_dir
24
+ end
25
+
21
26
def self . template_dir
22
27
@template_dir ||= File . join ( source_dir , '_templates' )
23
28
end
@@ -42,9 +47,7 @@ def self.package_dir
42
47
end
43
48
end
44
49
45
- def_delegators self , :source_dir , :template_dir , :preview_dir , :package_dir
46
-
47
- TemplateRenderer . initialize_cache ( template_dir )
50
+ def_delegators self , :source_dir , :set_source_dir , :template_dir , :preview_dir , :package_dir
48
51
49
52
BUILD_FILENAME = '_build_cfg.yml'
50
53
DISTRO_MAP_FILENAME = '_distro_map.yml'
@@ -70,17 +73,17 @@ def git_checkout branch_name
70
73
71
74
def git_stash_all
72
75
# See if there are any changes in need of stashing
73
- @stash_needed = `git status --porcelain` !~ /^\s *$/
76
+ @stash_needed = `cd #{ source_dir } && git status --porcelain` !~ /^\s *$/
74
77
if @stash_needed
75
78
puts "\n NOTICE: Stashing uncommited changes and files in working branch."
76
- `git stash -u`
79
+ `cd #{ source_dir } && git stash -u`
77
80
end
78
81
end
79
82
80
83
def git_apply_and_drop
81
84
return unless @stash_needed
82
85
puts "\n NOTE: Re-applying uncommitted changes and files to working branch."
83
- if system ( "git stash pop" )
86
+ if system ( "cd #{ source_dir } && git stash pop" )
84
87
puts "NOTE: Stash application successful."
85
88
else
86
89
puts "ERROR: Could not apply stashed code. Run `git stash apply` manually."
@@ -184,7 +187,7 @@ def page(args)
184
187
args [ :subtopic_shim ] = '../'
185
188
end
186
189
187
- TemplateRenderer . new . render ( " _templates/page.html.erb", args )
190
+ TemplateRenderer . new . render ( File . expand_path ( " #{ source_dir } / _templates/page.html.erb") , args )
188
191
end
189
192
190
193
def extract_breadcrumbs ( args )
@@ -405,6 +408,9 @@ def generate_docs(build_distro,single_page=nil)
405
408
puts "Building all distributions."
406
409
end
407
410
411
+ # Cache the page templates
412
+ TemplateRenderer . initialize_cache ( template_dir )
413
+
408
414
# First, notify the user of missing local branches
409
415
missing_branches = [ ]
410
416
distro_branches ( build_distro ) . sort . each do |dbranch |
@@ -432,6 +438,9 @@ def generate_docs(build_distro,single_page=nil)
432
438
end
433
439
end
434
440
441
+ # Note the image files checked in to this branch.
442
+ branch_image_files = Find . find ( source_dir ) . select { |path | not path . nil? and ( path =~ /.*\. png$/ or path =~ /.*\. png\. cache$/ ) }
443
+
435
444
first_branch = single_page . nil?
436
445
437
446
if local_branch =~ /^\( detached from .*\) /
@@ -477,13 +486,13 @@ def generate_docs(build_distro,single_page=nil)
477
486
system ( "mkdir -p #{ branch_path } /images" )
478
487
479
488
# Copy stylesheets into preview area
480
- system ( "cp -r _stylesheets/*css #{ branch_path } /stylesheets" )
489
+ system ( "cp -r #{ source_dir } / _stylesheets/*css #{ branch_path } /stylesheets" )
481
490
482
491
# Copy javascripts into preview area
483
- system ( "cp -r _javascripts/*js #{ branch_path } /javascripts" )
492
+ system ( "cp -r #{ source_dir } / _javascripts/*js #{ branch_path } /javascripts" )
484
493
485
494
# Copy images into preview area
486
- system ( "cp -r _images/* #{ branch_path } /images" )
495
+ system ( "cp -r #{ source_dir } / _images/* #{ branch_path } /images" )
487
496
488
497
# Build the landing page
489
498
navigation = nav_tree ( distro , branch_build_config )
@@ -573,6 +582,15 @@ def generate_docs(build_distro,single_page=nil)
573
582
return
574
583
end
575
584
585
+ # Remove DITAA-generated images
586
+ ditaa_image_files = Find . find ( source_dir ) . select { |path | not path . nil? and not ( path =~ /_preview/ or path =~ /_package/ ) and ( path =~ /.*\. png$/ or path =~ /.*\. png\. cache$/ ) and not branch_image_files . include? ( path ) }
587
+ if not ditaa_image_files . empty?
588
+ puts "\n Removing ditaa-generated files from repo before changing branches."
589
+ ditaa_image_files . each do |dfile |
590
+ File . unlink ( dfile )
591
+ end
592
+ end
593
+
576
594
if local_branch == working_branch
577
595
# We're moving away from the working branch, so save off changed files
578
596
git_stash_all
@@ -652,6 +670,7 @@ def configure_and_generate_page options
652
670
:images_path => "../../#{ dir_depth } #{ branch_config [ "dir" ] } /images/" ,
653
671
:site_home_path => "../../#{ dir_depth } index.html" ,
654
672
:css => [ 'docs.css' ] ,
673
+ :template_dir => template_dir ,
655
674
}
656
675
full_file_text = page ( page_args )
657
676
File . write ( tgt_file_path , full_file_text )
@@ -706,5 +725,11 @@ def package_docs(package_site)
706
725
end
707
726
end
708
727
end
728
+
729
+ def clean_up
730
+ if not system ( "rm -rf #{ source_dir } /_preview/* #{ source_dir } /_package/*" )
731
+ puts "Nothing to clean."
732
+ end
733
+ end
709
734
end
710
735
end
0 commit comments