# Classes used by the GitHub server task # # Although we don't actually use this, without it: 'uninitialized constant GitHub' require 'github/markup' require 'html/pipeline' require 'html/pipeline/rouge_filter' require 'webrick' module Nox class GitHubRenderer < WEBrick::HTTPServlet::AbstractServlet def initialize config, filename @filename = filename @pipeline = HTML::Pipeline.new [ HTML::Pipeline::MarkdownFilter, HTML::Pipeline::RougeFilter ] end def do_GET req, rsp begin rsp.status = 200 rsp['Content-Type'] = 'text/html' styles = [] styles << %{ } styles << %{ } render = @pipeline.call File.read(@filename) rsp.body = <<-BODY #{styles.join('')}
#{render[:output]}
BODY rescue rsp.status = 400 rsp['Content-Type'] = 'text/plain' rsp.body = "HTML Pipeline failed: #{$!}" end end end class Styles < WEBrick::HTTPServlet::AbstractServlet def do_GET req, rsp begin rsp.status = 200 rsp['Content-Type'] = 'text/css' rsp.body = ['normalize', 'github'].map do |style| File.read(File.absolute_path("../../#{style}.css", File.dirname(__FILE__))) end.join("\n") end end end end