Last active
December 18, 2015 00:49
-
-
Save jedschneider/5699700 to your computer and use it in GitHub Desktop.
This file contains 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
class Page | |
require 'uri' | |
require 'json' | |
require 'net/http' | |
require 'net/https' | |
def initialize(name, markup, css) | |
@name = name | |
@markup = markup | |
@css = css | |
end | |
def render | |
data = { | |
text: @markup, | |
mode: 'markdown' | |
} | |
uri = URI('https://api.github.com/markdown') | |
https = Net::HTTP.new(uri.host, uri.port) | |
https.use_ssl = true | |
response = https.post(uri.path, data.to_json) | |
stamp(response.body) | |
end | |
def stamp(html) | |
""" | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>#{@name}</title> | |
<style> | |
#{@css} | |
</style> | |
</head> | |
<body> | |
<div class='wikistyle'> | |
#{html} | |
</div> | |
</body> | |
</html> | |
""" | |
end | |
end | |
# example use case | |
# css from https://github.com/jasonm23/markdown-css-themes | |
css = File.read('avenir-white.css') | |
Dir.glob("myfiles/**/*.md") do |file| | |
garbage, path, name = *file.match(/^(.*)\/(.*)\.md$/) | |
page = Page.new(name, File.read(file), css) | |
open("#{path}/#{name}.html", "w+") do |f| | |
f.write page.render | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment