Skip to content

Commit

Permalink
Move API page to mustache.
Browse files Browse the repository at this point in the history
This is the last thing that needed to be moved. Closes Raynes#55.
  • Loading branch information
Raynes committed Feb 19, 2012
1 parent 5eb40e7 commit 57d2b4d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
30 changes: 8 additions & 22 deletions src/refheap/views/api.clj
@@ -1,34 +1,20 @@
(ns refheap.views.api
(:use [noir.core :only [defpage]]
[refheap.views.common :only [layout]]
[hiccup.page-helpers :only [link-to]])
[refheap.views.common :only [layout]])
(:require [noir.session :as session]
[stencil.core :as stencil]
[refheap.models.api :as api]
[refheap.models.paste :as paste]
[refheap.models.users :as users]))

(defn api-page []
(layout
[:div.written
[:p
"RefHeap has a simple API for accessing and creating pastes. You can use this API without an "
"account with RefHeap. However, if you want pastes that you create to be created under your "
"account, you'll need to supply your username and an API token with the request. "
"You want to keep this API token a secret. However, if you accidentally push it to Github "
"or it is otherwise compromised, you can generate a new one at anytime. When you generate a new "
"token, the old one no longer works."]
[:p
"Check out the API documentation on "
(link-to "https://github.com/Raynes/refheap/wiki/Documentation:-API" "Github")
"!"]
(if-let [id (:id (session/get :user))]
[:div#token
[:code#tokentext (api/get-token id)]
[:button#gentoken {:type "button"} "Generate New Token"]]
[:p "Login to see your API token."])]))
(stencil/render-file
"refheap/views/templates/api"
{:logged (when-let [id (:id (session/get :user))]
{:token (api/get-token id)})}))

(defpage "/api" []
(api-page))
(layout (api-page)))

(defpage "/token/generate" []
(when-let [id (:id (session/get :user))]
Expand Down Expand Up @@ -94,4 +80,4 @@
(defpage "/api/paste/:id" {:keys [id]}
(if-let [paste (paste/get-paste id)]
(api/response :ok (api/process-paste paste))
(api/response :not-found "Paste does not exist.")))
(api/response :not-found "Paste does not exist.")))
4 changes: 1 addition & 3 deletions src/refheap/views/common.clj
Expand Up @@ -2,8 +2,6 @@
(:use [clavatar.core :only [gravatar]])
(:require [noir.session :as session]
[stencil.core :as stencil]
[hiccup.core :as hiccup]
[hiccup.page-helpers :as ph]
[refheap.models.paste :as paste]))

(defn avatar [email size]
Expand All @@ -21,7 +19,7 @@
(stencil/render-file
"refheap/views/templates/common"
{:user (logged-in nil)
:content (hiccup/html body)}))
:content body}))

(def header nil)

Expand Down
3 changes: 1 addition & 2 deletions src/refheap/views/login.clj
@@ -1,6 +1,5 @@
(ns refheap.views.login
(:use [hiccup.form-helpers :only [text-field submit-button form-to]]
[refheap.views.common :only [layout logged-in]]
(:use [refheap.views.common :only [layout logged-in]]
[noir.core :only [defpage]]
[noir.response :only [redirect json]])
(:require [refheap.models.login :as login]
Expand Down
22 changes: 22 additions & 0 deletions src/refheap/views/templates/api.mustache
@@ -0,0 +1,22 @@
<div class="written">
<p>
RefHeap has a simple API for accessing and creating pastes. You can use this API without an
account with RefHeap. However, if you want pastes that you create to be created under your
account, you'll need to supply your username and an API token with the request.
You want to keep this API token a secret. However, if you accidentally push it to Github
or it is otherwise compromised, you can generate a new one at anytime. When you generate a new
token, the old one no longer works.
</p>
<p>
Check out the API documentation on <a href="https://github.com/Raynes/refheap/wiki/Documentation:-API">Github</a>!
</p>
{{#logged}}
<div id="token">
<code id="tokentext">{{token}}</code>
<button id="gentoken" type="button">Generate New Token</button>
</div>
{{/logged}}
{{^logged}}
<p>Login to see your API token.</p>
{{/logged}}
</div>

0 comments on commit 57d2b4d

Please sign in to comment.