├── .gitignore ├── README.md ├── project.clj ├── resources ├── Info.plist ├── config.clj └── icon.png ├── src └── clojuredocs_docset │ └── core.clj └── test └── clojuredocs_docset └── core_test.clj /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /lib 3 | /classes 4 | /checkouts 5 | pom.xml 6 | pom.xml.asc 7 | *.jar 8 | *.class 9 | .lein-deps-sum 10 | .lein-failures 11 | .lein-plugins 12 | .lein-repl-history 13 | docSet.dsidx 14 | clojure_core.html 15 | .DS_Store 16 | httrack.sh -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [Dash][dash] docset generator for [ClojureDocs.org][clojuredocs] 2 | 3 | Performs the following: 4 | 5 | * Mirror clojuredocs.org/clojure_core (around 17mb) using [HTTrack][httrack] 6 | * Copy html content to default dash docset template 7 | * Parse all functions from clojure_core.html 8 | * Populate searchIndex in docSet.dsidx (sqlite db) 9 | 10 | ## Installation 11 | 12 | Install the following dependencies: 13 | 14 | $ brew install httrack 15 | $ brew install leiningen 16 | 17 | ## Usage 18 | 19 | Download [uberjar][releases] and run: 20 | 21 | $ java -jar clojuredocs-docset--standalone.jar 22 | 23 | or clone source to customize [HTTrack][httrack] in config.clj and run: 24 | 25 | $ lein run 26 | 27 | Import the generated clojure-docs.docset into [Dash][dash]. 28 | 29 | ## License 30 | 31 | Copyright © 2013 Lokeshwaran 32 | 33 | Distributed under the Eclipse Public License, the same as Clojure. 34 | 35 | [clojuredocs]: http://clojuredocs.org 36 | [dash]: http://kapeli.com/dash 37 | [httrack]: http://www.httrack.com 38 | [releases]: https://github.com/dlokesh/clojuredocs-docset/releases 39 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject clojuredocs-docset "0.1.1" 2 | :description "Dash docset generator for ClojureDocs.org" 3 | :url "http://github.com/dlokesh/clojuredocs-docset" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :dependencies [[org.clojure/clojure "1.5.1"] 7 | [org.jsoup/jsoup "1.7.2"] 8 | [org.clojure/java.jdbc "0.3.0-alpha4"] 9 | [org.xerial/sqlite-jdbc "3.7.2"] 10 | [commons-io "2.4"]] 11 | :profiles {:dev {:dependencies [[midje "1.5.1"]]}} 12 | :plugins [[lein-midje "3.0.0"]] 13 | :main clojuredocs-docset.core) 14 | -------------------------------------------------------------------------------- /resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | ClojureDocs.org 7 | CFBundleName 8 | ClojureDocs.org 9 | DocSetPlatformFamily 10 | clj 11 | isDashDocset 12 | 13 | dashIndexFilePath 14 | clojuredocs.org/index.html 15 | isJavaScriptEnabled 16 | 17 | 18 | -------------------------------------------------------------------------------- /resources/config.clj: -------------------------------------------------------------------------------- 1 | { 2 | :db-file-path "clojure-docs.docset/Contents/Resources/docSet.dsidx", 3 | :index-html-path "clojure-docs.docset/Contents/Resources/Documents/clojuredocs.org/clojure_core.html", 4 | :httrack ["httrack" "http://clojuredocs.org/clojure_core" "-n" "--path" "httrack-clojuredocs.org"], 5 | :docset-template "clojure-docs.docset/Contents/Resources/Documents", 6 | :httrack-clojuredocs "httrack-clojuredocs.org/clojuredocs.org" 7 | } -------------------------------------------------------------------------------- /resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dlokesh/clojuredocs-docset/fced360868b9b53f8246e3e9eb4a133451f6bc01/resources/icon.png -------------------------------------------------------------------------------- /src/clojuredocs_docset/core.clj: -------------------------------------------------------------------------------- 1 | (ns clojuredocs-docset.core 2 | (:require [clojure.java.jdbc :as j] 3 | [clojure.java.jdbc.sql :as sql]) 4 | (:use [clojure.java.shell :only [sh]] 5 | [clojure.java.io :only [file resource]]) 6 | (:import [org.jsoup Jsoup] 7 | [org.apache.commons.io FileUtils]) 8 | (:gen-class)) 9 | 10 | (def user-dir (System/getProperty "user.dir")) 11 | (def conf (read-string (slurp (resource "config.clj")))) 12 | 13 | (defn file-ref [file-name] 14 | (file user-dir file-name)) 15 | 16 | (defn resource-copy [src dest] 17 | (FileUtils/copyURLToFile (resource src) (file-ref dest))) 18 | 19 | (def sqlite-db {:classname "org.sqlite.JDBC" 20 | :subprotocol "sqlite" 21 | :subname (:db-file-path conf)}) 22 | 23 | (defn print-progress [percent text] 24 | (let [x (int (/ percent 2)) 25 | y (- 50 x)] 26 | (print "\r" (apply str (repeat 100 " ")));clear existing text 27 | (print "\r" "[" 28 | (apply str (concat (repeat x "=") [">"] (repeat y " "))) 29 | (str "] " percent "%") text) 30 | (when (= 100 percent) (println)) 31 | (flush))) 32 | 33 | (defn mirror-clojuredocs [] 34 | (print-progress 15 "Mirroring clojuredocs.org/clojure_core") 35 | (apply sh (:httrack conf))) 36 | 37 | (defn create-docset-template [] 38 | (print-progress 40 "Creating docset template") 39 | (.mkdirs (file-ref (:docset-template conf))) 40 | (resource-copy "icon.png" "clojure-docs.docset/icon.png") 41 | (resource-copy "Info.plist" "clojure-docs.docset/Contents/Info.plist")) 42 | 43 | (defn copy-html-to-docset [] 44 | (print-progress 50 "Copying clojuredocs.org to docset") 45 | (FileUtils/copyDirectoryToDirectory (file-ref (:httrack-clojuredocs conf)) (file-ref (:docset-template conf)))) 46 | 47 | (defn clear-search-index [] 48 | (print-progress 60 "Clearing index") 49 | (j/with-connection sqlite-db 50 | (j/do-commands "DROP TABLE IF EXISTS searchIndex" 51 | "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)" 52 | "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path)"))) 53 | 54 | (defn populate-search-index [rows] 55 | (j/with-connection sqlite-db 56 | (apply j/insert-records :searchIndex rows))) 57 | 58 | (defn search-index-attributes [element] 59 | {:name (.text element) 60 | :type "Function" 61 | :path (str "clojuredocs.org/" (.attr element "href"))}) 62 | 63 | (defn generate-search-index [] 64 | (print-progress 75 "Generating index") 65 | (let [html-content (slurp (str user-dir "/" (:index-html-path conf))) 66 | document (Jsoup/parse html-content) 67 | rows (map search-index-attributes (.select document ".function a"))] 68 | (populate-search-index rows))) 69 | 70 | (defn generate-docset [] 71 | (mirror-clojuredocs) 72 | (create-docset-template) 73 | (copy-html-to-docset) 74 | (clear-search-index) 75 | (generate-search-index) 76 | (print-progress 100 "Done.")) 77 | 78 | (defn -main 79 | [& args] 80 | ;; work around dangerous default behaviour in Clojure 81 | (alter-var-root #'*read-eval* (constantly false)) 82 | (generate-docset) 83 | (shutdown-agents)) 84 | -------------------------------------------------------------------------------- /test/clojuredocs_docset/core_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojuredocs-docset.core-test 2 | (:use midje.sweet) 3 | (:require [clojure.test :refer :all] 4 | [clojure.java.jdbc :as j] 5 | [clojuredocs-docset.core :refer :all]) 6 | (:import [org.jsoup.nodes Element Attributes Attribute] 7 | [org.jsoup.parser Tag])) 8 | 9 | (facts "about search index" 10 | (fact "it should construct search index attributes" 11 | (let [tag (Tag/valueOf "a") 12 | attributes (Attributes.) 13 | _ (.put attributes "href" "clojure_core/clojure.html") 14 | element (Element. tag "uri" attributes) 15 | _ (.text element "core")] 16 | (search-index-attributes element) => {:name "core" :type "Function" :path "clojuredocs.org/clojure_core/clojure.html"}))) --------------------------------------------------------------------------------