Added _SUMMARY.md missing files checking

This commit is contained in:
kisenka 2015-04-29 01:44:09 +04:00
parent 5d4eeb24db
commit 3f4d5607b8
2 changed files with 41 additions and 0 deletions

26
_lib/summary_checker.rb Normal file
View File

@ -0,0 +1,26 @@
require 'rexml/xpath'
require_relative './utils.rb'
module Docs
class SummaryChecker
def self.check(path)
xml = Docs::Utils.md2xml(path)
dir = File.dirname(path)
is_ok = true
missing_files = []
xml.elements.each("//a") do |link|
href = link.attribute('href').to_s
path = "#{dir}/#{href.gsub(/\.html$/, '.md')}"
if !File.file?(path)
is_ok = false unless is_ok
missing_files.push href
break
end
end
missing_files
end
end
end

View File

@ -4,9 +4,24 @@ task :build_toc do
toc_file = ENV['dest'] || "#{src_dir}/HelpTOC.json"
load "#{src_dir}/_lib/toc_generator.rb"
load "#{src_dir}/_lib/summary_checker.rb"
kramdown_config = YAML::load_file("#{src_dir}/_config.yml")['kramdown']
toc = Docs::TocGenerator.extract("#{src_dir}/_SUMMARY.md", kramdown_config)
missing_files = Docs::SummaryChecker.check("#{src_dir}/_SUMMARY.md")
puts "Checking _SUMMARY.md\n"
if missing_files.size > 0
msg = ['Error, following files are missing:']
missing_files.each do |file|
msg.push "- #{file}"
end
raise (msg.join("\n"))
else
puts "_SUMMARY.md is OK"
end
res = File.write("#{toc_file}", toc.to_json)
puts "TOC successfully created in #{toc_file}" if res