Sha256: 6e35d8d33bfc161033f8759d419df9ad7a992821701f8caa15f92b6d911239f6

Contents?: true

Size: 2 KB

Versions: 15

Compression:

Stored size: 2 KB

Contents

require 'erb'

module Nwiki
  module Frontend
    class Html
      def initialize git_repo_path
        @wiki = Nwiki::Core::Wiki.new git_repo_path
      end

      def call env
        path_info = env["PATH_INFO"]
        page = @wiki.find path_info
        case page
        when Core::Page, Core::Directory
          [200, {"Content-Type" => "text/html; charset=#{page.encoding}"}, [html(page)]]
        when Core::File
          [200, {"Content-Type" => page.content_type}, [page.data]]
        else
          [404, {"Content-Type" => "text/plain"}, ["not found."]]
        end
      end

      def html page
        page_title = page.title.empty? ? '' : "#{page.title} - "
        erb = ERB.new <<EOS
<!DOCTYPE HTML>
<html>
<head>
  <title><%= page_title %><%= @wiki.title %></title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="alternate" type="application/atom+xml" title="ATOM Feed" href="/articles.xml">
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
</head>
<body>
  <a href="https://github.com/niku/nikulog">
    <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub">
  </a>
  <div class="container">
    <div class="row">
      <div class="col-md-12"><h1><a href="/articles/"><%= @wiki.title %></a></h1></div>
    </div>
    <div class="row">
      <div class="col-md-12"><h2"><small><%= @wiki.subtitle %></small></h2></div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <%= page.to_html %>
      </div>
    </div>
  </div>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>
EOS
        erb.result(binding).force_encoding(page.encoding)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nwiki-0.3.3 lib/nwiki/frontend/app/html.rb
nwiki-0.3.2 lib/nwiki/frontend/app/html.rb
nwiki-0.3.1 lib/nwiki/frontend/app/html.rb
nwiki-0.3.0 lib/nwiki/frontend/app/html.rb
nwiki-0.2.11 lib/nwiki/frontend/app/html.rb
nwiki-0.2.10 lib/nwiki/frontend/app/html.rb
nwiki-0.2.9 lib/nwiki/frontend/app/html.rb
nwiki-0.2.8 lib/nwiki/frontend/app/html.rb
nwiki-0.2.7 lib/nwiki/frontend/app/html.rb
nwiki-0.2.6 lib/nwiki/frontend/app/html.rb
nwiki-0.2.5 lib/nwiki/frontend/app/html.rb
nwiki-0.2.4 lib/nwiki/frontend/app/html.rb
nwiki-0.2.3 lib/nwiki/frontend/app/html.rb
nwiki-0.2.2 lib/nwiki/frontend/app/html.rb
nwiki-0.2.1 lib/nwiki/frontend/app/html.rb