Giter Site home page Giter Site logo

express-helpers's Introduction

Express Helpers

Express Helpers is a port of EJS's ViewHelpers.

Features

Express Helpers provides view helpers for common tasks. These helpers are very similar to those found in the Ruby on Rails framework.

  • date_tag
  • form_tag
  • form_tag_end
  • hidden_field_tag
  • input_field_tag
  • link_to
  • submit_link_to
  • link_to_if
  • link_to_unless
  • password_field_tag
  • select_tag
  • single_tag_for
  • start_tag_for
  • submit_tag
  • tag
  • tag_end
  • text_area_tag
  • text_tag
  • text_field_tag
  • url_for
  • img_tag

Installation

npm install express-helpers

How to use

Require modules and cretae a server.

var express = require('express');
var helpers = require('express-helpers');
var app = express.createServer();

Register necessary view helpers...

app.helpers({
  date_tag: helpers.date_tag
});

app.helpers({
  ...

Or all view helpers:D

app = helpers.all(app);

Details

date_tag(name, value, html_options)

Creates a date tag

date_tag('Installation[date]', new Date(1982, 10,20) )

form_tag(action, html_options)

Creates a start form tag.

form_tag('/myaction',{multipart: true}) 

end_form_tag()

Creates a start form tag.

form_tag_end()

hidden_field_tag( name, value, html_options)

Creates a hidden field.

hidden_field_tag('something[interesting]', 5) => 

"<input id=\'something[interesting]\' 
        value=\'5\' 
        type=\'hidden\' 
        name=\'something[interesting]\'/>"

img_tag

Creates an image tag.

img_tag('/some.png', 'something') => "<img src='/some.png' alt='something' />"

input_field_tag

Creates an input field tag.

input_field_tag('something[interesting]', 5) => 

"<input id='something[interesting]' 
        value='5' 
        type='text' 
        name='something[interesting]'/>"

link_to

Creates a link to another page.

link_to('hello world', '/something/here') => "<a href='/something/here' >hello world</a>"

submit_link_to

Creates a submit button that links to another page.

submit_link_to('holla', '/new/location') => 

"<input onclick='window.location=\"/new/location\";return false;' 
        value='holla' 
        type='submit' />"

link_to_if(condition, name, url, html_options, post, block)

Just like link_to if the condition is true. If condition is false it returns name.

link_to_unless(condition, name, url, html_options, block)

Just like link_to if the condition is false. If condition is true it returns name.

password_field_tag

Returns a password field.

password_field_tag('something[interesting]', 5) => 

"<input id='something[interesting]' 
        value='5' 
        type='password' 
        name='something[interesting]'/>"

select_tag

Returns a select tag.

var choices = [ {value: 1,    text: 'First Choice' }, 
                {value: 2,    text: 'Second Choice'},
                {value: 3,    text: 'Third Choice'}  ]
select_tag('mySelectElement', 2,  choices) => 

"<select id='mySelectElement' value='2' name='mySelectElement'>
    <option value='1' >First Choice</option>
    <option value='2' selected='selected'>Second Choice</option>
    <option value='3'>Third Choice</option>
 </select>"

single_tag_for

Helper for creating a single tag like

start_tag_for

Helper for creating a beginning tag like

submit_tag

Creates a submit tag.

submit_tag('Submit') => "<input type=\'submit\' value=\'Submit\' />"

tag

Creates a general tag.

tag_end

Creates an end tag like </div>.

text_area_tag

text_area_tag('task[description]', 'Here is some text.\nA new line.') =>

"<textarea id='task[description]' 
           name='task[description]' 
           cols='50' 
           rows='4' >Here is some text.\nA new line.</textarea>"

text_field_tag

text_field_tag('something[interesting]', 5) => 

"<input id='something[interesting]' 
        value='5' 
        type='text' 
        name='something[interesting]'/>"

url_for

returns a string that changes the url.

License

(The MIT License)

EJS - Embedded JavaScript

Copyright (c) 2007 Edward Benson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Ported by Masahiro Hayashi [email protected]

express-helpers's People

Contributors

mhayashi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

express-helpers's Issues

TypeError: object is not a function

I get this error:
TypeError: object is not a function
at Object.CALL_NON_FUNCTION (native)
at Object. (/home/node/app/app.js:12:40)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array. (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)

from this line: var helpers = require('express-helpers')(app);

Ideas?

all() needs updated for newer version of express

currently in all() at line 198 there is this instance of condition

if (app instanceof express.Server) {

Since express no longer has express.Server this line should be replaced with

if (app instanceof express.HTTPServer) {

For those that are looking for a work around this is how I am using it right now

//include all helpers 
express.Server = express.HTTPServer //this is a hack to make the helpers work
app = helpers.all(app);

This could also be a way of making express-helpers backward compatible.

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.