Permalink
Browse files

automatically generating tests a documents also made some bug fixes a…

…nd changes to methods so everything is used intuitively
  • Loading branch information...
1 parent 0b46da9 commit a835ea7bb08b3af51ad4c8738f0a3cd2ecd03770 @tanema committed Mar 12, 2012
Showing with 457 additions and 204 deletions.
  1. +1 −1 .gitignore
  2. +224 −0 docs/index.txt
  3. +72 −0 docs/outputdoc.js
  4. +41 −94 lib/express-helpers.js
  5. +116 −103 test/helpers.test.js
  6. +1 −1 test/test.ejs
  7. +2 −5 test/test.js
View
@@ -1 +1 @@
-lib-cov
+node_modules
View
@@ -0,0 +1,224 @@
+## Features
+
+If there are any here that are undocumented they will be soon I promise
+
+please contact me if you are stuck or log an issue I am more than happy to help
+
+* [button_to / button_link_to](#button_to)
+* [cdata](#cdata)
+* [checkbox_tag](#checkbox_tag)
+* [color_field_tag](#color_field_tag)
+* [css_tag](#css_tag)
+* [date_tag](#date_tag)
+* [date_time_tag](#date_time_tag)
+* [doctype_tag](#doctype_tag)
+* [email_field_tag](#email_field_tag)
+* [end_tag](#end_tag)
+* [escape_js](#escape_js)
+* [file_field_tag](#file_field_tag)
+* [form_tag](#form_tag)
+* [form_end_tag](#form_end_tag)
+* [hidden_field_tag](#hidden_field_tag)
+* [img_tag](#img_tag)
+* [image_submit_tag](#image_submit_tag)
+* [input_field_tag](#input_field_tag)
+* [js_tag](#js_tag)
+* [js_button](#js_button)
+* [label_for](#label_for)
+* [link_to](#link_to)
+* [link_to_if](#link_to_if)
+* [link_to_unless](#link_to_unless)
+* [link_to_unless_current](#link_to_unless_current)
+* [mail_to](#mail_to)
+* [number_field_tag](#number_field_tag)
+* [password_field_tag](#password_field_tag)
+* [phone_field_tag / telephone_field_tag](#phone_field_tag)
+* [radio_tag](#radio_tag)
+* [reset_field_tag](#reset_field_tag)
+* [sanitize_css](#sanitize_css)
+* [search_field_tag](#search_field_tag)
+* [select_tag](#select_tag)
+* [single_tag_for](#single_tag_for)
+* [start_tag_for](#start_tag_for)
+* [strip_links](#strip_links)
+* [strip_tags](#strip_tags)
+* [submit_tag](#submit_tag)
+* [tag](#tag)
+* [text_area_tag / text_tag](#text_area_tag)
+* [text_field_tag](#text_field_tag)
+* [time_tag](#time_tag)
+* [url_field_tag](#url_field_tag)
+
+## Details
+
+### <a name="doctype_tag"/>doctype_tag ##
+
+doctype that are define are:
+
+* HTML5
+* HTML4s
+* HTML4t
+* HTML4f
+* XHTML1s
+* XHTML1t
+* XHTML1f
+* XHTML1_1
+
+ doctype_tag(HTML4s) =>
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+ doctype_tag() =>
+ <!DOCTYPE HTML>
+
+### <a name="date_tag"/>date_tag(name, [value, html_options])
+Creates a date tag
+
+ date_tag('Installation[date]', new Date(1982, 10,20) )
+ date_tag('Installation[date]') // just on current time
+
+### <a name="time_tag"/>time_tag(name, [value, html_options])
+Creates a time tag
+
+ time_tag('Installation[time]', new Date(1982, 10,20) )
+ time_tag('Installation[time]') // just on current time
+
+### <a name="date_time_tag"/>date_time_tag(name, [value, html_options])
+Creates a time tag
+
+ date_time_tag('Installation[time]', new Date(1982, 10,20) )
+ date_time_tag('Installation[time]') // just on current time
+
+### <a name="css_tag"/>css_tag(src[, html_options])
+Creates a css tag
+
+ css_tag('/stylesheet/style.css') =>
+ "<link rel='stylesheet'
+ href='/stylesheet/style.css'
+ type='text/css'
+ charset='utf-8' />"
+
+### <a name="checkbox_tag"/>checkbox_tag(name, value[, html_options])
+Creates a checkbox
+
+ checkbox_tag('user_check_box', 'user') =>
+ "<input id='user_check_box' value='user' type='checkbox' name='user_check_box' />"
+
+### <a name="radio_tag"/>radio_tag(name, value[, html_options])
+Creates a radio button
+
+ radio_tag('user_radio', 'user') =>
+ "<input id='user_radio' value='user' type='radio' name='user_radio' />"
+
+### <a name="form_tag"/>form_tag(action[, html_options])
+Creates a start form tag.
+
+ form_tag('/myaction',{multipart: true})
+
+
+### <a name="end_form_tag"/>end_form_tag()
+Creates a end form tag.
+
+ form_end_tag()
+
+
+### <a name="hidden_field_tag"/>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]\'/>"
+
+
+### <a name="img_tag"/>img_tag(image_location, alt[, html_options])
+Creates an image tag.
+
+ img_tag('/some.png', 'something') => "<img src='/some.png' alt='something' />"
+
+### <a name="js_tag"/>js_tag(url[, html_options])
+Creates a javascript script tag
+
+ js_tag('/javascript/script.js') =>
+ "<script type='text/javascript'
+ src='/javascript/script.js'
+ charset='utf-8' ></script>"
+
+### <a name="label_for"/>label_for(name[, text, html_options])
+Creates a label for tag
+
+ label_for('user_id') => "<label for=\'user_id\' >User</label>"
+
+ label_for('book[user_id]') => "<label for=\'book[user_id]\' >User</label>"
+
+### <a name="link_to"/>link_to(name[, url, html_options])
+Creates a link to another page.
+
+ link_to('hello world', '/something/here') => "<a href='/something/here' >hello world</a>"
+
+### <a name="link_to_if"/>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.
+
+### <a name="link_to_unless"/>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.
+
+### <a name="password_field_tag"/>password_field_tag(name, value, html_options)
+Returns a password field.
+
+ password_field_tag('something[interesting]', 5) =>
+
+ "<input id='something[interesting]'
+ value='5'
+ type='password'
+ name='something[interesting]'/>"
+
+
+
+### <a name="select_tag"/>select_tag(name, value, choices[, html_options])
+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>"
+
+### <a name="submit_tag"/>submit_tag([text, url, html_options])
+Creates a submit tag.
+
+ submit_tag('Submit This') => "<input type=\'submit\' value=\'Submit This\' />"
+ submit_tag() => "<input type=\'submit\' value=\'Submit\' />"
+ submit_tag({class:'button'}) => "<input class='button' type=\'submit\' value=\'Submit\' />"
+
+ submit_tag('holla', '/new/location') =>
+
+ "<input onclick='window.location=\"/new/location\";return false;'
+ value='holla'
+ type='submit' />"
+
+### <a name="text_area_tag"/>text_area_tag(name[, value, html_options]) / text_tag(name[, value, html_options])
+Both create a text area tag
+
+ text_area_tag('task[description]', 'Here is some text.\nA new line.') =>
+ text_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>"
+
+
+
+### <a name="text_field_tag"/>text_field_tag(name[, value, html_options])
+
+ text_field_tag('something[interesting]', 5) =>
+
+ "<input id='something[interesting]'
+ value='5'
+ type='text'
+ name='something[interesting]'/>"
View
@@ -0,0 +1,72 @@
+var helpers = require('../lib/express-helpers.js')();
+var generate_docs = false,
+ generate_tests = true;
+var date = new Date(2007,10,20,1,1,1,1);
+var date_string = JSON.stringify(date);
+var choices = [ {value: 1,text:'First Choice' },{value: 2,text: 'Second Choice'},{value: '3',text: 'Third Choice'}];
+
+var methods = [
+ {helper: "button_to", args: ["google", "http://www.google.com"]},
+ {helper: "cdata", args: ['this is cdata']},
+ {helper: "checkbox_tag", args: ['user_check_box', {value:'user'}]},
+ {helper: "color_field_tag", args: ['color', {value: 5}]},
+ {helper: "css_tag", args: ['/stylesheet/style.css']},
+ {helper: "date_tag", args: ['Installation[date]', {value: date}]},
+ {helper: "date_time_tag", args: ['Installation[datetime]', {value: date}]},
+ {helper: "doctype_tag", args: []},
+ {helper: "email_field_tag", args: ['email', {value: 'test@email.com'}]},
+ {helper: "escape_js", args: ["var i = 5;"]},
+ {helper: "file_field_tag", args: ['file', {value: 5}]},
+ {helper: "form_tag", args: ['/myaction']},
+ {helper: "form_end_tag", args: []},
+ {helper: "hidden_field_tag", args: ['something[interesting]', {value:5}]},
+ {helper: "img_tag", args: ['/some.png', 'something']},
+ {helper: "image_submit_tag", args: ['/some.png', {alt: 'submit'}]},
+ {helper: "js_tag", args: ['/javascript/script.js']},
+ {helper: "js_button", args: ["google", "http://www.google.com"]},
+ {helper: "label_for", args: ['user_id']},
+ {helper: "link_to", args: ['hello world', '/something/here']},
+ {helper: "link_to_if", args: [false, 'Reply', '/reply']},
+ {helper: "link_to_unless", args: [true, 'Reply', '/reply']},
+ {helper: "mail_to", args: ["me@domain.com", "Send Me Email", {encode : "hex", subject: "that thing I sent you", body: "did you get that thing I sent you"}]},
+ {helper: "number_field_tag", args: ["number", {value: 5}]},
+ {helper: "password_field_tag", args: ['something[interesting]', {value:5}]},
+ {helper: "phone_field_tag", args: ["phony", {value: 12345123}]},
+ {helper: "radio_tag", args: ['user_radio', {value:'user'}]},
+ {helper: "reset_form_tag", args: []},
+ {helper: "sanitize_css", args: ['takes urls out of here']},
+ {helper: "search_field_tag", args: ['search']},
+ {helper: "select_tag", args: ['mySelectElement', choices, {value:2}]},
+ {helper: "strip_links", args: ['strip <a href="google">links</a> from here']},
+ {helper: "strip_tags", args: ['strip <b> tags </b> from here']},
+ {helper: "submit_tag", args: ['holla', '/new/location']},
+ {helper: "text_area_tag", args: ['task[description]', {value:'Here is some text.\nA new line.'}]},
+ {helper: "text_field_tag", args: ['something[interesting]', {value:5}]},
+ {helper: "time_tag", args: ['Installation[time]', {value: date}]},
+ {helper: "url_field_tag", args: ['url', {value: "website.com"}]}
+];
+
+if(generate_tests){
+ console.log("var assert = require('assert'),helpers = require('../lib/express-helpers.js')();");
+ console.log(" ");
+}
+for(var i = 0; i < methods.length; i++){
+
+ var json = JSON.stringify(methods[i].args)
+ if(generate_docs){
+ console.log(" ")
+ console.log(methods[i].helper+"("+ json.substring(1, json.length - 1)+")")
+ console.log(" ");
+ console.log(" => ");
+ console.log(" ");
+ console.log(helpers[methods[i].helper].apply(this, methods[i].args))
+ console.log(" ");
+ }
+
+ if(generate_tests){
+ console.log("assert.equal(\""+helpers[methods[i].helper].apply(this, methods[i].args).replace(/"/g, "\\\"").replace(/\n/g, "\\n")+"\","
+ +"helpers."+methods[i].helper+"("+ json.substring(1, json.length - 1).replace(date_string, 'new Date(2007,10,20,1,1,1,1)')+").replace(/\"/g, \"\\\"\").replace(/\\n/g, \"\\n\") )");
+ console.log("console.log('"+methods[i].helper+" test complete');");
+ console.log(" ");
+ }
+}
Oops, something went wrong.

0 comments on commit a835ea7

Please sign in to comment.