Created
January 4, 2014 21:59
-
-
Save beakr/8261294 to your computer and use it in GitHub Desktop.
Simple Ruby code for parsing markdown in a directory (Github flavoured Markdown, that is).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run 'bundle' in the command line afterward | |
source 'https://rubygems.org' | |
gem 'guard' | |
gem 'guard-rake' | |
gem 'rake' | |
gem 'rainbow' | |
gem 'github-markdown' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard :rake, task: 'doc' do | |
watch(/docs\/formal\/(.+)\.md/) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'github/markdown' | |
module Dendrite | |
class Markdown | |
def self.generate | |
Dir.glob('docs/formal/*.md').each do |f| | |
file = File.open(f); | |
contents = '' | |
file.each { |line| contents << line } | |
parsed_markdown = GitHub::Markdown.render_gfm(contents) | |
new_file_name = f.gsub(/docs\/formal\//, '').gsub(/\.md/, '') + '.html' | |
new_file = "docs/output/#{new_file_name}" | |
File.open("./#{new_file}", 'w') { |html| html.write(parsed_markdown) } | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake' | |
require 'rainbow' | |
require './markdown.rb' | |
task :doc do | |
begin | |
Dendrite::Markdown.generate | |
puts Rainbow("Generated documentation.").green | |
rescue | |
puts Rainbow("Failed to generate documentation!").red | |
raise | |
end | |
end | |
namespace :doc do | |
task :clean do | |
Dir.glob('docs/output/*.html').each { |f| FileUtils.rm(f) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment