lib/ascii_binder/helpers.rb in ascii_binder-0.1.4 vs lib/ascii_binder/helpers.rb in ascii_binder-0.1.5
- old
+ new
@@ -195,11 +195,13 @@
end
def find_topic_files
file_list = []
Find.find(source_dir).each do |path|
- next if path.nil? or not path =~ /.*\.adoc/ or path =~ /README/ or path =~ /\/old\//
+ # Only consider .adoc files and ignore README, and anything in
+ # directories whose names begin with 'old' or '_' (underscore)
+ next if path.nil? or not path =~ /.*\.adoc/ or path =~ /README/ or path =~ /\/old\// or path =~ /\/_/
src_path = Pathname.new(path).sub(source_dir,'').to_s
next if src_path.split('/').length < 3
file_list << src_path
end
file_list.map{ |path|
@@ -351,11 +353,14 @@
raise "One of the topic groups in #{build_config_file} is missing the '#{group_key}' key."
end
end
# Check for right format of topic group values
['Name','Dir'].each do |group_key|
- if not group[group_key].is_a?(String)
+ if [true, false].include?(group[group_key])
+ raise "One of the topic groups in #{build_config_file} is using a reserved YAML keyword for the #{group_key} setting. In order to prevent your text from being turned into a true/false value, wrap it in quotes."
+ end
+ if not group[group_key].kind_of?(String)
raise "One of the topic groups in #{build_config_file} is not using a string for the #{group_key} setting; current value is #{group[group_key].inspect}"
end
if group[group_key].empty? or group[group_key].match BLANK_STRING_RE
raise "One of the topic groups in #{build_config_file} is using a blank value for the #{group_key} setting."
end
@@ -744,22 +749,40 @@
src_group_path = options[:src_group_path]
tgt_group_path = options[:tgt_group_path]
single_page = options[:single_page]
site_name = options[:site_name]
+ # Distro Map settings can be overridden on a per-branch
+ # basis. This only works for top-level (string) values
+ # of the distro config and -not- the 'site' key.
+ branchwise_distro_config = {}
+ distro_config.each do |key,value|
+ next unless distro_config[key].kind_of?(String)
+ branchwise_distro_config[key] = value
+ end
+ if branch_config.has_key?('distro-overrides')
+ branch_config['distro-overrides'].each do |key,value|
+ if key == 'site'
+ puts "WARNING: The 'site' value of the distro config cannot be overriden on a branch-by-branch basis."
+ next
+ end
+ branchwise_distro_config[key] = value
+ end
+ end
+
src_file_path = File.join(src_group_path,"#{topic['File']}.adoc")
tgt_file_path = File.join(tgt_group_path,"#{topic['File']}.html")
if single_page.nil?
puts " - #{topic_path}"
end
topic_adoc = File.open(src_file_path,'r').read
page_attrs = asciidoctor_page_attrs([
"imagesdir=#{src_group_path}/images",
distro,
- "product-title=#{distro_config["name"]}",
+ "product-title=#{branchwise_distro_config["name"]}",
"product-version=#{branch_config["name"]}",
- "product-author=#{distro_config["author"]}"
+ "product-author=#{branchwise_distro_config["author"]}"
])
doc = Asciidoctor.load topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs
article_title = doc.doctitle || topic['Name']
@@ -771,13 +794,13 @@
if not topic_subgroup.nil?
dir_depth = '../' + dir_depth
end
page_args = {
:distro_key => distro,
- :distro => distro_config["name"],
+ :distro => branchwise_distro_config["name"],
:site_name => site_name,
- :site_url => distro_config["site_url"],
+ :site_url => branchwise_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'],
@@ -833,11 +856,15 @@
FileUtils.cp(File.join(preview_dir,distro,'index.html'),File.join(package_dir,site,'index.html'))
end
# Now build a sitemap
site_dir_path = Pathname.new(site_dir)
- SitemapGenerator::Sitemap.default_host = site_config[:url]
- SitemapGenerator::Sitemap.create( :compress => false, :filename => File.join(site_dir,'sitemap') ) do
+ SitemapGenerator::Sitemap.create(
+ :default_host => site_config[:url],
+ :public_path => site_dir_path,
+ :compress => false,
+ :filename => File.join(site_dir,'sitemap')
+ ) do
file_list = Find.find(site_dir).select{ |path| not path.nil? and path =~ /.*\.html$/ }.map{ |path| '/' + Pathname.new(path).relative_path_from(site_dir_path).to_s }
file_list.each do |file|
add(file, :changefreq => 'daily')
end
end