Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

compile

  • Loading branch information...
commit 6e224c4e4328e70da12637184117b95b3e0e46af 1 parent 7e67fa2
@huetsch authored
Showing with 35 additions and 2 deletions.
  1. +35 −2 form_tag_helper.js
View
37 form_tag_helper.js
@@ -1,12 +1,45 @@
(function() {
- var FormTagHelper;
+ var FormTagHelper, TagHelper, helper,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ require('cream');
+
+ TagHelper = require('tag-helper');
FormTagHelper = (function() {
- function FormTagHelper() {}
+ function FormTagHelper() {
+ this.sanitize_to_id = __bind(this.sanitize_to_id, this);
+ this.select_tag = __bind(this.select_tag, this);
+ }
+
+ FormTagHelper.prototype.select_tag = function(name, option_tags, options) {
+ var html_name, prompt;
+ if (option_tags == null) option_tags = null;
+ if (options == null) options = {};
+ html_name = options.multiple === true && (!new String(name).endsWith("[]")) ? "" + name + "[]" : name;
+ if (Object["delete"](options, 'include_blank')) {
+ option_tags = "<option value=\"\"></option>".html_safe().concat(option_tags);
+ }
+ if (prompt = Object["delete"](options, 'prompt')) {
+ option_tags = ("<option value=\"\">" + prompt + "</option>").html_safe().concat(option_tags);
+ }
+ return TagHelper.content_tag('select', option_tags, Object.update({
+ name: html_name,
+ id: this.sanitize_to_id(name)
+ }, options));
+ };
+
+ FormTagHelper.prototype.sanitize_to_id = function(name) {
+ return new String(name).replace(/]/g, '').replace(/[^-a-zA-Z0-9:.]/g, "_");
+ };
return FormTagHelper;
})();
+ helper = new FormTagHelper();
+
+ exports.select_tag = helper.select_tag;
+
}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.