问题标签 [enlive]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
131 浏览

clojure - How can I reduce the duplication in the Clojure code below?

I have the following Clojure code with a render function which renders a html page using enlive-html. Depending on the selected language a different html template is used.

As you can see, there is a lot of code duplication and I would like to remove it.

I was thinking of writing some macros but, if I understand correctly, the language (i.e. lang parameter) is not available at macro execution time because it is provided in the request and that is at execution time and not at compilation time.

I also tried to modify enlive in order to add i18n support at some later point but my Clojure skills are not there yet.

So the questions are:

How can I remove the code duplication in the code below?

Is enlive-html the way to go or should I use another library? Is there a library similar to enlive with support for i18n?

Thanks!

See the code here:

0 投票
1 回答
85 浏览

clojure - 如何重新加载直播模板?

我有一个使用 enlive 的 Web 应用程序。

如果我更改模板使用的 html 文件,除非我重新启动 figwheel,否则我看不到更改。

我正在使用 ring.middleware.reload/wrap-reload 像这样:

...但没有任何影响。

请注意,如果我更改任何 .clj 或 .cljs 文件,我不必重新启动服务器。

0 投票
1 回答
82 浏览

clojure - Clojure,Enlive:使用多步选择器时如何使用否定?

我正在为 Clojure 使用 Enlive。我正在尝试在特定的 div 标记中的 li 标记中获取具有类“标题”的跨度标记。

但是,我想在类名为“dummy”的 li 标签中排除 span 标签。下面的代码按预期工作:

问题是如何通过一个选择调用来完成这项工作。我无法在多个步骤中使用“但是”否定,最终使用嵌套的 2 个选择调用。

任何人都可以将它们放入一个单一的选择表达式中吗?

0 投票
0 回答
42 浏览

if-statement - 有条件地显示内容或不在 deftemplate 宏内(Clojure - Enlive)

到目前为止,我已经设法弄清楚如何使用 clone-for 复制一个 div,但是我还没有找到一个在 deftemplate 宏内部有条件地应用转换的函数。

返回

我想知道是否有更有经验的人可以提供帮助?我不确定以下应该写成什么。

编辑:在艾伦的建议下,我在下面评论并删除了与我的问题无关的代码。

0 投票
3 回答
237 浏览

html - 将 html 结构转换为 Clojure 结构

我有一个 html 页面,其中有一个结构,我想将其转换为 Clojure 数据结构。我在如何以惯用的方式处理这个问题上遇到了一个心理障碍

这是我的结构:

我想要的结构:

标题的重复是故意的。

我读过David Nolan 的直播教程。如果组和子组之间存在奇偶性,这提供了一个很好的解决方案,但在这种情况下它可以是随机的。

感谢您的任何建议。

0 投票
2 回答
540 浏览

python - 像在 Beautifulsoup 中一样在 Enlive 中解析 HTML

我正在尝试使用 Enlive 从 Clojure 中的 HTML 获取链接。我可以从一个页面获取所有链接的列表吗?我可以遍历它们吗?

或者

如何在 Clojure 中使用 Enlive 执行此操作?

0 投票
1 回答
39 浏览

clojure - 在enlive中对模板进行多次传递的最佳方法是什么

我想获取一个获取的 html 页面并从中创建一个活动模板

我的两个交换 fns 看起来像这样

所以困境是我可以从获取返回管道中注释掉这两个交换中的任何一个,它工作正常。尝试(以任何一种顺序)都会失败。我相信应用模板的结果是错误的格式,无法从中制作另一个模板,但无法完全到达我需要的位置。

我链接它们时得到的错误是HTML resource not found.

编辑为使用更多填写的代码并删除 comp

更新我从https://stackoverflow.com/a/38284236/736368 复制了一个函数,以使字符串成为阅读器。这似乎让这个工作。从性能的角度来看,这似乎是一种好方法吗?

0 投票
1 回答
70 浏览

json - 如何在 Clojure 中将 Enlive 对象转换为 JSON 对象?

我对 Clojure 有点陌生,想知道如何将这个 Enlive 对象转换为 JSON 对象。

我使用下面的 parse 方法解析了一个 XML 文件:

并像这样获得了一个 Enlive 对象:

我希望能够将其转换为 JSON 对象,如下所示:

如果使用的词汇不完全准确,我深表歉意

我在这一步转换时遇到了麻烦。提前谢谢你的帮助。