Skip to content

Commit

Permalink
Merge branch 'my-update'
Browse files Browse the repository at this point in the history
  • Loading branch information
magomimmo committed Jan 10, 2013
2 parents e7c3967 + f983603 commit b82cbb8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 28 deletions.
11 changes: 4 additions & 7 deletions project.clj
@@ -1,9 +1,6 @@
(defproject enlive-tutorial "0.1.0"
:description "Enlive Tutorial"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[enlive "1.0.0-SNAPSHOT"]
[ring "0.2.5"]
[net.cgrand/moustache "1.0.0-SNAPSHOT"]]
:dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]
:source-path "src")
:dependencies [[org.clojure/clojure "1.4.0"]
[enlive "1.0.1"]
[ring "1.1.6"]
[net.cgrand/moustache "1.1.0"]])
2 changes: 1 addition & 1 deletion src/tutorial/scrape1.clj
@@ -1,7 +1,7 @@
(ns tutorial.scrape1
(:require [net.cgrand.enlive-html :as html]))

(def *base-url* "http://news.ycombinator.com/")
(def ^:dynamic *base-url* "http://news.ycombinator.com/")

(defn fetch-url [url]
(html/html-resource (java.net.URL. url)))
Expand Down
2 changes: 1 addition & 1 deletion src/tutorial/scrape2.clj
@@ -1,7 +1,7 @@
(ns tutorial.scrape2
(:require [net.cgrand.enlive-html :as html]))

(def *base-url* "http://news.ycombinator.com/")
(def ^:dynamic *base-url* "http://news.ycombinator.com/")

(defn fetch-url [url]
(html/html-resource (java.net.URL. url)))
Expand Down
17 changes: 8 additions & 9 deletions src/tutorial/scrape3.clj
@@ -1,24 +1,23 @@
(ns tutorial.scrape3
(:require [net.cgrand.enlive-html :as html])
(:use [clojure.contrib.seq-utils :only [indexed]]
[clojure.contrib.str-utils :only [re-sub re-gsub]]))
(:require [net.cgrand.enlive-html :as html]
[clojure.string :as str]))

(def *base-url* "http://nytimes.com/")
(def ^:dynamic *base-url* "http://nytimes.com/")

(def *story-selector*
(def ^:dynamic *story-selector*
[[:div.story
(html/but :.advertisement)
(html/but :.autosStory)
(html/but :.adCreative)]])

(def *headline-selector*
(def ^:dynamic *headline-selector*
#{[html/root :> :h2 :a],
[html/root :> :h3 :a]
[html/root :> :h5 :a]})

(def *byline-selector* [html/root :> :.byline])
(def ^:dynamic *byline-selector* [html/root :> :.byline])

(def *summary-selector* [html/root :> :.summary])
(def ^:dynamic *summary-selector* [html/root :> :.summary])

(defn fetch-url [url]
(html/html-resource (java.net.URL. url)))
Expand All @@ -31,7 +30,7 @@
byline (first (html/select [node] *byline-selector*))
summary (first (html/select [node] *summary-selector*))
result (map html/text [headline byline summary])]
(zipmap [:headline :byline :summary] (map #(re-gsub #"\n" "" %) result))))
(zipmap [:headline :byline :summary] (map #(str/replace % #"\n" "") result))))

(defn empty-story? [node]
(every? (fn [[k v]] (= v "")) node))
Expand Down
2 changes: 1 addition & 1 deletion src/tutorial/template1.clj
Expand Up @@ -20,4 +20,4 @@
[&] {:status 404
:body "Page Not Found"}))

(defonce *server* (run-server routes))
(defonce ^:dynamic *server* (run-server routes))
8 changes: 4 additions & 4 deletions src/tutorial/template2.clj
Expand Up @@ -10,7 +10,7 @@
;; Dummy Data
;; =============================================================================

(def *dummy-context*
(def ^:dynamic *dummy-context*
{:title "Enlive Template2 Tutorial"
:sections [{:title "Clojure"
:data [{:text "Macros"
Expand Down Expand Up @@ -41,7 +41,7 @@
;; =============================================================================

; we only want to select a model link
(def *link-sel* [[:.content (nth-of-type 1)] :> first-child])
(def ^:dynamic *link-sel* [[:.content (nth-of-type 1)] :> first-child])

(defsnippet link-model "tutorial/template2.html" *link-sel*
[{:keys [text href]}]
Expand All @@ -50,7 +50,7 @@
(set-attr :href href)))

; we only want to select the model h2 ul range
(def *section-sel* {[:.title] [[:.content (nth-of-type 1)]]})
(def ^:dynamic *section-sel* {[:.title] [[:.content (nth-of-type 1)]]})

(defsnippet section-model "tutorial/template2.html" *section-sel*
[{:keys [title data]} model]
Expand All @@ -71,4 +71,4 @@
;; The App
;; ========================================

(defonce *server* (run-server routes))
(defonce ^:dynamic *server* (run-server routes))
2 changes: 1 addition & 1 deletion src/tutorial/template3.clj
Expand Up @@ -71,4 +71,4 @@
;; The App
;; =============================================================================

(defonce *server* (run-server routes))
(defonce ^:dynamic *server* (run-server routes))
8 changes: 4 additions & 4 deletions src/tutorial/utils.clj
@@ -1,13 +1,13 @@
(ns tutorial.utils
(:require [net.cgrand.enlive-html :as html])
(:require [net.cgrand.enlive-html :as html]
[clojure.java.io :as io])
(:use [ring.adapter.jetty :only [run-jetty]]
[ring.util.response :only [response file-response]]
[ring.middleware.reload :only [wrap-reload]]
[ring.middleware.file :only [wrap-file]]
[ring.middleware.stacktrace :only [wrap-stacktrace]]
[clojure.contrib.duck-streams :only [pwd]]))
[ring.middleware.stacktrace :only [wrap-stacktrace]]))

(def *webdir* (str (pwd) "/src/tutorial/"))
(def ^:dynamic *webdir* (str (.getCanonicalFile (io/file ".")) "/src/tutorial/"))

(defn render [t]
(apply str t))
Expand Down

0 comments on commit b82cbb8

Please sign in to comment.