Commits

Anonymous committed c20a504

Initial import of files from hangar project.

Comments (0)

Files changed (7)

neman/webapps/src/net/ksojat/neman/webapps/admin.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.admin
+  (:require
+    [net.ksojat.hangar.html :as html]
+    [net.ksojat.neman.web   :as web]
+    [net.ksojat.neman.css   :as css])
+  (:use
+    [net.ksojat.hangar.html :only [a-for shortcut-icon css-link]]
+    [net.ksojat.hangar.admin.style :only [style]]
+    (net.ksojat.neman
+      core
+      [css :only [to-css]]
+      [web :only [defview url-for]]
+      [xml :only [xml xml-node template template-from child render-str]])))
+
+;;
+;; Templates
+;;
+
+(def *nav* (ref []))
+
+(def base0
+  (template-from html/base
+    (:head
+      (=> :meta {:http-equiv "Content-Type" :content "text/html; charset=utf-8"})
+      (=> :title "Administration Panel")
+      (shortcut-icon "/media/favicon.png")
+      (child :head))
+    (:css
+      (css-link
+        "/media/admin/grid.css" (url-for :css))
+      (child :css))
+    (:body
+      (=> :div {:id "main"}
+        [(=> :div {:id "header" :class "fluid"}
+           [(=> :h1 "Administration Panel")])
+         (child :body)]))))
+
+(def default-base
+  (template-from base0
+    (:body
+       (=> :div {:id "nav" :class "fluid"}
+         [(html/nav @*nav*) (=> :div {:class "clear"})])
+       (=> :div {:class "mt1"} [(child :body)]))))
+
+(def base (ref #'default-base))
+
+(def login-template
+  (template-from base0
+    (:body [[error false]]
+      (=> :div.login
+        [(=> :form.mt5 {:method "post"}
+          [(=> :label {:for "username"} "Username")
+           (=> :input#username {:type "text" :name "username"})
+           (=> :label {:for "password"} "Password")
+           (=> :input#password {:type "password" :name "password"})
+           (=> :input {:type "submit" :value "Login"})
+           (if error
+             (=> :p.error "Invalid username or password."))])]))))
+
+;;
+;; Views
+;;
+
+(defview css [] ->
+  :get
+  [{"Content-Type" "text/css"}
+   (to-css (concat css/reset style))])
+
+(defview page-not-found []
+  "Not found!")
+
+(defview internal-server-error []
+  "Internal Sever Error!")
+
+(defview login [] ->
+  :get
+  [{"Content-Type" "text/html"}
+   (render-str login-template)]
+
+  :post
+  [{"Content-Type" "text/html"}
+   (render-str login-template {:error true})])
+
+;(defview login [] ->
+;  :session-user
+;  (redirect-to :index)
+
+;  :get
+;  [{"Content-Type" "text/html"}
+;   (render-str login-template)]
+
+;  :post
+;  (form [username, password]
+;    (if (not= username password)
+;      [{"Content-Type" "text/html"}
+;       (render-str login-template {:error true})]
+;      (do
+;        (set-session! :user username)
+;        (redirect-to :index)))))
+
+(defview logout []
+  "Logout screen")
+
+(def paths {
+  404 page-not-found
+  500 internal-server-error
+  :css    css
+  :login  login
+  :logout logout})

neman/webapps/src/net/ksojat/neman/webapps/admin/dashboard.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.admin.dashboard
+  (:require
+    [net.ksojat.hangar.admin :as admin])
+  (:use
+    (net.ksojat.neman
+      core
+      [xml :only [render-str]]
+      [web :only [defview]])))
+
+(defview index []
+  [:ok
+   {"Content-Type" "text/html"}
+   (render-str admin/default-base {})])

neman/webapps/src/net/ksojat/neman/webapps/admin/help.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.admin.help
+  (:refer-clojure :exclude [partial])
+  (:import (java.io File))
+  (:require
+    [net.ksojat.neman.textile :as textile]
+    (net.ksojat.hangar
+      [admin    :as admin]
+      [flatpage :as flatpage]))
+  (:use
+    (net.ksojat.hangar
+      [html     :only [a-for]]
+      [flatpage :only [textile-page]])
+    (net.ksojat.neman
+      core
+      [cells :only [cell]]
+      [xml   :only [xml-node render-str template-from child]]
+      [web   :only [defview call-view partial]])))
+
+;; Application names and base paths for there documentation.
+(def *catalog* (ref []))
+
+(def #^{:private true} catalog-map
+  (cell [*catalog*] [c]
+    (apply hash-map (apply concat c))))
+
+(defn toc-file-path [name]
+  (resource-as-file (str (@catalog-map name) "toc.textile")))
+
+(defn toc-file [name]
+  (when-let [path (toc-file-path name)] (File. path)))
+
+(defn help-file-path [name]
+  (resource-as-file (str (@catalog-map name) "help.textile")))
+
+(defn help-file [name]
+  (when-let [path (help-file-path name)] (File. path)))
+
+(defn help-dom [name]
+  (when-let [file (help-file name)]
+    (textile/textile-dom (textile/parse-textile-file file))))
+
+(defn toc-list []
+  (map
+    (fn [[name base]]
+      (let [title (textile/title (help-dom name))]
+        ; TODO: Fix this
+        (list
+          (xml-node (=> :dt [(a-for :app {'name name} title)]))
+          (xml-node (=> :dd "Some text will be inserted here.")))))
+    @*catalog*))
+
+(defn toc-sidebar []
+  (map
+    (fn [[name _]]
+      (let [title (textile/title (help-dom name))]
+        (xml-node (=> :li [(a-for :app {'name name} title)]))))
+    @*catalog*))
+
+;;
+;; Templates
+;;
+
+(def base
+   (template-from admin/default-base
+    (:body
+      (=> :div.toc.dl15
+        [(a-for :index "Table of Content")
+         (=> :ol [(toc-sidebar)])])
+      (=> :div.help.fluid.ml15 [(child :body)]))))
+
+(def toc-template
+  (template-from base
+    (:head
+      (=> :title "Help"))
+    (:body
+      (=> :dl [(toc-list)]))))
+
+(def help-template
+  (template-from base
+    (:head [name]
+      (=> :title [name]))
+    (:body [body]
+      (=> :div [body]))))
+
+;;
+;; Views
+;;
+
+; Show Table of Content.
+(defview index [] ->
+  :get
+  [{"Content-Type" "text/html"}
+    (render-str toc-template)])
+
+; Show help page for given app name.
+(defview app [name]
+  (when-let [doc (help-file name)]
+    (call-view textile-page {'file doc, 'template #'help-template})))
+
+(defview not-found [] ->
+  :get
+  "Help page was not found!")
+
+;;
+;; Default paths.
+;;
+
+(def paths {
+  404    not-found
+  :index index
+  :app   app})

neman/webapps/src/net/ksojat/neman/webapps/admin/overview.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.admin.overview
+  (:require
+    [net.ksojat.hangar.admin :as admin])
+  (:use
+    (net.ksojat.neman
+      [xml :only [render-str template-from]]
+      [web :only [defview]])))
+
+(defview overview [] ->
+  :get
+  [{"Content-Type" "text/html"}
+   (render-str
+     (template-from admin/default-base
+       (:body "hi")))])

neman/webapps/src/net/ksojat/neman/webapps/admin/style.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.admin.style)
+
+(def color1 "#1A1916")
+(def color2 "#C63D63")
+(def color3 "#902545")
+(def color4 "#F37D2C")
+(def color5 "#F3F3F1")
+(def color6 "#1D1A1A")
+(def color7 "#FDFDFC")
+(def color8 "#E33258")
+(def color9 "#D9EBE9")
+(def color10 "#CDDAD9")
+(def color11 "#A3C7CA")
+(def color12 "#789030")
+(def color13 "#D3E2E1")
+(def color14 "#215A6D")
+(def color15 "#F8F8F8")
+(def color16 "#36393D")
+(def color17 "#E8E8E8")
+
+(def style
+  [["body"
+    :font-family "Sans-Serif"]
+
+   ["#header"
+    :background-color color1
+    :padding-bottom   "7px"
+    :padding-top      "5px"]
+
+   ["#header h1"
+    :color        color2
+    :font-family  "Tahoma"
+    :font-size    "1.3em"
+    :padding-left "5px"
+    :margin       "0"
+    :display      :inline]
+
+   ["#header h1 span"
+    :color color3]
+
+   ["#header h2"
+    :color          :white
+    :font-family    "Arial Black"
+    :text-transform :uppercase]
+
+   ["#header p"
+    :color          color4
+    :font-family    "Verdana"
+    :font-size      "0.65em"
+    :padding-bottom "5px"
+    :margin         "0"
+    :display        :inline]
+
+   ["#nav"
+    :font-size        "0.8em"
+    :padding          "0 2px 5px 0"
+    :background-color color5]
+
+   ["#nav ul"
+    :margin-left "30px"]
+
+   ["#nav ul li"
+    :list-style     :none
+    :display        :inline
+    :text-transform :uppercase]
+
+   ["#nav ul li a"
+    :float           :left
+    :display         :block
+    :font            "bold 11px Arial"
+    :color           color6
+    :text-decoartion :none
+    :margin          "0 1px 0 0"
+    :padding         "5px 10px"
+    :background-color color5
+    :border-top       (str "1px solid " color5)]
+
+   ["#nav ul li a:hover"
+    :background-color color7]
+
+   ["#nav ul li.current a"
+    :color            color5
+    :border-color     color1
+    :background-color color1
+    :border           "0"
+    :border-radius-bottomleft  "0.3em"
+    :border-radius-bottomright "0.3em"]
+
+   ["#nav ul li.experiments a"
+    :color color8]
+
+   ["#nav ul li a img"
+    :margin-right "2px"]
+
+   ["#nav form.search"
+    :padding-top  "4px"
+    :float        :right
+    :margin-left  "3px"
+    :margin-right "3px"]
+
+   ["#nav form.search input[type='submit']"
+    :border "1px solid black"
+    :background-color :white]
+
+   ["#nav form.search input[type='text']"
+    :border "1px solid black"]
+
+   ["#browse-intro"
+    :font-family      "Verdana"
+    :font-size        "0.9em"
+    :padding          "5px 5px 5px 15px"
+    :background-color color9
+    :border-top       (str "1px solid " color10)
+    :border-bottom    (str "1px solid " color10)]
+
+   ["#browse-intro p"
+    :padding-right "60px"]
+
+   ["#browse-intro a"
+    :color color3]
+
+   ["#browse-intro img.close"
+    :position :relative
+    :float    :right]
+
+   [".paginator ul"
+    :padding-left "10px"]
+
+   [".paginator ul li"
+    :list-style  :none
+    :display     :inline
+    :font-family "Arial"
+    :font-weight :bold]
+
+   [".paginator ul li a"
+    :color :black]
+
+   [".paginator ul li.current a"
+    :color color8]
+
+   [".solvers table"
+    :border-spacing "10px"
+    :width          "100%"]
+
+   [".solver"
+    :margin        "0 10px 0 10px"
+    :padding       "6px 0 0 0"
+    :border-radius "0.2em"
+    :border-bottom (str "1px solid " color10)
+    :margin-bottom "5px"]
+
+   [".solver h1"
+    :font-weight :bold
+    :color       color6
+    :font-family "Arial"]
+
+   [".solver img"
+    :border (str "2px solid " color11)
+    :padding "1px"
+    :float   :left
+    :margin-right "5px"
+    :margin-left  "6px"]
+
+   [".solver ul li"
+    :list-style :none
+    :display    :inline]
+
+   [".solver p"
+    :font-size "0.7em"]
+
+   [".solver ul"
+    :clear :both
+    :border-radius-bottomleft "0.2em"
+    :border-radius-bottomright "0.2em"
+    :padding-left "5px"
+    :margin-top   "5px"]
+
+   [".solver ul li a"
+    :text-decoration :none
+    :color :black
+    :font-family "Sans-serif"
+    :font-size   "0.75em"]
+
+   [".progress"
+    :width  "100px"
+    :height "4px"
+    :background-color color10]
+
+   [".progress > div"
+    :width  "30px"
+    :height "4px"
+    :background-color color12]
+
+   ["#footer"
+    :text-align :center
+    :font-size  "0.8em"]
+
+   [".dim"
+    :z-index  "999"
+    :position :absolute
+    :background-color color6
+    :color :white
+    :top "0"
+    :left "0"
+    :opacity "0.7"]
+
+   [".client"
+    :z-index "1000"
+    :position :absolute
+    :background-color :white
+    :border (str "1px solid " color10)
+    :top "15px"
+    :left "15px"
+    :opacity "1.0"
+    :border-radius "0.2em"]
+
+   [".client h1"
+    :color color6
+    :font-family "Arial Black"
+    :padding-left "5px"
+    :background-color color13
+    :border-bottom (str "2px solid " color10)]
+
+   [".client a"
+    :float :right
+    :color color3
+    :font-size "0.8em"
+    :margin-top "2px"
+    :margin-right "10px"]
+
+   [".info"
+    :font-family "Arial"
+    :font-weight :bold
+    :font-size   "0.95em"
+    :color       color14]
+
+   [".error"
+    :font-family "Arial"
+    :font-weight :bold
+    :font-size   "0.95em"
+    :color       color8]
+
+   ["div.login"
+    :margin "0 auto"
+    :width  "20em"]
+
+   ["div.login form"
+    :float :left]
+
+   ["div.login form label"
+    :display :block
+    :font-family "Arial"]
+
+   ["div.login forn label:after"
+    :content ":"]
+
+   ["div.login form input[type='text']"
+    :width "100%"]
+
+   ["div.login form input[type='password']"
+    :width "100%"]
+
+   ["div.login form input[type='submit']"
+    :float :right
+    :margin-top "3px"]
+
+   ["div.login .error"
+    :clear :both
+    :padding-top "4px"]
+
+   ["div.toc"
+    :margin-right "10px"
+    :margin-left  "10px"
+    :background-color color15
+    :padding "10px 7px"
+    :border-radius "10px"]
+
+   ["div.toc > a"
+    :color color2]
+
+   ["div.toc ol"
+    :font-size "0.85em"
+    :font-family "Helvetica"
+    :padding-left "10px"
+    :padding-top  "5px"]
+
+   ["div.toc ol li"
+    :margin-left "1em"]
+
+   ["div.toc ol li a"
+    :color :black]
+
+   ["div.help"
+    :padding-left "35px"
+    :padding-right "30px"]
+
+   ["div.help dt"
+    :font-size "1.5em"
+    :font-family "Helvetica"]
+
+   ["div.help dt a"
+    :color color16]
+
+   ["div.help dd"
+    :border-bottom (str "1px solid " color17)]
+
+   ["div.help h1"
+    :color color16
+    :font-size "1.5em"
+    :font-family "Helvetica"]])

neman/webapps/src/net/ksojat/neman/webapps/flatpage.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.flatpage
+  (:use
+    (net.ksojat.neman
+      core
+      [textile :only [textile-dom parse-textile-file title body]]
+      [xml     :only [render-str template-from child]]
+      [web     :only [defview]])))
+
+(def flatpage
+  (template-from :flatpage
+    (:body [body] body)))
+
+(defview textile-page [file template] ->
+  :get
+  [{"Content-Type" "text/html"}
+   (render-str flatpage
+     {:body     (body (textile-dom (parse-textile-file file)))
+      :flatpage template})])

neman/webapps/src/net/ksojat/neman/webapps/html.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+
+(ns net.ksojat.hangar.html
+  (:import (org.jdom Namespace))
+  (:use
+    (net.ksojat.neman
+      core
+      [web :only [url-for url-for-path *current-path*]]
+      [xml :only [xml xml-node xml-nodes template child]])))
+
+(defn css-link [& href]
+  (map #(=> :link {:rel "stylesheet" :type "text/css" :href %}) href))
+
+(defn js-script [& src]
+  (map #(=> :script {:type "text/javascript" :src %}) src))
+
+(defn shortcut-icon
+  ([href]
+    (shortcut-icon href "image/png"))
+
+  ([href type]
+    (xml-nodes
+      (=> :link {:rel "icon"          :type type :href href})
+      (=> :link {:rel "shortcut icon" :type type :href href}))))
+
+(defn a-for
+  ([path title]
+    (a-for path {} title))
+
+  ([path args title]
+    (xml-node
+      (=> :a {:href (url-for path args)} [title]))))
+
+(defn a-for-path
+  ([path title]
+    (a-for-path {} title))
+
+  ([path args title]
+    (xml-node
+      (=> :a {:href (url-for-path path args)} [title]))))
+
+(def base
+  (template
+    (=> :html
+      [(=> :head [(child :head) (child :css)])
+       (=> :body [(child :body) (child :js)])])))
+
+;; TODO: Replace this
+(defn current-menu [n]
+  (first
+    (reduce (fn [[p1 n1] [p2 n2]] (if (> n2 n1) [p2 n2] [p1 n1]))
+      [nil -1]
+      (filter not-nil?
+        (map
+          (fn [path]
+            (let [[n m] (split-at (count path) *current-path*)]
+              (if (= n path) [path (count m)])))
+          (take-nth 2 n))))))
+
+(defn nav-link [current [link title]]
+  (xml-node
+    (=> :li {:class (if current "current")} [(=> :a {:href (link)} [title])])))
+
+(defn nav [n]
+  (let [current (current-menu n)]
+    (xml-node
+      (=> :ul
+        [(map
+           (fn [[path spec]]
+             (let [current? (= path current)]
+               (if (vector? spec) (nav-link current? spec) (spec current?))))
+           (partition 2 n))]))))
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.