Giter Site home page Giter Site logo

node-cfml's Introduction

Forked node-cfml

I'm attempting to fix the node-cfm package with this fork.

node-cfml

A simple cfml template engine for node.js/express

Introduction

Version 1.0 is out! It's a complete rewrite of what started out as a few regexps quickly thrown together. It is now a decently fast template engine. It uses a static cache, it supports tag nesting, comments, dynamic variable names, etc. It behaves mostly like Coldfusion but it interprets javascript code. (eg: arrays start at 0). Just use it like you would any other express template engine. Enjoy the clean views, the tag completion and color coding ... Using tags for view logic in HTML actually kicks ass.

Support

Only a few CFML tags have been implemented. It wouldn't make sense to use most other CF tags in a view. The implemented tags are:

  • CFSET
  • CFOUTPUT
  • CFIF
  • CFLOOP
  • CFPARAM
  • CFSAVECONTENT
  • CFINCLUDE
  • CFBREAK
  • CFABORT

The implemented CF operators are:

  • EQ, IS
  • NEQ, IS NOT
  • LT
  • GT
  • LTE, LE
  • GTE, GE
  • NOT
  • AND, OR
  • MOD
  • &

You can also use javascript operators directly. The parser will not like the > operator in tags so use GT or GTE in a CFIF tag.

Installation

npm install node-cfml --save

Usage

var express = require('express')
var app = express()
var cfml = require('node-cfml')

app.engine('cfm', cfml.renderFile)
app.set('view engine', 'cfm')
app.get('/', function (req, res) {
	res.render('test.cfm')
})

var server = app.listen(3000, function () {
	var host = server.address().address
	var port = server.address().port

	console.log('Example app listening at http://%s:%s', host, port)
})

Tests

Just run

mocha

to run the tests

node-cfml's People

Contributors

lafougere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-cfml's Issues

[Feature] Plugins

Kinda like Cold Fusion has custom tags, I think it would be a good idea to implement plugins so people can write their own cmfl tags.

For example, i really like using layouts, but with cold fusion you have to use include. This means if I'm rendering a view, ill have to repeat the base site html. However, if i created a cf_extends tag, then i can have the amazing feature of layouts.

https://github.com/AndrewKralovec/node-cfml/tree/cf_extends

However to implement this i had to edit the source code. I'm thinking we could just create a plugs method, that loads in the desired tags.

Examples what what i mean

app.js

cfml.plugin('./cfextends')

cfml.js

tags = {
  cfabort: require('./lib/cfabort'),
   ...this.plugins()
},

layout.cfm

<html lang="en">
    <head>
        <title>Base Layout</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    </head>
    <body>
        <!-- Navbar -->
        <nav class="navbar blurs">
            <div class="container">
            </div>
        </nav>
        <div class="container-fluid">
             <!--- Inject View Template --->
            <cfblock>
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </body>
</html>

index.cfm

<cfextends template="views\layout.cfm">
<cfoutput>
    #title# <br>
    #message# <br>
</cfoutput>

image

First < is removed

When parseing the cfml files, the fist '<' is striped from the page.
This issue is occurring in cfml.js In processQueue function, the bracket is picked up as an other tag.
buf[buf.length - 1] is undefined at this point, so the '<' is not added and the string sliced at index 1. The fist tag does not get processed correctly. I quick fix is to add the '<' at the begging of the rendered result, but a more permanent solution should be put in place.

Input

<html>
    <h2>Hello World</h2>
    <cfset test = "10">
    <cfoutput>
        #test#
    </cfoutput>
</html>

Output

html>
    <h2>Hello World</h2>
    
    
        10
    
</html>

Expected output


<html>
    <h2>Hello World</h2>
    
    
        10
    
</html>

[Bug] Boolean types are not evaulated in render

In the render function, we check to see if a property is on an object to find out if we need to evaul it into tmp. This will fail if the value of that property is evaluated to false.
Ex:

// if (false)
if (vars[instr.value]) out += vars[instr.value] // if go through undefined logic

Instead we should be checking if its undefined.
if (vars[instr.value] !== undefined) out += vars[instr.value]

<body>
      <cfset temp = false >
      <cfif temp>
        <h2> Hello </h2>
      <cfelse>
        <h2> GoodBye </h2>
      </cfif>

        <cfoutput>
          #title# <br>
          #message# <br>
          #temp# <!--- Will Error out --->
        </cfoutput>
</body>

node newbie issue

Hi, I'm a ColdFusion guy trying out node-cfml. I'm very new to node.

When I run the following in my app.js, node just hangs. I'm getting a response at

app.get('/', function (req, res) {
console.log(res).

I'm running this with:
node v4.4.1

Can you suggest a way to debug?

app.js

var express = require('express')
var app = express()
var cfml = require('node-cdml')

app.engine('cfm', cfml.renderFile)
app.set('views', __dirname + '/views')
app.set('view engine', 'com')

app.get('/', function (req, res) {
    res.render('test.cfm')
})

var server = app.listen(3000, function () {
    var host = server.address().address
    var port = server.address().port

    console.log('Example app listening at http://%s:%s', host, port)
})

[Feature] cfquery

@Lafougere , do you think we should implement <cfquery>or is this overkill ?
I was thinking what we could do i import knex.js. This is what we can use to build the query.
The user will be required to still setup a datasource, just like in cold fusion.
As far as building the query, we could just read the text block in the <cfquery> tag, and plug that string into knex as a raw query.

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.