lib/ascii_binder/helpers.rb in ascii_binder-0.1.3.2 vs lib/ascii_binder/helpers.rb in ascii_binder-0.1.4
- old
+ new
@@ -83,10 +83,26 @@
def build_date
Time.now.utc
end
+ def notice(hey,message,newline = false)
+ # TODO: (maybe) redirect everything to stderr
+ if newline
+ puts "\n"
+ end
+ puts "#{hey}: #{message}"
+ end
+
+ def warning(message,newline = false)
+ notice("WARNING",message,newline)
+ end
+
+ def nl_warning(message)
+ warning(message,true)
+ end
+
def git
@git ||= Git.open(source_dir)
end
def git_checkout branch_name
@@ -136,11 +152,11 @@
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}'."
+ warning "'#{BUILD_FILENAME}' is a deprecated filename. Rename this to '#{TOPIC_MAP_FILENAME}'."
end
use_file
end
def distro_map_file
@@ -213,11 +229,11 @@
end
end
end
end
if nonexistent_topics.length > 0
- puts "\nWARNING: The #{build_config_file} file on branch '#{branch}' references nonexistant topics:\n" + nonexistent_topics.map{ |topic| "- #{topic}" }.join("\n")
+ nl_warning "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)
@@ -469,10 +485,11 @@
'linkcss!',
'icons=font',
'idprefix=',
'idseparator=-',
'sectanchors',
+ 'data-uri',
].concat(more_attrs)
end
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
@@ -544,11 +561,11 @@
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_config_file} file:\n" + branch_orphan_files.map{ |file| "- #{file}" }.join("\n")
+ nl_warning "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|
if not build_distro == ''
@@ -741,20 +758,13 @@
"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")
+ doc = Asciidoctor.load topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs
+ article_title = doc.doctitle || topic['Name']
- topic_html = Asciidoctor.render topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs
+ topic_html = doc.render
dir_depth = ''
if branch_config['dir'].split('/').length > 1
dir_depth = '../' * (branch_config['dir'].split('/').length - 1)
end
if not topic_subgroup.nil?