enlive

Append to an attribute in Enlive

纵然是瞬间 提交于 2019-12-19 09:46:53
问题 Is it possible to append a value to an attribute using enlive? example: I have this <a href="/item/edit/">edit</a> and would like this <a href="/item/edit/123">edit</a> I am currently doing this: (html/defsnippet foo "views/foo.html" [:#main] [ctxt] [:a] (html/set-attr :href (str "/item/edit/" (ctxt :id)))) But I would prefer not to embed the URL into my code, by just appending the id to the existing URL (html/defsnippet foo "views/foo.html" [:#main] [ctxt] [:a@href] (html/append (ctxt :id)))

Clojure: enlive deftemplate can't use snippet

本秂侑毒 提交于 2019-12-13 02:57:50
问题 I'm trying to create template that produces table with some data in it. Data comes from a map defined in msh-contents. (require '[net.cgrand.enlive-html :as html]) (def msh-contents {:title "Events mashup", :data-content [{:title "ICTM Study Group ", :url "http://some-url.com"} {:title "Volodja Balzalorsky - Hinko Haas", :url "http://some- other-url.com"} ]}) ;; define snippets based on some divs in the template (html/defsnippet header-cell (template-div) [:div.Heading :div.Cell][value] (html

Rescraping data with Enlive

↘锁芯ラ 提交于 2019-12-12 18:25:23
问题 I tried to create function to scrape and tags from HTML page, whose URL I provide to a function, and this works as it should. I get sequence of <h3> and <table> elements, when I try to use select function to extract only table or h3 tags from resulting sequence, I get (), or if I try to map those tags I get (nil nil nil ...). Could you please help me to resolve this issue, or explain me what am I doing wrong? Here is the code: (ns Test2 (:require [net.cgrand.enlive-html :as html]) (:require

Enlive templating - Adding CSS includes to <head>

不打扰是莪最后的温柔 提交于 2019-12-08 06:23:46
问题 I'm not sure how I should be approaching this. I have a list of CSS files that I want to feed into something and get HTML back. For example, (list "base.css" "index.css" "more_css.css") ;vector might be more appropriate? should be transformed into: <link href="css/base.css" rel="stylesheet" /> <link href="css/index.css" rel="stylesheet" /> <link href="css/more_css.css" rel="stylesheet" /> From there it should be appended into <head> . defsnippet almost looks appropriate but takes a template

Range selectors in enlive

余生颓废 提交于 2019-12-08 02:29:43
问题 I'm trying to create a range selector, and can't seem to get off the ground. I'm trying things like: (sniptest "<div><p class='start'>Hi</p><p class='end'>There</p></div>" [{[:.start] [:.end]}] (content "Hello")) And that just returns the supplied html. I'd expect it to return a div with the body "Hello". How do I do this? EDIT Just to be more concise, this is what I've done with deftemplate and a real html file: HTML <html> <head> <title></title> </head> <body> <h1>Not hello</h1> <div class=

clojure, enlive, multi-site

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 12:09:03
问题 Trying to load a particular template based on what :server-name returns in the request: (ns rosay.views.common (:use noir.core) (:require [noir.request :as req] [clojure.string :as string] [net.cgrand.enlive-html :as html])) (defn get-server-name "Pulls servername for template definition" [] (or (:server-name (req/ring-request)) "localhost")) (defn get-template "Grabs template name for current server" [tmpl] (string/join "" (concat [(get-server-name) tmpl]))) (html/deftemplate base (get

Enlive templates – add to head section

半世苍凉 提交于 2019-12-05 04:11:33
问题 Some pages of my app will have it's own js/css includes, so I wonder how I can add these resources to the head section of an html document with Enlive. I found "append" transformer, but there is no "html-append" without auto escaping. Or what a proper way to do that? 回答1: The other answers might predate enlive hiccup-style helpers. Answer taken and expanded from: Enlive templating - Adding CSS includes to <head>. (require '[net.cgrand.enlive-html :as html]) Functions for generating HTML nodes

Enlive templates – add to head section

吃可爱长大的小学妹 提交于 2019-12-03 20:27:53
Some pages of my app will have it's own js/css includes, so I wonder how I can add these resources to the head section of an html document with Enlive. I found "append" transformer, but there is no "html-append" without auto escaping. Or what a proper way to do that? deadghost The other answers might predate enlive hiccup-style helpers. Answer taken and expanded from: Enlive templating - Adding CSS includes to <head> . (require '[net.cgrand.enlive-html :as html]) Functions for generating HTML nodes (much much MUCH simpler): (defn include-js [src] (first (html/html [:script {:src src}]))) (defn