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
#initialize(git_repo_path) ⇒ Html
Returns a new instance of Html.
6 7 8 |
# File 'lib/nwiki/frontend/app/html.rb', line 6 def initialize git_repo_path @wiki = Nwiki::Core::Wiki.new git_repo_path end |
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 |
# File 'lib/nwiki/frontend/app/html.rb', line 23 def html page erb = ERB.new "<!DOCTYPE HTML>\n<html>\n<head>\n <title><%= page.title %> - <%= @wiki.title %></title>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <link rel=\"alternate\" type=\"application/atom+xml\" title=\"ATOM Feed\" href=\"/articles.xml\">\n <link rel=\"stylesheet\" href=\"//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css\">\n <link rel=\"stylesheet\" href=\"//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css\">\n</head>\n<body>\n <div class=\"container\">\n <div class=\"row\">\n<div class=\"col-md-8\"><h1><a href=\"/articles/\"><%= @wiki.title %></a></h1></div>\n<div class=\"col-md-4\"><h2 class=\"text-right\"><small><%= @wiki.subtitle %></small></h2></div>\n </div>\n <div class=\"row\">\n<div class=\"col-md-12\">\n <%= page.to_html %>\n</div>\n </div>\n </div>\n <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js\"></script>\n <script src=\"//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js\"></script>\n</body>\n</html>\n" erb.result(binding).force_encoding(page.encoding) end |