keight 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +263 -0
- data/Rakefile +92 -0
- data/bench/bench.rb +278 -0
- data/bench/benchmarker.rb +502 -0
- data/bin/k8rb +496 -0
- data/keight.gemspec +36 -0
- data/lib/keight/skeleton/.gitignore +10 -0
- data/lib/keight/skeleton/app/action.rb +98 -0
- data/lib/keight/skeleton/app/api/hello.rb +39 -0
- data/lib/keight/skeleton/app/form/.keep +0 -0
- data/lib/keight/skeleton/app/helper/.keep +0 -0
- data/lib/keight/skeleton/app/model/.keep +0 -0
- data/lib/keight/skeleton/app/model.rb +144 -0
- data/lib/keight/skeleton/app/page/welcome.rb +17 -0
- data/lib/keight/skeleton/app/template/_layout.html.eruby +56 -0
- data/lib/keight/skeleton/app/template/welcome.html.eruby +6 -0
- data/lib/keight/skeleton/app/usecase/.keep +0 -0
- data/lib/keight/skeleton/config/app.rb +29 -0
- data/lib/keight/skeleton/config/app_dev.private +11 -0
- data/lib/keight/skeleton/config/app_dev.rb +8 -0
- data/lib/keight/skeleton/config/app_prod.rb +7 -0
- data/lib/keight/skeleton/config/app_stg.rb +5 -0
- data/lib/keight/skeleton/config/app_test.private +11 -0
- data/lib/keight/skeleton/config/app_test.rb +8 -0
- data/lib/keight/skeleton/config/server_puma.rb +22 -0
- data/lib/keight/skeleton/config/server_unicorn.rb +21 -0
- data/lib/keight/skeleton/config/urlpath_mapping.rb +16 -0
- data/lib/keight/skeleton/config.rb +44 -0
- data/lib/keight/skeleton/config.ru +21 -0
- data/lib/keight/skeleton/index.txt +38 -0
- data/lib/keight/skeleton/static/lib/jquery/1.11.3/jquery.min.js +6 -0
- data/lib/keight/skeleton/static/lib/jquery/1.11.3/jquery.min.js.gz +0 -0
- data/lib/keight/skeleton/static/lib/modernizr/2.8.3/modernizr.min.js +4 -0
- data/lib/keight/skeleton/static/lib/modernizr/2.8.3/modernizr.min.js.gz +0 -0
- data/lib/keight/skeleton/tmp/upload/.keep +0 -0
- data/lib/keight.rb +2017 -0
- data/test/data/example1.jpg +0 -0
- data/test/data/example1.png +0 -0
- data/test/data/multipart.form +0 -0
- data/test/data/wabisabi.js +77 -0
- data/test/data/wabisabi.js.gz +0 -0
- data/test/keight_test.rb +3161 -0
- data/test/oktest.rb +1537 -0
- metadata +114 -0
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
/// # -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
///
|
4
|
+
/// very small DOM builder using wabi-sabi style
|
5
|
+
///
|
6
|
+
/// Example:
|
7
|
+
///
|
8
|
+
/// var a = dom(["a", {href: "/link"}, "Link"]);
|
9
|
+
/// console.log(a);
|
10
|
+
/// //=> <a href="/link">Link</a>
|
11
|
+
///
|
12
|
+
/// var ul = dom(
|
13
|
+
/// ["ul#main.foo.bar", {style: "float:left"}
|
14
|
+
/// , ["li", ["a", "AAA"]]
|
15
|
+
/// , ["li", ["a", "BBB"]]
|
16
|
+
/// , ["li.active", ["a", "CCC"]]
|
17
|
+
/// ]
|
18
|
+
/// );
|
19
|
+
/// console.log(ul);
|
20
|
+
/// //=> <ul id="main" class="foo bar" style="float:left">
|
21
|
+
/// // <li><a>AAA</a></li>
|
22
|
+
/// // <li><a>BBB</a></li>
|
23
|
+
/// // <li class="active"><a>CCC</a></li>
|
24
|
+
/// // </ul>
|
25
|
+
///
|
26
|
+
/// License: MIT-License
|
27
|
+
///
|
28
|
+
|
29
|
+
"use strict";
|
30
|
+
|
31
|
+
|
32
|
+
function dom(arr) {
|
33
|
+
/// element
|
34
|
+
/// (ex: span#foo.bar.baz => <span id="foo" class="bar baz">)
|
35
|
+
var tag = arr[0], id = null, cls = null;
|
36
|
+
var m = tag.match(/^([-\w]+)(?:\#([-\w]+))?(?:\.(.*))?/);
|
37
|
+
if (m) { tag = m[1]; id = m[2]; cls = m[3]; }
|
38
|
+
var el = document.createElement(tag);
|
39
|
+
if (id) { el.id = id; }
|
40
|
+
if (cls) { el.className = cls.replace('.', ' '); }
|
41
|
+
/// attributes
|
42
|
+
var attrs = arr[1];
|
43
|
+
if (attrs && typeof attrs === 'object' && ! (attrs instanceof Array)) {
|
44
|
+
for (var k in attrs) {
|
45
|
+
var v = attrs[k];
|
46
|
+
if (v == null) {
|
47
|
+
// pass
|
48
|
+
} else if (v === true || v === false) {
|
49
|
+
el[k] = v; // set as property
|
50
|
+
} else {
|
51
|
+
el.setAttribute(k, v); // set as attribute
|
52
|
+
}
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
attrs = null;
|
56
|
+
}
|
57
|
+
/// children
|
58
|
+
for (var i = attrs ? 2 : 1, n = arr.length; i < n; i++) {
|
59
|
+
var x = arr[i];
|
60
|
+
var t = typeof x;
|
61
|
+
var c;
|
62
|
+
if (x == null || x === "") { c = null; }
|
63
|
+
else if (t === "string" || t === "number" || t === "boolean")
|
64
|
+
{ c = document.createTextNode(x); }
|
65
|
+
else if (t === "function") { c = dom(x(el)); } // TODO: what is the best?
|
66
|
+
else if (x instanceof Array) { c = x.length ? dom(x) : null; }
|
67
|
+
else if (x instanceof Node) { c = x; }
|
68
|
+
else { c = document.createTextNode(x); } // should throw error?
|
69
|
+
if (c) { el.appendChild(c); }
|
70
|
+
}
|
71
|
+
/// special operation!
|
72
|
+
if (tag === "a" && ! el.href) {
|
73
|
+
el.href = "javascript:undefined";
|
74
|
+
}
|
75
|
+
///
|
76
|
+
return el;
|
77
|
+
}
|
Binary file
|