ascii_binder 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Guardfile +3 -0
- data/ascii_binder.gemspec +1 -0
- data/bin/asciibinder +155 -0
- data/lib/ascii_binder/helpers.rb +35 -10
- data/lib/ascii_binder/version.rb +1 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f0d4eedad5a44476a05c8b2dfe80341974779e
|
4
|
+
data.tar.gz: 8efa57a740e9c2f879f02f9e55abd63ea1985080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b286233ac388b2ab379f46d0d0125d12c30260dd0692f2a199d8f9b4ddbe7ebea8ddacd8e803e27960981fe0116b4e89b3f172e880f5a27974ef36e6bbcf4928
|
7
|
+
data.tar.gz: b622ed29d46c457b40970660083b58ccf4d56c43201a113b392419c563d7857fb4b36a0853f9ee88e0461b64c97fa1054975564a19951d48a6b9bb37054a288c
|
data/Guardfile
ADDED
data/ascii_binder.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_dependency 'json'
|
32
32
|
spec.add_dependency 'pandoc-ruby'
|
33
33
|
spec.add_dependency 'sitemap_generator', '~> 5.1.0'
|
34
|
+
spec.add_dependency 'trollop', '~> 2.1.2'
|
34
35
|
spec.add_dependency 'yajl-ruby'
|
35
36
|
spec.add_dependency 'tilt'
|
36
37
|
end
|
data/bin/asciibinder
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ascii_binder/helpers'
|
4
|
+
require 'pathname'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
|
8
|
+
include AsciiBinder::Helpers
|
9
|
+
|
10
|
+
SUB_COMMANDS = %w{help build watch package clean}
|
11
|
+
Trollop::options do
|
12
|
+
banner <<-EOF
|
13
|
+
Usage:
|
14
|
+
#$0 <command> <repo_dir>
|
15
|
+
|
16
|
+
Commands:
|
17
|
+
build (default action)
|
18
|
+
Builds the HTML docs in the indicated repo dir
|
19
|
+
watch
|
20
|
+
Starts Guard, which automatically regenerates changed HTML
|
21
|
+
files on the working branch in the repo dir
|
22
|
+
package
|
23
|
+
Builds and packages the static HTML for all of the sites
|
24
|
+
defined in the _distro_config.yml file
|
25
|
+
clean
|
26
|
+
Remove _preview, _publish and _package dirs created by
|
27
|
+
other asciibinder operations.
|
28
|
+
|
29
|
+
Options:
|
30
|
+
EOF
|
31
|
+
stop_on SUB_COMMANDS
|
32
|
+
end
|
33
|
+
|
34
|
+
cmd = ARGV.shift
|
35
|
+
repo_dir = nil
|
36
|
+
|
37
|
+
if cmd.nil?
|
38
|
+
cmd = "build"
|
39
|
+
elsif not SUB_COMMANDS.include?(cmd)
|
40
|
+
if not ARGV.empty?
|
41
|
+
Trollop::die "'#{cmd}' is not a valid asciibinder command. Legal values are '#{SUB_COMMANDS.join('\', \'')}'."
|
42
|
+
else
|
43
|
+
repo_dir = Pathname.new(cmd)
|
44
|
+
cmd = "build"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
cmd_opts = case cmd
|
49
|
+
when "build"
|
50
|
+
Trollop::options do
|
51
|
+
banner <<-EOF
|
52
|
+
Usage:
|
53
|
+
#$0 build <options> <repo_dir>
|
54
|
+
|
55
|
+
Description:
|
56
|
+
This is the default behavior for the asciibinder utility. When run,
|
57
|
+
asciibinder reads the _distro_config.yml file out of the working
|
58
|
+
branch of the indicated repo directory and based on that, proceeds to
|
59
|
+
build the working branch version of the documentation for each distro.
|
60
|
+
|
61
|
+
Once the working branch version is built, asciibinder cycles through
|
62
|
+
the other branches named in the _distro_config.yml file until all of
|
63
|
+
the permutations have been built.
|
64
|
+
|
65
|
+
Options:
|
66
|
+
EOF
|
67
|
+
opt :distro, "Instead of building all distros, build branches only for the specified distro.", :default => ''
|
68
|
+
end
|
69
|
+
#when "new"
|
70
|
+
# Trollop::options do
|
71
|
+
# opt :initialize, "Create a new AsciiBinder-ready git repo in the target directory.", :default => true
|
72
|
+
# end
|
73
|
+
when "watch"
|
74
|
+
Trollop::options do
|
75
|
+
banner <<-EOF
|
76
|
+
Usage:
|
77
|
+
#$0 watch <repo_dir>
|
78
|
+
|
79
|
+
Description:
|
80
|
+
In watch mode, asciibinder starts a Guard process in the foreground.
|
81
|
+
This process watches the repo_dir for changes to the AsciiDoc (.adoc)
|
82
|
+
files. When a change occurs, asciibinder regenerates the specific
|
83
|
+
HTML output of the file that was changed, for the working branch only.
|
84
|
+
|
85
|
+
This is meant to be used in conjunction with a web browser that is
|
86
|
+
running a LiveReload plugin. If you are viewing the output HTML page
|
87
|
+
in a browser where LiveReload is active, then every time you save a
|
88
|
+
new version of the .adoc file, the new HTML is automatically
|
89
|
+
regenrated and your page view is automatically refreshed.
|
90
|
+
EOF
|
91
|
+
end
|
92
|
+
when "package"
|
93
|
+
Trollop::options do
|
94
|
+
banner <<-EOF
|
95
|
+
Usage:
|
96
|
+
#$0 package <options> <repo_dir>
|
97
|
+
|
98
|
+
Description:
|
99
|
+
Publish mode is similar to 'build' mode, but once all of the branches' of
|
100
|
+
HTML are generated, 'publish' goes on to organize the branch / distro
|
101
|
+
combinations that are described in _distro_config.yml into their "site"
|
102
|
+
layouts. As a final step, the site layouts are tarred and gzipped for
|
103
|
+
easy placement onto a production web server.
|
104
|
+
|
105
|
+
Options:
|
106
|
+
EOF
|
107
|
+
opt :site, "Instead of packaging every docs site, package the specified site only.", :default => ''
|
108
|
+
end
|
109
|
+
when "help"
|
110
|
+
Trollop::educate
|
111
|
+
end
|
112
|
+
|
113
|
+
if (not repo_dir.nil? and not ARGV.empty?) or (repo_dir.nil? and ARGV.length > 1)
|
114
|
+
Trollop::die "Too many arguments provided to ascii_binder: '#{ARGV.join(' ')}'. Exiting."
|
115
|
+
elsif repo_dir.nil?
|
116
|
+
if ARGV.length == 1
|
117
|
+
repo_dir = Pathname.new(ARGV.shift)
|
118
|
+
else
|
119
|
+
repo_dir = Pathname.pwd
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Validate the repo_dir path
|
124
|
+
if not repo_dir.exist?
|
125
|
+
Trollop::die "The specified repo directory '#{repo_dir}' does not exist."
|
126
|
+
elsif not repo_dir.directory?
|
127
|
+
Trollop::die "The specified repo directory path '#{repo_dir}' is not a directory."
|
128
|
+
elsif not repo_dir.readable?
|
129
|
+
Trollop::die "The specified repo directory '#{repo_dir}' is not readable."
|
130
|
+
elsif not repo_dir.writable?
|
131
|
+
Trollop::die "The specified repo directory '#{repo_dir}' cannot be written to."
|
132
|
+
end
|
133
|
+
|
134
|
+
# Set the repo root
|
135
|
+
set_source_dir(File.expand_path(repo_dir))
|
136
|
+
|
137
|
+
# Do the things with the stuff
|
138
|
+
case cmd
|
139
|
+
when "build"
|
140
|
+
build_distro = cmd_opts[:build] || ''
|
141
|
+
generate_docs(build_distro)
|
142
|
+
when "package"
|
143
|
+
clean_up
|
144
|
+
generate_docs('')
|
145
|
+
package_site = cmd_opts[:site] || ''
|
146
|
+
package_docs(package_site)
|
147
|
+
when "watch"
|
148
|
+
guardfile_path = File.join(Gem::Specification.find_by_name("ascii_binder").full_gem_path, 'Guardfile')
|
149
|
+
exec("guard -G #{guardfile_path}")
|
150
|
+
when "clean"
|
151
|
+
clean_up
|
152
|
+
puts "Cleaned up #{repo_dir}."
|
153
|
+
end
|
154
|
+
|
155
|
+
exit
|
data/lib/ascii_binder/helpers.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ascii_binder/template_renderer'
|
1
2
|
require 'asciidoctor'
|
2
3
|
require 'asciidoctor/cli'
|
3
4
|
require 'asciidoctor-diagram'
|
@@ -18,6 +19,10 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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 "\nNOTICE: 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 "\nNOTE: 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 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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 "\nRemoving 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 @@ module AsciiBinder
|
|
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 @@ module AsciiBinder
|
|
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
|
data/lib/ascii_binder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ascii_binder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- N. Harrison Ripps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 5.1.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: trollop
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 2.1.2
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 2.1.2
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: yajl-ruby
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,16 +223,19 @@ dependencies:
|
|
209
223
|
description: Builder for multi product documention websites.
|
210
224
|
email:
|
211
225
|
- nhr@redhat.com
|
212
|
-
executables:
|
226
|
+
executables:
|
227
|
+
- asciibinder
|
213
228
|
extensions: []
|
214
229
|
extra_rdoc_files: []
|
215
230
|
files:
|
216
231
|
- ".gitignore"
|
217
232
|
- Gemfile
|
233
|
+
- Guardfile
|
218
234
|
- LICENSE.txt
|
219
235
|
- README.adoc
|
220
236
|
- Rakefile
|
221
237
|
- ascii_binder.gemspec
|
238
|
+
- bin/asciibinder
|
222
239
|
- lib/ascii_binder.rb
|
223
240
|
- lib/ascii_binder/helpers.rb
|
224
241
|
- lib/ascii_binder/tasks/guards.rb
|