Skip to content

Instantly share code, notes, and snippets.

@TrevorBramble
Created March 2, 2013 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrevorBramble/5069017 to your computer and use it in GitHub Desktop.
Save TrevorBramble/5069017 to your computer and use it in GitHub Desktop.
auto-updating render of markdown file as html
#!/usr/bin/env ruby
exit 1, 'no markdown file specified' if ARGV[0].nil?
require 'bundler'
Bundler.setup
Bundler.require
configure do
set converter: ARGV.fetch(1, 'markdown-calibre')
set md_file: ARGV.fetch(0)
end
helpers do
def title
"#{File.basename(settings.md_file)} :: mddy"
end
def md_content
`#{settings.converter} #{settings.md_file}`
end
end
get '/' do
erb :index
end
get '/favicon.ico' do
status 418
end
__END__
@@ index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><%= title %></title>
<style>
body {
font-family: helvetica, Arial, "Lucida Grande", sans-serif;
background-color: rgb(215,215,215);
color: rgb(25,25,25);
}
</style>
</head>
<body>
<%= md_content %>
<script>
reload = function () { window.location.reload(true) }
// refresh every 10000 milliseconds
setInterval(reload, 5000);
</script>
</body>
</html>
@TrevorBramble
Copy link
Author

$ ./app.rb README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment