lib/ascii_binder/engine.rb in ascii_binder-1.0.1 vs lib/ascii_binder/engine.rb in ascii_binder-1.2
- old
+ new
@@ -109,15 +109,17 @@
# topic map files are in the _topic_maps folder
# create a combined temp file with all topic maps
tf = Tempfile.new("#{TOPIC_MAP_FILENAME}")
- Dir.glob("#{topic_map_folder}/*.yml").each do |filename|
+ Dir.glob("#{topic_map_folder}/*.yml").sort.each do |filename|
lines = IO.read(filename)
tf << lines
+ tf.write "\n"
end
+ tf.rewind
t = tf.path
end
# returns the path to the final file
t
@@ -215,58 +217,88 @@
end
def page(args)
# TODO: This process of rebuilding the entire nav for every page will not scale well.
# As the doc set increases, we will need to think about refactoring this.
- args[:breadcrumb_root], args[:breadcrumb_group], args[:breadcrumb_subgroup], args[:breadcrumb_topic] = extract_breadcrumbs(args)
+ args[:breadcrumb_root], args[:breadcrumb_group], args[:breadcrumb_subgroup], args[:breadcrumb_subsubgroup], args[:breadcrumb_topic] = extract_breadcrumbs(args)
args[:breadcrumb_subgroup_block] = ''
if args[:breadcrumb_subgroup]
args[:breadcrumb_subgroup_block] = "<li class=\"hidden-xs active\">#{args[:breadcrumb_subgroup]}</li>"
end
+ args[:breadcrumb_subsubgroup_block] = ''
+ if args[:breadcrumb_subsubgroup]
+ args[:breadcrumb_subsubgroup_block] = "<li class=\"hidden-xs active\">#{args[:breadcrumb_subsubgroup]}</li>"
+ end
+
args[:subtopic_shim] = '../' * (args[:topic_id].split('::').length - 2)
args[:subtopic_shim] = '' if args[:subtopic_shim].nil?
template_path = File.expand_path("#{docs_root_dir}/_templates/page.html.erb")
template_renderer.render(template_path, args)
end
def extract_breadcrumbs(args)
breadcrumb_root = breadcrumb_group = breadcrumb_subgroup = breadcrumb_topic = nil
+ selected_subgroup = selected_subsubgroup = nil
root_group = args[:navigation].first
selected_group = args[:navigation].detect { |group| group[:id] == args[:group_id] }
selected_subgroup = selected_group[:topics].detect { |subgroup| subgroup[:id] == args[:subgroup_id] }
- current_is_subtopic = selected_subgroup ? true : false
+ if selected_subgroup
+ selected_subsubgroup = selected_subgroup[:topics].detect { |subsubgroup| subsubgroup[:id] == args[:subsubgroup_id] }
+ end
+ offset = 0;
+ if selected_subgroup
+ offset = 1
+ end
+ if selected_subsubgroup
+ offset = 2
+ end
+
if root_group
root_topic = root_group[:topics].first
- breadcrumb_root = linkify_breadcrumb(root_topic[:path], "#{args[:distro]} #{args[:version]}", current_is_subtopic) if root_topic
+ breadcrumb_root = linkify_breadcrumb(root_topic[:path], "#{args[:distro]} #{args[:version]}", offset) if root_topic
end
if selected_group
group_topic = selected_group[:topics].first
- breadcrumb_group = linkify_breadcrumb(group_topic[:path], selected_group[:name], current_is_subtopic) if group_topic
+ breadcrumb_group = linkify_breadcrumb(group_topic[:path], selected_group[:name], offset) if group_topic
+ selected_topic = selected_group[:topics].detect { |topic| topic[:id] == args[:topic_id] }
+ breadcrumb_topic = linkify_breadcrumb(nil, selected_topic[:name], offset) if selected_topic
+ end
- if selected_subgroup
- subgroup_topic = selected_subgroup[:topics].first
- breadcrumb_subgroup = linkify_breadcrumb(subgroup_topic[:path], selected_subgroup[:name], current_is_subtopic) if subgroup_topic
+ if selected_subgroup
+ subgroup_topic = selected_subgroup[:topics].first
+ breadcrumb_subgroup = linkify_breadcrumb(subgroup_topic[:path], selected_subgroup[:name], offset) if subgroup_topic
- selected_topic = selected_subgroup[:topics].detect { |topic| topic[:id] == args[:topic_id] }
- breadcrumb_topic = linkify_breadcrumb(nil, selected_topic[:name], current_is_subtopic) if selected_topic
- else
- selected_topic = selected_group[:topics].detect { |topic| topic[:id] == args[:topic_id] }
- breadcrumb_topic = linkify_breadcrumb(nil, selected_topic[:name], current_is_subtopic) if selected_topic
- end
+ selected_topic = selected_subgroup[:topics].detect { |topic| topic[:id] == args[:topic_id] }
+ breadcrumb_topic = linkify_breadcrumb(nil, selected_topic[:name], offset) if selected_topic
end
- return breadcrumb_root, breadcrumb_group, breadcrumb_subgroup, breadcrumb_topic
+ if selected_subsubgroup
+ subsubgroup_topic = selected_subsubgroup[:topics].first
+ breadcrumb_subsubgroup = linkify_breadcrumb(subsubgroup_topic[:path], selected_subsubgroup[:name], offset) if subsubgroup_topic
+
+ selected_topic = selected_subsubgroup[:topics].detect { |topic| topic[:id] == args[:topic_id] }
+ breadcrumb_topic = linkify_breadcrumb(nil, selected_topic[:name], offset) if selected_topic
+ end
+
+
+ return breadcrumb_root, breadcrumb_group, breadcrumb_subgroup, breadcrumb_subsubgroup, breadcrumb_topic
end
- def linkify_breadcrumb(href, text, extra_level)
- addl_level = extra_level ? '../' : ''
+ def linkify_breadcrumb(href, text, offset)
+ addl_level = ''
+ if offset == 1
+ addl_level = '../'
+ end
+ if offset == 2
+ addl_level = '../../'
+ end
href ? "<a href=\"#{addl_level}#{href}\">#{text}</a>" : text
end
def asciidoctor_page_attrs(more_attrs=[])
[
@@ -300,11 +332,11 @@
exit
else
log_unknown("Building only the #{distro_map.get_distro(build_distro).name} distribution.")
end
elsif single_page.nil?
- log_unknown("Building every distribution.")
+ log_unknown("Building all distributions.")
end
# Notify the user of missing local branches
missing_branches = []
distro_map.distro_branches(build_distro).sort.each do |dbranch|
@@ -510,14 +542,28 @@
group_id = breadcrumb[0][:id]
topic_title = breadcrumb[-1][:name]
topic_id = breadcrumb[-1][:id]
subgroup_title = nil
subgroup_id = nil
+ subsubgroup_title = nil
+ subsubgroup_id = nil
if breadcrumb.length == 3
subgroup_title = breadcrumb[1][:name]
subgroup_id = breadcrumb[1][:id]
end
+
+ if breadcrumb.length == 4
+ topic_title = breadcrumb[-1][:name]
+ topic_id = breadcrumb[-1][:id]
+ subsubgroup_title = breadcrumb[-2][:name]
+ subsubgroup_id = breadcrumb[-2][:id]
+ subgroup_title = breadcrumb[-3][:name]
+ subgroup_id = breadcrumb[-3][:id]
+ group_title = breadcrumb[-4][:name]
+ group_id = breadcrumb[-4][:id]
+ end
+
dir_depth = '../' * topic.breadcrumb[-1][:id].split('::').length
dir_depth = '' if dir_depth.nil?
preview_path = topic.preview_path(distro.id,branch_config.dir)
topic_publish_url = topic.topic_publish_url(distro.site.url,branch_config.dir)
@@ -531,15 +577,17 @@
:topic_url => preview_path,
:topic_publish_url => topic_publish_url,
:version => branch_config.name,
:group_title => group_title,
:subgroup_title => subgroup_title,
+ :subsubgroup_title => subsubgroup_title,
:topic_title => topic_title,
:article_title => article_title,
:content => topic_html,
:navigation => navigation,
:group_id => group_id,
:subgroup_id => subgroup_id,
+ :subsubgroup_id => subsubgroup_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",