Comments (8)
Based on a quick look at the source, this should be fairly easy to implement. Not sure which direction James wants to take Hiccup, but something like this should do the trick:
(defn include-css
"Include a list of external stylesheet files."
[attr-map & styles]
(if (map? attr-map)
(for [style styles]
[:link (merge {:type "text/css", :href (to-uri style), :rel "stylesheet"}
attr-map)])
(apply include-css {} attr-map contents)))
Depending on how important performance is, this could also be implemented as a macro—a là xhtml
in the same namespace—for compile time resolution of the (if (map? attr-map))
"dispatch".
And for backwards compatibility, it might be a good idea to add support for the degenerate case of (include-css)
, i.e. a call with no arguments.
from hiccup.
Or just change defn
to defelem
, which automatically adds the optional attr-map.
from hiccup.
That wouldn't work since include-css
(and include-js
) can both return multiple elements. In this case the optional attributes would only be applied to the first of the returned elements.
from hiccup.
Ah, quite right. So something like defelem
but which works for a list of elements.
from hiccup.
In that case, the two main options seem to be:
- Change
include-css
andinclude-css
work as if they were created usingdefelem
- Change
defelem
to add the optionalattr-map
to all elements in case the function body returns a seq of elements - Create a separate
defelemseq
to deal with function bodies returning element sequences
Option 1 seems rather limited and option 3 contorted so my preference would be for option 2, but that does break backwards compatibility in one edge case:
(defelem titles [& titles]
(for [title titles]
[:h1 title]))
(titles {:class "main-headline"} "Latest news" "Yesterday")
;With current implementation
;=> ([:h1 {:class "main-headline"} "Latest news"]
; [:h1 "Yesterday"])
;With suggested implementation. Note attributes on second element.
;=> ([:h1 {:class "main-headline"} "Latest news"]
; [:h1 {:class "main-headline"} "Yesterday"])
I can take a stab at a patch if you think one of the above would work. (Speaking of which, would you mind taking a look at #68? 😉)
from hiccup.
I implemented this in the 2.0 branch. Page includes now use defelem and defelem applies attrs to seqs.
from hiccup.
Any idea when allowing {:media "screen"}
for include-css
will be released?
from hiccup.
Hiccup currently isn't that far up my priority list, I'm afraid. It might be a while until I get around to completing the 2.0 branch.
from hiccup.
Related Issues (20)
- Shouldn't this line call the html function in hiccup2.core? HOT 1
- Hi How to write hiccup code for observable embed code in Roam ? HOT 3
- Null pointer exception with `:class` attribute containing vector nil HOT 3
- Replace license.html with license.txt (for artifact scanners) HOT 9
- Passing nil query param values to to url-encode throws exception
- New version? HOT 15
- :script async HOT 1
- Clojerl support HOT 2
- Historical question: Why is hiccup called hiccup? HOT 2
- link to api docs in project description is broken HOT 3
- Please remove.
- Fragment equivalent for the back end. HOT 2
- *escape-strings?* HOT 1
- hiccup.core/h not backward-compatible HOT 1
- Getting RuntimeException: no such var util/raw-string HOT 2
- Parameters for iframe src attribute HOT 8
- clj-kondo exported config HOT 4
- void-tags might not be complete HOT 3
- "Method code too large!" when compiling the hiccup2.core/html macro HOT 1
- Exponential increase in generated code when there are multiple nested hiccup2.core/html calls HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hiccup.