This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Initial commit.

  • Loading branch information...
technomancy committed Jan 16, 2012
0 parents commit 0e2114456e947581357ba8c43060085ee7409784
@@ -0,0 +1,7 @@
+pom.xml
+*jar
+/classes/
+/.lein-deps-sum
+/.lein-failures
+/checkouts
+/.env
@@ -0,0 +1 @@
+web: lein run -m lein-survey.web
@@ -0,0 +1,15 @@
+# lein-survey
+
+A simple survey for Leiningen users.
+
+## Usage
+
+To start a web server
+
+ $ PORT=5000 lein run -m lein-survey.web
+
+## License
+
+Copyright © 2012 Phil Hagelberg
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,8 @@
+(defproject lein-survey "1.0.0-SNAPSHOT"
+ :description "Survey for Leiningen users"
+ :dependencies [[clojure "1.3.0"]
+ [compojure "1.0.1"]
+ [org.clojure/java.jdbc "0.1.1"]
+ [postgresql "8.4-702.jdbc4"]
+ [hiccup "0.3.8"]
+ [ring/ring-jetty-adapter "0.3.9"]])
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Leiningen Survey</title>
+ <link rel="stylesheet" href="bootstrap.min.css">
+ </head>
+
+ <body>
+ <div class="container">
+ <div class="content">
+
+ <div class="page-header">
+ <h1>Leiningen Survey</h1>
+ </div>
+
+ <div class="row">
+ <div class="span10">
+ <p>Do you use Leiningen? We'd love it if you could take a few
+ minutes to answer some questions.</p>
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="span10 offset1">
+ <form action="/" method="post">
+ <p>When did you start using Leiningen?</p>
+ <ul class="inputs-list">
+ <li>
+ <label><input type="radio" name="start"
+ value="0.5"><span>0.5 (Nov 2009)</span></label>
+ </li>
+ </ul>
+
+
+ </form>
+ </div>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,23 @@
+html, body {
+ background-color: #eee;
+}
+body {
+ padding-top: 40px;
+}
+.content {
+ background-color: #fff;
+ padding: 20px;
+}
+.page-header {
+ background-color: #f5f5f5;
+ padding: 20px 20px 10px;
+ margin: -20px -20px 20px;
+}
+
+.form {
+ padding: 20px;
+}
+
+.float {
+ float: left;
+}
@@ -0,0 +1,74 @@
+(ns lein-survey.questions)
+
+(def questions [["When did you start using Leiningen?" :radio
+ ["0.5 (Nov 2009)"
+ "1.0 (Dec 2009)"
+ "1.1 (Feb 2010)"
+ "1.2 (Jul 2010)"
+ "1.3 (Aug 2010)"
+ "1.4 (Dec 2010)"
+ "1.5 (Mar 2011)"
+ "1.6 (Jun 2011)"
+ "2.0.0-SNAPSHOT"
+ "I don't remember"]]
+ ["How long have you been using Clojure?" :radio
+ ["Just started" "Weeks" "Months" "1 year" "2 years" "3+ years"]]
+ ["For what do you use Leiningen? (pick as many as apply)" :check
+ ["Open source" "Proprietary projects"
+ "Libraries" "Web sites"
+ "Backend code" "GUI clients" "Command-line applications"]]
+ ["Do you deploy jars?" :check
+ ["to Clojars" "to other public repositories"
+ "to private repositories"]]
+ ["Your OS and package manager" :check
+ ["Debian/Ubuntu"
+ "Fedora/other RPM-based"
+ "Arch" "Gentoo" "Nix"
+ "Other GNU/Linux"
+ "Mac OS X with Homebrew"
+ "Mac OS X with Macports"
+ "Mac OS X with Fink"
+ "Mac OS X other"
+ "Windows with Powershell"
+ "Windows without Powershell"
+ "Windows with Cygwin"
+ "Solaris"
+ "BSD"
+ "other"]]
+ ["How do you install Leiningen" :check
+ ["Downloading bin/lein"
+ "Package manager"
+ "Git"]]
+ [(str "Paste your stats for: history | grep \"lein \" | "
+ "awk '{print $3}' | sort | uniq -c | sort -nr | "
+ "egrep -v \"^ +1\"") :textarea]
+ ["Which Leiningen features do you use?" :check
+ ["Auto-cleaning of transitively-compiled .class files"
+ "Checkout dependencies"
+ "clean task"
+ "Custom options to :repositories"
+ "Editor integration"
+ "interactive task"
+ "javac task"
+ "lein-clojars plugin"
+ "Native dependencies"
+ "pom task (other than for pushing to Clojars)"
+ "repl task"
+ "Shell wrappers"
+ "Test selectors"
+ "trampoline task"]]
+ ["Favourite plugins?" :textarea]
+ ["Biggest problem/annoyance?" :rank
+ ["Startup time"
+ "Difficulty finding dependencies"
+ "Not enough plugins"
+ "Leiningen's own end-user docs"
+ "Docs on extending Leiningen or writing plugins"
+ "ClojureScript"]]
+ ["Do you have custom tasks you haven't published as a plugin?"
+ :radio
+ ["Yes" "No"]]
+ [(str "Did you know if you have a single patch accepted you can"
+ " ask for commit rights and a sticker?") :radio
+ ["Yes" "No"]]
+ ["Other comments?" :textarea]])
@@ -0,0 +1,66 @@
+(ns lein-survey.render
+ (:use [hiccup.page-helpers :only [html5 doctype include-css]]
+ [hiccup.form-helpers :only [form-to label text-field submit-button]]))
+
+(def input nil) ; dang it defonce semantics!
+(defmulti input second)
+
+(defmethod input :radio [[question _ answers]]
+ [:div
+ [:p question]
+ [:ul.inputs-list
+ (for [a answers]
+ [:li [:label [:input {:type "radio" :name question :value a}]
+ [:span a]]])]])
+
+(defmethod input :check [[question _ answers]]
+ [:div
+ [:p question]
+ [:ul.inputs-list
+ (for [a answers]
+ [:li [:label [:input {:type "checkbox" :name question :value a}]
+ [:span a]]])]])
+
+(defmethod input :rank [[question _ answers]]
+ [:div
+ [:p question]
+ [:ul.inputs-list
+ (for [a answers]
+ [:li [:span a]
+ [:ul.inputs-list
+ (for [n (reverse (range (count answers)))]
+ [:li.float [:label [:input {:type "radio" :name (str question "-" a)
+ :value n}]
+ [:span n]]])]])]])
+
+(defmethod input :textarea [[question _ rows]]
+ [:div [:p question] [:textarea.xxlarge {:rows (or rows 5) :name question}]])
+
+(defn questions-form [questions]
+ [:form {:method "POST" :action "/"}
+ (concat (map input questions)
+ [[:div.content [:input.btn.primary {:type "submit"
+ :value "Answer"}]]])])
+
+(defn layout [content]
+ (html5
+ [:head
+ [:meta {:charset "utf-8"}]
+ [:title "Leiningen Survey"]
+ (include-css "bootstrap.min.css"
+ "lein-survey.css"
+ "http://fonts.googleapis.com/css?family=Electrolize")]
+ [:body
+ [:div.container
+ [:div.content
+ [:div.page-header
+ [:h1 "Leiningen Survey"]]
+
+ [:div.row
+ [:div.span10
+ [:p (str "Do you use Leiningen? We'd love it if you could take a few"
+ "minutes to answer some questions.")]]]
+
+ [:div.row
+ [:div.span10.offset1
+ content]]]]]))
@@ -0,0 +1,41 @@
+(ns lein-survey.web
+ (:require [lein-survey.render :as render]
+ [lein-survey.questions :as q]
+ [compojure.core :as compojure]
+ [ring.adapter.jetty :as jetty]
+ [clojure.java.jdbc :as sql]
+ [ring.middleware.params :as params]
+ [ring.middleware.resource :as resource]
+ [compojure.route :as route]))
+
+(defn create-table []
+ (sql/with-connection (or (System/getenv "DATABASE_URL")
+ "postgres://localhost:5432/lein-survey")
+ (sql/create-table :answers
+ [:id :serial "PRIMARY KEY"]
+ [:body :varchar "NOT NULL"]
+ [:timestamp :timestamp "NOT NULL"
+ "DEFAULT CURRENT_TIMESTAMP"])))
+
+(defn record [params]
+ (sql/with-connection (or (System/getenv "DATABASE_URL")
+ "postgres://localhost:5432/lein-survey")
+ (sql/insert-values :answers [:body] [(pr-str params)]))
+ (render/layout [:h1 "Thank you!"]))
+
+(defn handler [req]
+ (if (= :post (:request-method req))
+ {:status 201
+ :headers {"Content-type" "text/html"}
+ :body (record (:params req))}
+ {:status 200
+ :headers {"Content-type" "text/html"}
+ :body (render/layout (render/questions-form q/questions))}))
+
+(def app (-> handler
+ params/wrap-params
+ (resource/wrap-resource "/public")))
+
+(defn -main []
+ (let [port (Integer. (or (System/getenv "PORT") 5000))]
+ (jetty/run-jetty #'app {:port port})))

0 comments on commit 0e21144

Please sign in to comment.