Adds AuthHandler which handles login requests
Uses githubs oauth api
Checks if code is included in request
if not, forward to github sign in
else, redirect to desired URL such as last visited
Session keeps track of current and previously visited paths.
This will be updated for session unless the new current is the
same as the old current.
Auth_handler will redirect to previous url only if their was a
previously visited page.  If not, it will redirect to home.
Fixed a problem with set function for session_ets, it needs to
check for 0 position of tuples rather than position 1.
Cleaned up some code.
Auth_handler has been made to support both login and logout.
On login, the session is updated with a is_loggedin value.
The base template is sent the is_loggedin value to change display accordingly.
Logout will delete the session and redirect user to the previous page,
if no previous page exists then they will be redirected to home.
Made sure that delete in session_ets returned as expected.
Includes the ability to post comments to gists while logged in.
Gist_handler is modified to support POSTs.
Gist_handler will direct to previous path after a comment POST.
Gist_client now has the ability to send comment POSTs to github.
The comment section of the page will hide the form whenever
the user is not logged in, but will provide a button for sign in.
Comment form provides a preview view to show what their input
looks like after being parsed for markdown.
Includes the following libraries and css files:
highlight.pack.js, marked.js, monokai_sublime.css
Allows for the creation of a gist once logged in.
Base template includes the form needed for creating a gist.
The option is given at log in, will pop up a bootstrap modal with
the form.
The form will take a title, teaser and blog content.
There is also an option to add a file, which creates a
file name input and content text area.
The post handler extracts the file and content data to be
sent to github for gist creation.
Made some corrections from last commit.
Fixed existing bugs with creating a new gist.
Added codemirror editor for files that are added to the gist.
The editor currently only displays syntax for javascript, this will
be changed in the next few commits.
Added a preview tab for the blog content when creating a gist.
The blog content file name is created with the title, spaces are replaced
with underscores and a .md is added to the end for markdown.
Changes allow for the editing of the logged in user's gists.
Currently will only allow you to change the title, teaser and blog content.
A modal pops out like the creation of a gist, but will populate those fields
with the existing content.
Currently everything is sent as an update to github.
A check should probably be made to see what has changed and to only
send those changes.
Username will need to be checked to not allow logged in users to see
an edit link on other's pages.
Changes the logged in session data to contain the username.
Authentication will query the authenticated user's information
if they are successfully logged in, this contains username.
This allows for content on user pages to only be shown to
the owning user.
Allows for the deletion of a user's gist from their gist page.
Once signed in the link to delete will appear on the gist page.
Deletion is a POST to our service under the /gistID/delete path.
May need a better way to handle deletions, the path may not
be the best practice.
Gist client sends a deletion to github to remove by gist_id.
The on request function will ignore setting previous paths
for any path that includes the binary "/s/".
[WIP] Add caching system for gists

* A generic key-value caching system called `Cacherl`.
* Each cache is a `gen_server` holding value. It can expire.
* Their `pid` is mapped with the key by an ETS store.
* Each gist is cached with the key `{username, gist_id}`.
* Had to remove pager temporarily to simplify data structure

@TODO:
* Add pagination back, with cache taken into account.
* Cache gist incrementally when a gist entry is opened.
Cache the user data too
Make sure that the gist client is alive or start a new one

The gist client can crash when it fails to make request to GitHub (due
to timeout, etc…). So the `on request` will check if the process in the
session is still alive. Otherwise, start a new one.
Using cache for getting a single gist

* Get the gist and store to cache
* Get the user and store to cache
* Abstract out a module to handle all common cache-related ops.
Fix the mismatch between data returned by GH and binding

* Cowboy's binding for `gist_id` is integer
* Gist's ID returned by GH is binary.
* Needed to convert to binary.
Lazy load gist's full data

When opening a gist page from the listing page, the gist's data were
cached, but not full data for the detail page to show. Therefore need
to check whether full data, and replace with full if not.
Cache comments

* Added Lager for logging
* Clean up unused variables
Cache rendered html from markdown

* Separate the rendering of gist content and comments.
* Each rendered html is cached with the key is the markdown itself.
* It's kinda hacky to take advantage of blockquote markdown style to
differentiate between comments, but we don't want to call render for
individual comment.
* Change the order of arguments in `GistsIO.Cache` to take advantage
of pipe in Elixir.
Fix issue with the key for comments' cache
First attempt of revisiting pagination with cache in place

This is really tricky, at least for me. GitHub supports pagination but
we need to cache them per page(?). And we only care about gists
with Markdown file, so how it takes into account of the page?

Implemented a function to continuously fetching GitHub and cache
for `page` requested * `@per_page` (set in `env`). The result is sliced
accordingly later on. However, still has not filtered for Markdown yet.