lib/ascii_binder/helpers.rb in ascii_binder-0.1.2 vs lib/ascii_binder/helpers.rb in ascii_binder-0.1.3
- old
+ new
@@ -69,12 +69,12 @@
end
def_delegators self, :source_dir, :set_source_dir, :template_dir, :preview_dir, :package_dir, :gem_root_dir, :stylesheet_dir, :javascript_dir, :image_dir
BUILD_FILENAME = '_build_cfg.yml'
+ TOPIC_MAP_FILENAME = '_topic_map.yml'
DISTRO_MAP_FILENAME = '_distro_map.yml'
- BUILDER_DIRNAME = '_build_system'
PREVIEW_DIRNAME = '_preview'
PACKAGE_DIRNAME = '_package'
STYLESHEET_DIRNAME = '_stylesheets'
JAVASCRIPT_DIRNAME = '_javascripts'
IMAGE_DIRNAME = '_images'
@@ -131,11 +131,18 @@
def working_branch
@working_branch ||= local_branches[0]
end
def build_config_file
- @build_config_file ||= File.join(source_dir,BUILD_FILENAME)
+ use_file = TOPIC_MAP_FILENAME
+ unless File.exist?(File.join(source_dir,TOPIC_MAP_FILENAME))
+ # The new filename '_topic_map.yml' couldn't be found;
+ # switch to the old one and warn the user.
+ use_file = BUILD_FILENAME
+ puts "WARNING: '#{BUILD_FILENAME}' is a deprecated filename. Rename this to '#{TOPIC_MAP_FILENAME}'."
+ end
+ use_file
end
def distro_map_file
@distro_map_file ||= File.join(source_dir, DISTRO_MAP_FILENAME)
end
@@ -144,22 +151,18 @@
Dir.entries(dir).select{ |f| not f.start_with?('.') }.empty?
end
# Protip: Don't cache this! It needs to be reread every time we change branches.
def build_config
- validate_config(YAML.load_stream(open(build_config_file)))
+ validate_config(YAML.load_stream(open(File.join(source_dir,build_config_file))))
end
def create_new_repo
gem_template_dir = File.join(gem_root_dir,"templates")
# Create the new repo dir
- begin
- Dir.mkdir(source_dir)
- rescue Exception => e
- raise "Could not create directory '#{source_dir}': #{e.message}"
- end
+ FileUtils.mkdir_p(source_dir)
# Copy the basic repo content into the new repo dir
Find.find(gem_template_dir).each do |path|
next if path == gem_template_dir
src_path = Pathname.new(path)
@@ -169,17 +172,12 @@
else
FileUtils.cp src_path.to_s, tgt_path.to_s
end
end
- # Initialize the git repo and check everything in
- g = nil
- begin
- g = Git.init(source_dir)
- rescue Exception => e
- raise "Could not initialize git repo in '#{source_dir}': #{e.message}"
- end
+ # Initialize the git repo
+ Git.init(source_dir)
end
def find_topic_files
file_list = []
Find.find(source_dir).each do |path|
@@ -215,11 +213,11 @@
end
end
end
end
if nonexistent_topics.length > 0
- puts "\nWARNING: The _build_cfg.yml file on branch '#{branch}' references nonexistant topics:\n" + nonexistent_topics.map{ |topic| "- #{topic}" }.join("\n")
+ puts "\nWARNING: The #{build_config_file} file on branch '#{branch}' references nonexistant topics:\n" + nonexistent_topics.map{ |topic| "- #{topic}" }.join("\n")
end
end
def distro_map
@distro_map ||= YAML.load_file(distro_map_file)
@@ -235,13 +233,21 @@
end
site_map
end
def distro_branches(use_distro='')
- @distro_branches ||= begin
- use_distro_list = use_distro == '' ? distro_map.keys : [use_distro]
- distro_map.select{ |dkey,dval| use_distro_list.include?(dkey) }.map{ |distro,dconfig| dconfig["branches"].keys }.flatten
+ use_distro_list = use_distro == '' ? distro_map.keys : [use_distro]
+ distro_map.select{ |dkey,dval| use_distro_list.include?(dkey) }.map{ |distro,dconfig| dconfig["branches"].keys }.flatten
+ end
+
+ def branch_group_branches
+ @branch_group_branches ||= begin
+ group_branches = Hash.new
+ group_branches[:working_only] = [local_branches[0]]
+ group_branches[:publish] = distro_branches
+ group_branches[:all] = local_branches
+ group_branches
end
end
def page(args)
# TODO: This process of rebuilding the entire nav for every page will not scale well.
@@ -466,11 +472,11 @@
'idseparator=-',
'sectanchors',
].concat(more_attrs)
end
- def generate_docs(build_distro,single_page=nil)
+ def generate_docs(branch_group,build_distro,single_page)
# First, test to see if the docs repo has any commits. If the user has just
# run `asciibinder create`, there will be no commits to work from, yet.
if local_branches.empty?
raise "Before you can build the docs, you need at least one commit in your docs repo."
end
@@ -505,12 +511,15 @@
puts "- #{mbranch}"
end
puts "The build will proceed but these branches will not be generated."
end
- # Generate all distros for every local branch
- local_branches.each do |local_branch|
+ # Generate all distros for all branches in the indicated branch group
+ branch_group_branches[branch_group].each do |local_branch|
+ # Skip known missing branches; this will only come up for the :publish branch group
+ next if missing_branches.include?(local_branch)
+
# Single-page regen only occurs for the working branch
if not local_branch == working_branch
if single_page.nil?
# Checkout the branch
puts "\nCHANGING TO BRANCH '#{local_branch}'"
@@ -535,18 +544,32 @@
branch_orphan_files = find_topic_files
branch_build_config = build_config
remove_found_config_files(local_branch,branch_build_config,branch_orphan_files)
if branch_orphan_files.length > 0 and single_page.nil?
- puts "\nWARNING: Branch '#{local_branch}' includes the following .adoc files that are not referenced in the _build_cfg.yml file:\n" + branch_orphan_files.map{ |file| "- #{file}" }.join("\n")
+ puts "\nWARNING: Branch '#{local_branch}' includes the following .adoc files that are not referenced in the #{build_config_file} file:\n" + branch_orphan_files.map{ |file| "- #{file}" }.join("\n")
end
# Run all distros.
distro_map.each do |distro,distro_config|
- # Only building a single distro; skip the others.
- if not build_distro == '' and not build_distro == distro
- next
+ if not build_distro == ''
+ # Only building a single distro; build for all indicated branches, skip the others.
+ if not build_distro == distro
+ next
+ end
+ else
+ current_distro_branches = distro_branches(distro)
+
+ # In publish mode we only build "valid" distro-branch combos from the distro map
+ if branch_group == :publish and not current_distro_branches.include?(local_branch)
+ next
+ end
+
+ # In "build all" mode we build every distro on the working branch plus the publish distro-branch combos
+ if branch_group == :all and not local_branch == working_branch and not current_distro_branches.include?(local_branch)
+ next
+ end
end
site_name = distro_config["site_name"]
branch_config = { "name" => "Branch Build", "dir" => local_branch }
@@ -718,49 +741,51 @@
"product-title=#{distro_config["name"]}",
"product-version=#{branch_config["name"]}",
"product-author=#{distro_config["author"]}"
])
- # Because we render only the body of the article with AsciiDoctor, the full article title
- # would be lost in conversion. So, use the _build_cfg.yml 'Name' as a fallback but try
- # to read the full article title out of the file itself.
- file_lines = topic_adoc.split("\n")
- article_title = topic['Name']
- if file_lines.length > 0
- article_title = file_lines[0].gsub(/^\=\s+/, '').gsub(/\s+$/, '').gsub(/\{product-title\}/, distro_config["name"]).gsub(/\{product-version\}/, branch_config["name"])
- end
- topic_adoc = file_lines.join("\n")
+ # Because we render only the body of the article with AsciiDoctor, the full article title
+ # would be lost in conversion. So, use the _build_cfg.yml 'Name' as a fallback but try
+ # to read the full article title out of the file itself.
+ file_lines = topic_adoc.split("\n")
+ article_title = topic['Name']
+ if file_lines.length > 0
+ article_title = file_lines[0].gsub(/^\=\s+/, '').gsub(/\s+$/, '').gsub(/\{product-title\}/, distro_config["name"]).gsub(/\{product-version\}/, branch_config["name"])
+ end
+ topic_adoc = file_lines.join("\n")
- topic_html = Asciidoctor.render topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs
- dir_depth = ''
- if branch_config['dir'].split('/').length > 1
- dir_depth = '../' * (branch_config['dir'].split('/').length - 1)
- end
- if not topic_subgroup.nil?
- dir_depth = '../' + dir_depth
- end
- page_args = {
- :distro_key => distro,
- :distro => distro_config["name"],
- :site_name => site_name,
- :version => branch_config["name"],
- :group_title => topic_group['Name'],
- :subgroup_title => topic_subgroup && topic_subgroup['Name'],
- :topic_title => topic['Name'],
- :article_title => article_title,
- :content => topic_html,
- :navigation => navigation,
- :group_id => topic_group['ID'],
- :subgroup_id => topic_subgroup && topic_subgroup['ID'],
- :topic_id => topic['ID'],
- :css_path => "../../#{dir_depth}#{branch_config["dir"]}/#{STYLESHEET_DIRNAME}/",
- :javascripts_path => "../../#{dir_depth}#{branch_config["dir"]}/#{JAVASCRIPT_DIRNAME}/",
- :images_path => "../../#{dir_depth}#{branch_config["dir"]}/#{IMAGE_DIRNAME}/",
- :site_home_path => "../../#{dir_depth}index.html",
- :template_path => template_dir,
- }
- full_file_text = page(page_args)
- File.write(tgt_file_path,full_file_text)
+ topic_html = Asciidoctor.render topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs
+ dir_depth = ''
+ if branch_config['dir'].split('/').length > 1
+ dir_depth = '../' * (branch_config['dir'].split('/').length - 1)
+ end
+ if not topic_subgroup.nil?
+ dir_depth = '../' + dir_depth
+ end
+ page_args = {
+ :distro_key => distro,
+ :distro => distro_config["name"],
+ :site_name => site_name,
+ :site_url => distro_config["site_url"],
+ :topic_url => "#{branch_config['dir']}/#{topic_path}.html",
+ :version => branch_config["name"],
+ :group_title => topic_group['Name'],
+ :subgroup_title => topic_subgroup && topic_subgroup['Name'],
+ :topic_title => topic['Name'],
+ :article_title => article_title,
+ :content => topic_html,
+ :navigation => navigation,
+ :group_id => topic_group['ID'],
+ :subgroup_id => topic_subgroup && topic_subgroup['ID'],
+ :topic_id => topic['ID'],
+ :css_path => "../../#{dir_depth}#{branch_config["dir"]}/#{STYLESHEET_DIRNAME}/",
+ :javascripts_path => "../../#{dir_depth}#{branch_config["dir"]}/#{JAVASCRIPT_DIRNAME}/",
+ :images_path => "../../#{dir_depth}#{branch_config["dir"]}/#{IMAGE_DIRNAME}/",
+ :site_home_path => "../../#{dir_depth}index.html",
+ :template_path => template_dir,
+ }
+ full_file_text = page(page_args)
+ File.write(tgt_file_path,full_file_text)
end
# package_docs
# This method generates the docs and then organizes them the way they will be arranged
# for the production websites.