Permalink
Browse files

pimp out home & search UI

  • Loading branch information...
1 parent fac0792 commit b3de82f1d168be813cf1ba6e959755588eea2485 @mislav committed May 13, 2012
Showing with 108 additions and 38 deletions.
  1. +41 −3 app.rb
  2. +1 −1 bootstrap
  3. +20 −23 views/index.erb
  4. +10 −4 views/layout.erb
  5. +25 −5 views/search.erb
  6. +11 −2 views/style.sass
View
@@ -39,16 +39,54 @@
require_relative 'models'
+helpers do
+ def display_document_id doc_id
+ doc_id = doc_id.document_id if doc_id.respond_to? :document_id
+ doc_id.sub(/(\d+)/, ' \1')
+ end
+
+ def display_abstract text
+ text.sub(/\[STANDARDS[ -]{1,2}TRA?CK\]/, '') if text
+ end
+
+ def search_path options = {}
+ get_params = request.GET.merge('page' => options[:page])
+ url '/search?' + Rack::Utils.build_query(get_params), false
+ end
+
+ def rfc_path doc_id
+ doc_id = doc_id.document_id if doc_id.respond_to? :document_id
+ url doc_id, false
+ end
+
+ def home_path
+ url '/'
+ end
+
+ def page_title title = nil
+ if title
+ @page_title = title
+ else
+ @page_title
+ end
+ end
+end
+
+before do
+ page_title "Pretty RFCs"
+end
+
get "/" do
cache_control :public
last_modified File.mtime('views/index.erb')
- erb :index, {}, title: "Pretty RFCs"
+ erb :index
end
get "/search" do
@query = params[:q]
- @results = RfcEntry.search_raw @query, page: params[:page], limit: 50
- erb :search, {}, title: "RFC search"
+ @limit = 50
+ @results = RfcEntry.search_raw @query, page: params[:page], limit: @limit
+ erb :search
end
get "/oauth" do
View
@@ -1,30 +1,27 @@
<div id=home class=container>
- <h1>The RFC is now <em>diamonds</em></h1>
+ <div class=hero-unit>
+ <h1>The RFC is now <em>diamonds</em></h1>
+ <p>
+ <abbr title="Request For Comments" class=initialism>RFC</abbr>s are
+ documents produced by
+ <a href="http://www.ietf.org">The Internet Enginnering Task Force</a>,
+ and many are official standards for various Internet protocols.
+ This site indexes and formats these documents for easier finding &amp; viewing.
+ </p>
- <form action=/search>
- <input type=search name=q placeholder="Search RFC titles">
- <input type=submit value="Search">
- </form>
-
- <div class=well>
- <p>
- Sample RFC: <a href=/oauth>OAuth 2.0</a>
- </p>
-
- <p>Sample PDF for RFC: <a href="https://s3.amazonaws.com/mislav/oauth.pdf">oauth.pdf</a></p>
+ <form action=/search class=form-search>
+ <input type=search class=search-query name=q placeholder="Search RFCs">
+ <input type=submit value="Search" class=btn>
+ </form>
</div>
- <p>More to come:</p>
- <ul>
- <li>Intro about what RFCs are</li>
- <li>Search for RFCs</li>
- <li>Search by content</li>
- <li>EPUB and Kindle versions</li>
- </ul>
+ <p>Coming next: PDF, EPUB &amp; Kindle formats</p>
- <footer><p>
- By <a href="http://mislav.uniqpath.com">Mislav</a> ·
- <a href="https://github.com/mislav/rfc">Code on GitHub</a>.
- </p></footer>
+ <footer>
+ <p>
+ By <a href="http://mislav.uniqpath.com">Mislav</a> ·
+ <a href="https://github.com/mislav/rfc">Source code on GitHub</a>.
+ </p>
+ </footer>
</div>
View
@@ -1,6 +1,12 @@
<!doctype html>
-<title><%= title %></title>
-<%#= javascript_includes %>
-<link rel=stylesheet type="text/css" href=style.css>
+<html>
+<head>
+ <title><%= page_title %></title>
+ <%#= javascript_includes %>
+ <link rel=stylesheet type="text/css" href=/style.css>
+</head>
-<%= yield %>
+<body>
+ <%= yield %>
+</body>
+</html>
View
@@ -1,17 +1,37 @@
-<div class=container>
+<% page_title "RFC search: %s" % @query.inspect %>
+<div id=search class=container>
- <h1>Search for <%= @query.inspect %></h1>
+
+ <div class=page-header>
+ <nav><a href="<%= home_path %>">&larr; Home</a></nav>
+ <h1>Search results for <%= @query.inspect %></h1>
+ </div>
+
+ <form action=/search class=form-search>
+ <input type=search class=search-query name=q placeholder="Search RFCs" value="<%= @query %>">
+ <input type=submit value="Search" class=btn>
+ </form>
<% if @results.any? %>
<ol>
<% for rfc in @results %>
- <li>
- <h2><%= rfc.document_id %>: <%= rfc.title %></h2>
- <%= rfc.abstract %>
+ <li<%= ' class=obsoleted' if rfc.obsoleted %>>
+ <span class=document-id><%= display_document_id rfc %></span>
+ <% if rfc.obsoleted %><span class="label label-warning">obsolete</span><% end %>
+ <h2><a href="<%= rfc_path rfc %>"><%= rfc.title %></a></h2>
+ <%= rfc.abstract.try(:sub, /\[STANDARDS[ -]{1,2}TRA?CK\]/, '') %>
</li>
<% end %>
</ol>
+ <% if @limit == @results.size %>
+ <ul class=pager>
+ <li class=next>
+ <a rel=next href="<%= search_path(:page => Integer(params[:page] || 1) + 1) %>">Next page &rarr;</a>
+ </li>
+ </ul>
+ <% end %>
+
<% else %>
<p>No results.</p>
<% end %>
View
@@ -13,8 +13,17 @@ $sidebarWidth: 230px
h1 em
font-style: normal
text-transform: uppercase
- color: crimson
- font-size: 120%
+ color: $pink
+ text-shadow: rgba($pink, .7) 0 0 5px
+
+ .initialism
+ font-weight: bold
+ border-bottom-color: $grayLight
+
+#search
+ h2
+ font-size: 16px
+ line-height: 1.1
figure, div.figure
page-break-inside: avoid

0 comments on commit b3de82f

Please sign in to comment.