a util for compiling HTML/PDF documents using Hiccup style templates

栏目: IT技术 · 发布时间: 6年前

内容简介:A simple data driven document builder for ClojureScript. A document is described using two files. One file conains HTML markup for the document in Hiccup format, and the other contains document data in EDN format. The library will inject the EDN data into

doc-builder

A simple data driven document builder for ClojureScript. A document is described using two files. One file conains HTML markup for the document in Hiccup format, and the other contains document data in EDN format. The library will inject the EDN data into the markup and compile it to either HTML or PDF formats.

Overview

The document data should be placed in an EDN file in the documents directory. See documents/sample.edn for an example.

The content of the data file is referenced by the template using a namespaced keyword in the following format:

:data/path.to.field

The keyword represents a get-in path to provide support for accessing nested fields in the document. The above will be translated into [:path :to :field] when the template is compiled.

When the template is loaded, the values from the data file will be injected into it. Templates can contain code referencing functions from Clojure core, e,g:

[:div.row
 (for [{:keys [network username url]} :data/basics.profiles]
   [:div.col-sm-6
    [:strong.network network]
    [:div.username
    [:div.url
    [:a {:href url} username]]]])]

Corresponding data payload should look as follows:

{:basics
 {:network  "Twitter"
  :username "john"
  :url      "http://twitter.com/john"}}

Templates use the following directory structure:

templates
  <template name>
    template.edn
    <related files>

Templates can reference CSS in files from the template directory, e.g:

[:page/css
   "css/bootstrap.min.css"
   "css/octicons.min.css"
   "css/resume.css"]

See the default template for a complete example.

Usage

  1. install Lumo
  2. check out this project locally
  3. run npm install
  4. update documents/sample.edn with your data
  5. update the configuration file called config.edn as necessary:
{:template :default
 :formats  [:pdf :html]
 :pdf-opts {:format "A4"} ;defaults to Letter
 :document "sample.edn"
 :target   "build"}
  1. build the resume ./build.cljs

License

Copyright © 2020 Dmitri Sotnikov

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 .

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html .


以上所述就是小编给大家介绍的《a util for compiling HTML/PDF documents using Hiccup style templates》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

模糊数学基础及实用算法

模糊数学基础及实用算法

李鸿吉编 / 科学出版社 / 2005-1 / 55.00元

本书开发了模糊数学常用的计算机程序,并以大量的算例系统地介绍了模糊数学的实用算法。本书可以作为模糊数学的应用程序包,在详细解释源代码的同时,对应用程序开发所用到的Visual Basic 6.0方法做了系统介绍,其目的是为读者做进一步的自主开发提供便利。本书所提供的源程序可以作为读者自主开发的素材。本书配有光盘,分章节提供程序源代码。 本书可以作为大专院校、培训班的教学参考书。对需......一起来看看 《模糊数学基础及实用算法》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具