Class: Nwiki::Frontend::Html
- Inherits:
-
Object
- Object
- Nwiki::Frontend::Html
- Defined in:
- lib/nwiki/frontend/app/html.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #html(page) ⇒ Object
-
#initialize(git_repo_path) ⇒ Html
constructor
A new instance of Html.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/nwiki/frontend/app/html.rb', line 10 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 |
#html(page) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nwiki/frontend/app/html.rb', line 23 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 |