Git Product home page Git Product logo

jaderl's Introduction

jaderl

An implementation of the Jade templating language in Erlang

Current Status

With reference to the docs at https://github.com/visionmedia/jade#readme ...

Things that are implemented and working:

  • tags
  • nesting
  • tag text on same line
  • tag text using '|'
  • tag text using '.'
  • tags which accept only text don't need leading '|'
  • attributes
  • block expansion
  • single line comments
  • block comments
  • conditional comments
  • tag nesting
  • inline html
  • doctypes
  • Case
  • Filters
  • Iteration
  • Conditionals

Note: Standard 'dot syntax' is supported, so sub-variables can be references as "var.sub". This includes the ability to pass a tuple and lookup a module with name matching element(1... and call the appropriate function. (This is intended to be used to call functions in a model, but I have not tested it for that yet so it probably does not quite work, though it works as I have described it here) I have a flag for escaping values, but escaping is not implemented yet.

Things that are not yet implemented:

  • Code
  • Template Inheritance
  • Block Append / prepend
  • Includes
  • Mixins

Notes

  1. "- Code" means embedding JavaScript in the template, and I am not expecting to provide that at any point, unless there is a really good case for it

  2. Where functions are required in the generated template I have created in-line anonymous functions rather than named functions - I may go back on this as i think named functions would make the generated template more readable (though I am not sure how much this matters)

  3. For some strange reason I did not generate embedded functions to evaluate conditionals, but rather pass the expression tree into the generated template where it is "interpreted" by functions in the runtime library. Going the other way would probably produce slightly faster rendering, though I do not know whether the difference would be significant.

  4. I have passed an options variable through the code, but have not had occasion to use it yet.

  5. As I mentioned below, Jaderl is structured in two phases as discussed earlier in this thread, and I would like to propose HST (the Html Syntax Tree) as a possible candidate for a standard intermediate form. I have no doubt it needs work, but it is in the jaderl.hrl file, and I am happy to document it further as a start-point for discussion. (Note that at the moment the HST is an intermediate form passed between two functions in jaderl.erl.)

"Non-standard" items

  1. "Code" is not implemented, but I do intend to include the ability to execute an erlang function which would be expected to return HTML (this is somewhat a replacement for the custom tags that Django supports - likely syntax "-call module function, params" )

  2. Jaderl requires the use of "-" as the initial character for . I like the way it makes these elemnts stand out from tags, and it ensures that no potential tags are "reserved words". (Does this mean that Jaderl could be used to generate arbitrary

Most of the code is fairly well covered by unit tests, but where I have misunderstood, my tests will be testing in accordance with my misunderstanding.

Feedback on any of this very much appreciated!

Getting Started

  1. write a page in jade (see test.jade as an example
  2. run jaderl:comp_file(test). This will create the generated template for your page. This is a plain erlang source file and will be named test.erl.
  3. compile test.erl (creating test.beam ;-) )
  4. run test:render(Env) - where env is a proplist of variables to be passed into the render operation. Env = [{"v1","val"}, {"v2","val"}] will give "xxx" in the generated html. Env = [{"v1","val"}, {"v2","vax"}] will give "yyy".

jaderl's People

Contributors

evanmiller avatar graeme-defty avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.