Getting started: Clojure Web App with Compojure and Envlive
来源:互联网 发布:淘宝店铺采集器 编辑:程序博客网 时间:2024/05/07 09:49
Getting started: Clojure Web App with Compojure and Envlive
In this article I will show you how to create a basic Clojure web application built withCompojure and Enlive. Our HTML templates will be Pure.
You can find the code for this tutorial at Github.
CREATE A PROJECT
Generate a new Compojure project using Leiningen. For more details about Leiningen, check an older Clojure App 101 article.
is a Leiningen configuration. It stores project metadata: its dependencies, description, version et al.
In
directory we put assets such as images, JavaScript and CSS files along with HTML templates. and usually have similar structure, the first directory stores the actual application code while the second one the tests that goes with it.Run the application
Check if it works
ROUTES WITH COMPOJURE
Compojure is a routing library built on top of Ring. Routes are defined in
using macro. This macro creates a Ring handler for routes defined inside it. Each route consists of a method name ( , , ...), a path, a list of arguments (which may be empty) and a response.In our example we have 3 routes.
and are special routes, the 1st serves resources from the classpath and the 2nd returns 404 for undefined route paths.TEMPLATES WITH ENLIVE
In the presentation layer we will use pure HTML files - no cutom templating language, not even single 'staches. Data will be put into that HTML using transformations defined with Enlive. This way the design will be kept separated from the code that implements the behaviour for the display.
Add
as a project dependency in .Create a template function inside
Enlive provides a
macro which allows to specify a list of elements along with their transformations for a given HTML file. In our example we set the content of a tag with identifier to a value passed to the template definition as a parameter.Last piece of the puzzle is the actual HTML file. Create it under
as .Finally, run it as follows
Go to
to see the application in action.- Getting started: Clojure Web App with Compojure and Envlive
- Clojure Getting Started
- compojure-clojure
- Getting Started with Eclipse and the SWT
- Getting Started With Ruby and Rails
- Getting Started With Node.js and mongoDB
- Getting Started with Eclipse and Counterclockwise
- Getting Started with Kinect and Processing
- Getting Started With IronRuby And RSpec
- Getting started with OpenCL and GPU Computing
- Getting started with GWT, Maven and Eclipse
- Getting Started with JPA and Eclipse
- Getting started with OpenCL and GPU Computing
- Clojure入门指南(Getting Started)
- Clojure入门指南(Getting Started)
- Getting Started with Smartphone
- Getting Started With JasperReports
- Getting started with OpenCV
- 一步步学习SPD2010--第五章节--处理数据视图(9)--部署Web部件
- 怎么让progressbar不转动
- 商圈研究方案-调研内容及方法
- LINUX 菜鸟私房菜---体系观
- 一步步学习SPD2010--第五章节--处理数据视图(10)--关键点
- Getting started: Clojure Web App with Compojure and Envlive
- 关于android的好的博客栏目(持续更新。。。)
- WebService 的创建,部署和使用
- ext form combo 不能隐藏 labfield的问题
- 一步步学习SPD2010--第六章节--处理数据源
- OS X 10.9 安装
- 《COM技术内幕》学习一
- .net连接oracle数据库
- postgresql使用参考网址