• Stars
    star
    221
  • Rank 179,773 (Top 4 %)
  • Language
    JavaScript
  • Created about 16 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript port of Tobias Luetke's Liquid template engine.

Liquid.js

General

This is a complete port of Liquid from Ruby to JavaScript. Any template that Ruby Liquid can compile and render, Liquid.js should too.

This tries to be javascript framework agnostic (i.e. doesn’t use jQuery nor Prototype). This adds a little extra code as it implements its own helpers like clear, first, last on Array, and a Class OOP implementation; this tradeoff is made to allow the code to be portable across many systems.

Liquid.js does not use eval or with, so it’s pretty clean and really safe.

Installation

The current version of the library is checked into the dist directory.

To re-build from source, follow these steps:

  1. Clone the repository somewhere locally and go into the folder; i.e. git clone gitgithub.com:/mattmccray/liquid.js.git@.
  2. Run bundle install to install the necessary Gemfiles.
  3. Compile the JavaScript files with the default rake task; i.e. bundle exec rake.
  4. Copy the distribution files to your desired location; i.e. cp dist/liquid*.js ~/projects/my_project/public/javascripts/.

Differences

  1. Ranges. JavaScript doesn’t really have Ranges like Ruby does. So when Liquid.js comes across a range “(1..5)”, it creates an Array with the values 1 through 5. In addition ranges like (a..z) should work.
  2. ‘replace’ and ‘replace_first’ filters build RegExps from the input, so you can actually define a regexp to use in your replacement.
  3. ‘include’ tag. By default, this will return a Liquid error (but not an exception). To use the ‘include’ tag, you’ll need to implement your own ‘filesystem’ support. Which, in Liquid.js, just means you override the Liquid.readTemplateFile function to suit your own needs. Here’s an example:
<script>

  Liquid.readTemplateFile = function(path) {
    var elem = $(path);
    if(elem) {
      return elem.innerHTML;
    } else {
      return path +" can't be found.";
      // Or throw and error, or whatever you want...
    }
  }

  var src = "{% include 'myOtherTemplate' with current_user %}";

  var tmpl = Liquid.parse( src );

  alert( tmpl.render({ current_user:'M@' }));

</script>
<!-- Browsers ignore script blocks with an unrecognized type.  -->
<!-- Makes for pretty good inline template storage.  -->
<script type="text/liquid" id="myOtherTemplate">
  Hello, {{ current_user }}!
</script>

Known Issues

  1. Known to work in Safari 3.1+ and FireFox 3+.
  2. IE 7: passes tests but needs more actual usage testing

References:

Development

  1. Fork the project on github.
  2. Follow the installation steps with your repository.
  3. Load the test/liquid-tests.html file to execute the tests; i.e. in a web browser load ‘file:///home/username/projects/liquid.js/test/liquid-tests.html’.
  4. Load the test/liquid-console.html to debug specific templates or test scenarios; i.e. in a web browser load ‘file:///home/username/projects/liquid.js/test/liquid-tests.html’.
  5. NOTE: It is recommended to use Chrome or Firefox (with Firebug) for development so you can see javascript errors in detail.

Todo

  • Add support for console-based testing?
  • Move the Class OOP support (that replaced Prototype) into Liquid.Class so it won’t conflict with other implementations.
  • Look at the Object extensions and consider making a Liquid.Hash class similar to Prototype.
  • Look into making into a gem or something that has the auto-compiled JS file in the workflow somewhere.

More Repositories

1

comatose

Comatose is a micro CMS, implemented as a Rails plugin, that is designed to be easy to embed and extend.
Ruby
192
star
2

gumdrop

The sweet 'n simple cms/prototyping tool for creating static html websites and webapps.
Ruby
17
star
3

flipbook.js

FlipBook is an embeddable comic viewer...
CoffeeScript
12
star
4

dm.js

DM.js is a simple JavaScript ORM (loosely based on ActiveRecord) that supports the following sqlite browser backends: Safari/HTML5, Adobe Air, and Google Gears.
JavaScript
11
star
5

Template.ts

Simple, code based, template engine for TypeScript.
JavaScript
9
star
6

new-react-simple

Simple ReactJS + CoffeeScript skeleton includes: react-brunch, react-brunch-tags, elucidata-react-coffee
CoffeeScript
9
star
7

klass.js

A prototype-chain based class inheritance library (no dependencies).
JavaScript
7
star
8

thor-tasks

Miscellaneous Thor Tasks
Ruby
6
star
9

middleman-webcomic

An extension for MiddleMan (2) for creating webcomic sites.
Ruby
3
star
10

cumulus

A simple HTML, file based, content management tool.
Ruby
2
star
11

darthapo.github.com

My github page...
2
star
12

sequent

Sequent, an easy to use web-comic publishing tool.
Ruby
2
star
13

blam.js

Templates are just code.
JavaScript
2
star
14

stratus

Static blog generation tool, based on ideas form Cumulus
Ruby
2
star
15

boilerplate

Tool for generating boilerplate directories and files
2
star
16

taskthis

Simple, AJAX enabled, todo list manager.
Ruby
2
star
17

core-js-utils

JavaScript
1
star
18

sdo.js

Simple Data Objects. Very simple, intended for use with React and small projects.
JavaScript
1
star
19

core-js

JavaScript
1
star
20

ShortStack

A compact, customizable, MVC framework for PHP.
PHP
1
star
21

ShortStack-Starter

A starter project for a ShortStack application.
PHP
1
star
22

wabu

Web App Bundling Utility
1
star
23

lumbar

Lumbar supports building Backbone (JS) applications
Ruby
1
star
24

settee.js

S-Expression template engine.
JavaScript
1
star
25

McUtils-tmbundle

My bundle of snippets/commands for Textmate.
1
star
26

crudly

Locally cruderific
Ruby
1
star
27

ewok.js

Yub Nub!
JavaScript
1
star
28

syncodemayo

FTP syncing tool for servers that don't support rsync.
TypeScript
1
star
29

GraphicNovelist-tmbundle

Textmate bundle for syntax highlighting and HTML export of Graphic Novelist scripts.
Ruby
1
star
30

taskthis2

TaskTHIS 2, HTML5 client-side app using Rails 3.
Ruby
1
star