markdown/use_cases/Rakefile in markdown_helper-1.8.0 vs markdown/use_cases/Rakefile in markdown_helper-1.9.0

- old
+ new

@@ -1,56 +1,86 @@ +require_relative 'include/include_use_case' namespace :build do + def camelize(snake_case_string) + snake_case_string.split('_').collect(&:capitalize).join + end + desc 'Build use case markdown' task :use_cases do + # Page that links to use cases. File.open('use_cases.md', 'w') do |use_case_file| use_case_file.puts(<<EOT # Use Cases EOT ) dir_path = File.dirname(__FILE__) - use_case_file_paths = [] - tbs_file_paths = [] Dir.chdir(dir_path) do + IncludeUseCase.write_interface_file use_case_dirs = { :include => %w/ reuse_text include_with_added_comments + nest_inclusions + include_markdown + include_code_block + include_highlighted_code + include_generated_text + diagnose_missing_includee + diagnose_circular_includes /, - :resolve => %w/ - / + # :resolve => %w/ + # resize_images + # resolve_with_added_comments + # gemify_images + # / } use_case_dirs.each_pair do |section, dir_names| + + # Header for section, if any dirs therein. use_case_file.puts(<<EOT ## #{section.to_s.capitalize} EOT ) unless dir_names.empty? + + backtrace_cases = %w/ + diagnose_missing_includee + diagnose_circular_includes + / dir_names.each do |dir_name| - ruby_file_path = File.join( - dir_path, - section.to_s, - dir_name, - "#{dir_name}.rb" - ) - if File.exist?(ruby_file_path) - command = "ruby #{ruby_file_path}" - system(command) - end - use_case_file_path = File.join( - dir_path, - section.to_s, - dir_name, - "#{dir_name}.md" - ) - if File.exist?(use_case_file_path) + Dir.chdir("#{section}/#{dir_name}") do + # If the dir has a Ruby file, run it. + ruby_file_path = "#{dir_name}.rb" + if File.exist?(ruby_file_path) + class_name = camelize(dir_name) + command = "ruby -I . -r #{dir_name} -e #{class_name}.build" + if backtrace_cases.include?(dir_name) + command += " 2> #{dir_name}.err" + begin + system(command) + rescue + # + ensure + end + else + system(command) + end + end + + # If the dir has a use case file, link to it. + use_case_file_path = 'use_case.md' + unless File.exist?(use_case_file_path) + message = "File #{dir_name}/use_case.md does not exist" + warn(message) + next + end title_line = File.open(use_case_file_path).grep(/^#/).first.chomp title = title_line.split(/\s/, 2).pop use_case_file_name = File.basename(use_case_file_path) - use_case_name = File.basename(use_case_file_path, '.md') - use_case_anchor = use_case_name.gsub('_', '-') + use_case_anchor = dir_name.gsub('_', '-') use_case_relative_url = File.join( section.to_s, dir_name, use_case_file_name + '#' + use_case_anchor, )