Class: Nox::GitHubRenderer
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Nox::GitHubRenderer
- Defined in:
- lib/nox/ghserver.rb
Instance Method Summary collapse
- #do_GET(req, rsp) ⇒ Object
-
#initialize(config, filename) ⇒ GitHubRenderer
constructor
A new instance of GitHubRenderer.
Constructor Details
#initialize(config, filename) ⇒ GitHubRenderer
Returns a new instance of GitHubRenderer.
13 14 15 16 17 18 19 |
# File 'lib/nox/ghserver.rb', line 13 def initialize config, filename @filename = filename @pipeline = HTML::Pipeline.new [ HTML::Pipeline::MarkdownFilter, HTML::Pipeline::RougeFilter ] end |
Instance Method Details
#do_GET(req, rsp) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nox/ghserver.rb', line 21 def do_GET req, rsp begin rsp.status = 200 rsp['Content-Type'] = 'text/html' styles = [] styles << %{<link crossorigin="anonymous" href="/style.css" media="all" rel="stylesheet"> } styles << %{ <style> body { padding: 25px 25px 25px 25px; } </style> } render = @pipeline.call File.read(@filename) rsp.body = <<-BODY <html> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <head>#{styles.join('')}</head> <body> <article class="markdown-body"> #{render[:output]} </article> </body> </html> BODY rescue rsp.status = 400 rsp['Content-Type'] = 'text/plain' rsp.body = "HTML Pipeline failed: #{$!}" end end |