ice 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/js/Cakefile +12 -0
- data/js/lib/form-tag-inputs.coffee +66 -0
- data/js/lib/form-tag-inputs.js +87 -0
- data/js/lib/path-helper.coffee +30 -0
- data/js/lib/path-helper.js +50 -0
- metadata +6 -1
data/js/Cakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
{spawn, exec} = require 'child_process'
|
3
|
+
sys = require 'sys'
|
4
|
+
|
5
|
+
task 'assets:watch', 'Watch source files and build JS', (options) ->
|
6
|
+
runCommand = (name, args...) ->
|
7
|
+
proc = spawn name, args
|
8
|
+
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
|
9
|
+
proc.stdout.on 'data', (buffer) -> console.log buffer.toString()
|
10
|
+
proc.on 'exit', (status) -> process.exit(1) if status isnt 0
|
11
|
+
|
12
|
+
runCommand 'coffee', '-wcb', '../spec/javascripts', 'lib'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
humanize = (name) ->
|
2
|
+
match = name.match(/(.*)_id$/)
|
3
|
+
if match
|
4
|
+
name = match[1]
|
5
|
+
name.split('_').join(' ')
|
6
|
+
|
7
|
+
getTypeValue = (type, opts) ->
|
8
|
+
switch type
|
9
|
+
when "disabled"
|
10
|
+
if opts[type] then "disabled" else ""
|
11
|
+
when "checked" then (opts[type] ? "checked" : "")
|
12
|
+
else opts[type]
|
13
|
+
|
14
|
+
getAttributeString = (type, opts) ->
|
15
|
+
(opts && opts[type] && type + "=\"" + getTypeValue(type,opts) + "\" ") || ""
|
16
|
+
|
17
|
+
getSizeString = (opts) ->
|
18
|
+
getAttributeString('size', opts)
|
19
|
+
|
20
|
+
getClassString = (opts) ->
|
21
|
+
getAttributeString('class', opts)
|
22
|
+
|
23
|
+
getDisabledString = (opts) ->
|
24
|
+
getAttributeString('disabled', opts)
|
25
|
+
|
26
|
+
getCheckedString = (opts) ->
|
27
|
+
getAttributeString('checked', opts)
|
28
|
+
|
29
|
+
getMaxlengthString = (opts) ->
|
30
|
+
getAttributeString('maxlength', opts)
|
31
|
+
|
32
|
+
labelTag = (name, opts) ->
|
33
|
+
label = if typeof opts == 'string' then opts else humanize(name)
|
34
|
+
classString = getClassString(opts)
|
35
|
+
"<label #{classString}for=\"#{name}\">#{label.charAt(0).toUpperCase()}#{label.substr(1)}</label>"
|
36
|
+
|
37
|
+
class BaseInputTag
|
38
|
+
constructor: (@tagType) ->
|
39
|
+
|
40
|
+
render: ->
|
41
|
+
"<input #{@checkedString}#{@disabledString}#{@classString}id=\"#{@name}\" #{@maxlengthString}name=\"#{@name}\" #{@sizeString}type=\"#{@tagType}\" #{@value}/>"
|
42
|
+
|
43
|
+
setOpts: (opts) ->
|
44
|
+
@classString = getClassString opts
|
45
|
+
@sizeString = getSizeString opts
|
46
|
+
@disabledString = getDisabledString(opts)
|
47
|
+
@maxlengthString = getMaxlengthString(opts)
|
48
|
+
|
49
|
+
|
50
|
+
passwordFieldTag = (name) ->
|
51
|
+
tag = new BaseInputTag("password")
|
52
|
+
tag.name = name
|
53
|
+
tag.value = ((typeof arguments[1] == 'string') && "value=\"" + arguments[1] + "\" ") || ""
|
54
|
+
opts = arguments[2] || arguments[1]
|
55
|
+
tag.setOpts(opts)
|
56
|
+
tag.checkedString = ""
|
57
|
+
tag.render()
|
58
|
+
|
59
|
+
checkBoxTag = (name) ->
|
60
|
+
tag = new BaseInputTag("checkbox")
|
61
|
+
tag.name = name
|
62
|
+
tag.value = "value=\"" + (((typeof arguments[1] == 'string') && arguments[1]) || 1) + "\" "
|
63
|
+
tag.checkedString = if arguments[2] is true then "checked=\"checked\" " else ""
|
64
|
+
opts = arguments[2] || arguments[1]
|
65
|
+
tag.setOpts(opts)
|
66
|
+
tag.render()
|
@@ -0,0 +1,87 @@
|
|
1
|
+
var BaseInputTag, checkBoxTag, getAttributeString, getCheckedString, getClassString, getDisabledString, getMaxlengthString, getSizeString, getTypeValue, humanize, labelTag, passwordFieldTag;
|
2
|
+
humanize = function(name) {
|
3
|
+
var match;
|
4
|
+
match = name.match(/(.*)_id$/);
|
5
|
+
if (match) {
|
6
|
+
name = match[1];
|
7
|
+
}
|
8
|
+
return name.split('_').join(' ');
|
9
|
+
};
|
10
|
+
getTypeValue = function(type, opts) {
|
11
|
+
var _ref;
|
12
|
+
switch (type) {
|
13
|
+
case "disabled":
|
14
|
+
if (opts[type]) {
|
15
|
+
return "disabled";
|
16
|
+
} else {
|
17
|
+
return "";
|
18
|
+
}
|
19
|
+
break;
|
20
|
+
case "checked":
|
21
|
+
return (_ref = opts[type]) != null ? _ref : {
|
22
|
+
"checked": ""
|
23
|
+
};
|
24
|
+
break;
|
25
|
+
default:
|
26
|
+
return opts[type];
|
27
|
+
}
|
28
|
+
};
|
29
|
+
getAttributeString = function(type, opts) {
|
30
|
+
return (opts && opts[type] && type + "=\"" + getTypeValue(type, opts) + "\" ") || "";
|
31
|
+
};
|
32
|
+
getSizeString = function(opts) {
|
33
|
+
return getAttributeString('size', opts);
|
34
|
+
};
|
35
|
+
getClassString = function(opts) {
|
36
|
+
return getAttributeString('class', opts);
|
37
|
+
};
|
38
|
+
getDisabledString = function(opts) {
|
39
|
+
return getAttributeString('disabled', opts);
|
40
|
+
};
|
41
|
+
getCheckedString = function(opts) {
|
42
|
+
return getAttributeString('checked', opts);
|
43
|
+
};
|
44
|
+
getMaxlengthString = function(opts) {
|
45
|
+
return getAttributeString('maxlength', opts);
|
46
|
+
};
|
47
|
+
labelTag = function(name, opts) {
|
48
|
+
var classString, label;
|
49
|
+
label = typeof opts === 'string' ? opts : humanize(name);
|
50
|
+
classString = getClassString(opts);
|
51
|
+
return "<label " + classString + "for=\"" + name + "\">" + (label.charAt(0).toUpperCase()) + (label.substr(1)) + "</label>";
|
52
|
+
};
|
53
|
+
BaseInputTag = (function() {
|
54
|
+
function BaseInputTag(tagType) {
|
55
|
+
this.tagType = tagType;
|
56
|
+
}
|
57
|
+
BaseInputTag.prototype.render = function() {
|
58
|
+
return "<input " + this.checkedString + this.disabledString + this.classString + "id=\"" + this.name + "\" " + this.maxlengthString + "name=\"" + this.name + "\" " + this.sizeString + "type=\"" + this.tagType + "\" " + this.value + "/>";
|
59
|
+
};
|
60
|
+
BaseInputTag.prototype.setOpts = function(opts) {
|
61
|
+
this.classString = getClassString(opts);
|
62
|
+
this.sizeString = getSizeString(opts);
|
63
|
+
this.disabledString = getDisabledString(opts);
|
64
|
+
return this.maxlengthString = getMaxlengthString(opts);
|
65
|
+
};
|
66
|
+
return BaseInputTag;
|
67
|
+
})();
|
68
|
+
passwordFieldTag = function(name) {
|
69
|
+
var opts, tag;
|
70
|
+
tag = new BaseInputTag("password");
|
71
|
+
tag.name = name;
|
72
|
+
tag.value = ((typeof arguments[1] === 'string') && "value=\"" + arguments[1] + "\" ") || "";
|
73
|
+
opts = arguments[2] || arguments[1];
|
74
|
+
tag.setOpts(opts);
|
75
|
+
tag.checkedString = "";
|
76
|
+
return tag.render();
|
77
|
+
};
|
78
|
+
checkBoxTag = function(name) {
|
79
|
+
var opts, tag;
|
80
|
+
tag = new BaseInputTag("checkbox");
|
81
|
+
tag.name = name;
|
82
|
+
tag.value = "value=\"" + (((typeof arguments[1] === 'string') && arguments[1]) || 1) + "\" ";
|
83
|
+
tag.checkedString = arguments[2] === true ? "checked=\"checked\" " : "";
|
84
|
+
opts = arguments[2] || arguments[1];
|
85
|
+
tag.setOpts(opts);
|
86
|
+
return tag.render();
|
87
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
safe = (value)->
|
2
|
+
result = new String(value)
|
3
|
+
result.ecoSafe = true
|
4
|
+
result
|
5
|
+
|
6
|
+
linkTo = (label, link, opts) ->
|
7
|
+
if (! link)
|
8
|
+
link = label
|
9
|
+
'<a href="' + link + '">' + label + '</a>'
|
10
|
+
|
11
|
+
navBar = (options, yield)->
|
12
|
+
config = try
|
13
|
+
NavBarConfig
|
14
|
+
catch error
|
15
|
+
{}
|
16
|
+
config["linkPrefix"] ||= "<li>"
|
17
|
+
config["linkPostfix"] ||= "</li>"
|
18
|
+
config["navPrefix"] ||= "<ul>"
|
19
|
+
config["navPostfix"] ||= "</ul>"
|
20
|
+
|
21
|
+
linkPrefix = ()-> options["linkPrefix"] || config["linkPrefix"]
|
22
|
+
linkPostfix = ()-> options["linkPostfix"] || config["linkPostfix"]
|
23
|
+
navPrefix = ()-> options["navPrefix"] || config["navPrefix"]
|
24
|
+
navPostfix = ()-> options["navPostfix"] || config["navPostfix"]
|
25
|
+
bar =
|
26
|
+
linkTo: (label, link = null) =>
|
27
|
+
safe "#{linkPrefix()}#{linkTo label, link}#{linkPostfix()}"
|
28
|
+
|
29
|
+
links = yield(bar)
|
30
|
+
safe "#{navPrefix()}#{links}#{navPostfix}"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
var linkTo, navBar, safe;
|
2
|
+
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
+
safe = function(value) {
|
4
|
+
var result;
|
5
|
+
result = new String(value);
|
6
|
+
result.ecoSafe = true;
|
7
|
+
return result;
|
8
|
+
};
|
9
|
+
linkTo = function(label, link, opts) {
|
10
|
+
if (!link) {
|
11
|
+
link = label;
|
12
|
+
}
|
13
|
+
return '<a href="' + link + '">' + label + '</a>';
|
14
|
+
};
|
15
|
+
navBar = function(options, yield) {
|
16
|
+
var bar, config, linkPostfix, linkPrefix, links, navPostfix, navPrefix;
|
17
|
+
config = (function() {
|
18
|
+
try {
|
19
|
+
return NavBarConfig;
|
20
|
+
} catch (error) {
|
21
|
+
return {};
|
22
|
+
}
|
23
|
+
})();
|
24
|
+
config["linkPrefix"] || (config["linkPrefix"] = "<li>");
|
25
|
+
config["linkPostfix"] || (config["linkPostfix"] = "</li>");
|
26
|
+
config["navPrefix"] || (config["navPrefix"] = "<ul>");
|
27
|
+
config["navPostfix"] || (config["navPostfix"] = "</ul>");
|
28
|
+
linkPrefix = function() {
|
29
|
+
return options["linkPrefix"] || config["linkPrefix"];
|
30
|
+
};
|
31
|
+
linkPostfix = function() {
|
32
|
+
return options["linkPostfix"] || config["linkPostfix"];
|
33
|
+
};
|
34
|
+
navPrefix = function() {
|
35
|
+
return options["navPrefix"] || config["navPrefix"];
|
36
|
+
};
|
37
|
+
navPostfix = function() {
|
38
|
+
return options["navPostfix"] || config["navPostfix"];
|
39
|
+
};
|
40
|
+
bar = {
|
41
|
+
linkTo: __bind(function(label, link) {
|
42
|
+
if (link == null) {
|
43
|
+
link = null;
|
44
|
+
}
|
45
|
+
return safe("" + (linkPrefix()) + (linkTo(label, link)) + (linkPostfix()));
|
46
|
+
}, this)
|
47
|
+
};
|
48
|
+
links = yield(bar);
|
49
|
+
return safe("" + (navPrefix()) + links + navPostfix);
|
50
|
+
};
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nate Kidwell
|
@@ -53,6 +53,11 @@ files:
|
|
53
53
|
- lib/ice/eco_template/handler.rb
|
54
54
|
- lib/ice/railtie.rb
|
55
55
|
- lib/ice.rb
|
56
|
+
- js/Cakefile
|
57
|
+
- js/lib/form-tag-inputs.coffee
|
58
|
+
- js/lib/form-tag-inputs.js
|
59
|
+
- js/lib/path-helper.coffee
|
60
|
+
- js/lib/path-helper.js
|
56
61
|
- MIT-LICENSE
|
57
62
|
- Rakefile
|
58
63
|
- Gemfile
|