rapid-core 0.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +35 -2
  3. data/Rakefile +77 -48
  4. data/doc/server.txt +15 -0
  5. data/features/settings/double-nested/default.feature +2 -2
  6. data/features/settings/double-nested/validates/presence_of.feature +1 -1
  7. data/features/settings/nested/default.feature +1 -1
  8. data/features/settings/nested/validates/presence_of.feature +1 -1
  9. data/features/settings/not_found.feature +2 -2
  10. data/features/step_definitions/settings_steps.rb +7 -3
  11. data/features/step_definitions/template_steps.rb +3 -1
  12. data/lib/rapid/check.rb +30 -23
  13. data/lib/rapid/core.rb +12 -0
  14. data/lib/rapid/error.rb +1 -0
  15. data/lib/rapid/module.rb +10 -1
  16. data/lib/rapid/railtie.rb +6 -0
  17. data/lib/rapid/setting/base.rb +31 -8
  18. data/lib/rapid/setting/boolean_setting.rb +20 -1
  19. data/lib/rapid/setting/definer.rb +11 -47
  20. data/lib/rapid/setting/integer_setting.rb +7 -7
  21. data/lib/rapid/setting/module.rb +56 -0
  22. data/lib/rapid/setting/namespace/base.rb +35 -60
  23. data/lib/rapid/setting/namespace/instance.rb +195 -28
  24. data/lib/rapid/setting/string_setting.rb +7 -1
  25. data/lib/rapid/settings.rb +51 -65
  26. data/lib/rapid/skeleton/base.rb +39 -18
  27. data/lib/rapid/skeleton/helpers/directory.rb +5 -6
  28. data/lib/rapid/skeleton/helpers/files.rb +62 -0
  29. data/lib/rapid/skeleton/helpers/gem.rb +43 -32
  30. data/lib/rapid/skeleton/helpers/if_setting.rb +44 -0
  31. data/lib/rapid/skeleton/helpers/migration.rb +102 -32
  32. data/lib/rapid/skeleton/helpers/route.rb +8 -12
  33. data/lib/rapid/skeleton/helpers/script.rb +1 -2
  34. data/lib/rapid/skeleton/helpers/template.rb +23 -25
  35. data/lib/rapid/skeleton/helpers/view.rb +7 -7
  36. data/lib/rapid/spec/template.rb +1 -1
  37. data/lib/rapid/version.rb +1 -1
  38. data/lib/rapid/web/base.rb +35 -0
  39. data/lib/rapid/web/bootstrap.rb +98 -0
  40. data/lib/rapid/web/controller_helpers.rb +60 -0
  41. data/lib/rapid/web/navigator.rb +18 -0
  42. data/lib/rapid/web/select_helpers.rb +63 -0
  43. data/lib/rapid/web/settings_form_builder.rb +205 -0
  44. data/lib/rapid/web/static_helpers.rb +28 -0
  45. data/lib/rapid/web/tasks.rb +10 -0
  46. data/public/rapid/core/bootstrap-collapse.js +136 -0
  47. data/public/rapid/core/bootstrap-responsive.min.css +3 -0
  48. data/public/rapid/core/bootstrap.min.css +556 -0
  49. data/public/rapid/core/jquery-1.7.1.js +9253 -0
  50. data/public/rapid/core/prettify.css +30 -0
  51. data/public/rapid/core/prettify.js +28 -0
  52. data/rapid-core.gemspec +5 -0
  53. data/spec/rapid/check_spec.rb +11 -4
  54. data/spec/rapid/module_spec.rb +18 -0
  55. data/spec/rapid/setting/base_spec.rb +71 -0
  56. data/spec/rapid/setting/boolean_setting_spec.rb +95 -0
  57. data/spec/rapid/setting/definer_spec.rb +7 -13
  58. data/spec/rapid/setting/integer_setting_spec.rb +49 -0
  59. data/spec/rapid/setting/module_spec.rb +25 -0
  60. data/spec/rapid/setting/namespace/base_spec.rb +88 -54
  61. data/spec/rapid/setting/namespace/instance_spec.rb +308 -5
  62. data/spec/rapid/setting/string_setting_spec.rb +43 -0
  63. data/spec/rapid/settings_spec.rb +65 -17
  64. data/spec/rapid/skeleton/base_spec.rb +113 -7
  65. data/spec/rapid/skeleton/helpers/directory_spec.rb +8 -6
  66. data/spec/rapid/skeleton/helpers/files_spec.rb +93 -0
  67. data/spec/rapid/skeleton/helpers/gem_spec.rb +65 -36
  68. data/spec/rapid/skeleton/helpers/if_setting_spec.rb +110 -0
  69. data/spec/rapid/skeleton/helpers/migration_spec.rb +190 -1
  70. data/spec/rapid/skeleton/helpers/route_spec.rb +13 -12
  71. data/spec/rapid/skeleton/helpers/script_spec.rb +2 -1
  72. data/spec/rapid/skeleton/helpers/template_spec.rb +22 -35
  73. data/spec/rapid/spec/template_spec.rb +1 -1
  74. data/spec/rapid/web/base_spec.rb +33 -0
  75. data/spec/rapid/web/bootstrap_spec.rb +72 -0
  76. data/spec/rapid/web/controller_helpers_spec.rb +86 -0
  77. data/spec/rapid/web/navigator_spec.rb +17 -0
  78. data/spec/rapid/web/select_helpers_spec.rb +71 -0
  79. data/spec/rapid/web/settings_form_builder_spec.rb +255 -0
  80. data/spec/rapid/web/static_helpers_spec.rb +26 -0
  81. data/spec/spec_helper.rb +3 -0
  82. data/views/index.erb +11 -0
  83. data/views/layout.erb +9 -0
  84. metadata +107 -12
  85. data/lib/rapid.rb +0 -37
  86. data/lib/rapid/setting/class_hash.rb +0 -34
  87. data/lib/rapid/setting/instance_hash.rb +0 -132
  88. data/lib/rapid/setting/instance_root.rb +0 -107
  89. data/spec/rapid/setting/instance_root_spec.rb +0 -161
@@ -0,0 +1,30 @@
1
+ .com { color: #93a1a1; }
2
+ .lit { color: #195f91; }
3
+ .pun, .opn, .clo { color: #93a1a1; }
4
+ .fun { color: #dc322f; }
5
+ .str, .atv { color: #D14; }
6
+ .kwd, .linenums .tag { color: #1e347b; }
7
+ .typ, .atn, .dec, .var { color: teal; }
8
+ .pln { color: #48484c; }
9
+
10
+ .prettyprint {
11
+ padding: 8px;
12
+ background-color: #f7f7f9;
13
+ border: 1px solid #e1e1e8;
14
+ }
15
+ .prettyprint.linenums {
16
+ -webkit-box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0;
17
+ -moz-box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0;
18
+ box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0;
19
+ }
20
+
21
+ /* Specify class=linenums on a pre to get line numbering */
22
+ ol.linenums {
23
+ margin: 0 0 0 33px; /* IE indents via margin-left */
24
+ }
25
+ ol.linenums li {
26
+ padding-left: 12px;
27
+ color: #bebec5;
28
+ line-height: 18px;
29
+ text-shadow: 0 1px 0 #fff;
30
+ }
@@ -0,0 +1,28 @@
1
+ var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
2
+ (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a=
3
+ [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c<i;++c){var j=f[c];if(/\\[bdsw]/i.test(j))a.push(j);else{var j=m(j),d;c+2<i&&"-"===f[c+1]?(d=m(f[c+2]),c+=2):d=j;b.push([j,d]);d<65||j>122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;c<b.length;++c)i=b[c],i[0]<=j[1]+1?j[1]=Math.max(j[1],i[1]):f.push(j=i);b=["["];o&&b.push("^");b.push.apply(b,a);for(c=0;c<
4
+ f.length;++c)i=f[c],b.push(e(i[0])),i[1]>i[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c<b;++c){var j=f[c];j==="("?++i:"\\"===j.charAt(0)&&(j=+j.substring(1))&&j<=i&&(d[j]=-1)}for(c=1;c<d.length;++c)-1===d[c]&&(d[c]=++t);for(i=c=0;c<b;++c)j=f[c],j==="("?(++i,d[i]===void 0&&(f[c]="(?:")):"\\"===j.charAt(0)&&
5
+ (j=+j.substring(1))&&j<=i&&(f[c]="\\"+d[i]);for(i=c=0;c<b;++c)"^"===f[c]&&"^"!==f[c+1]&&(f[c]="");if(a.ignoreCase&&s)for(c=0;c<b;++c)j=f[c],a=j.charAt(0),j.length>=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p<d;++p){var g=a[p];if(g.ignoreCase)l=!0;else if(/[a-z]/i.test(g.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){s=!0;l=!1;break}}for(var r=
6
+ {b:8,t:9,n:10,v:11,f:12,r:13},n=[],p=0,d=a.length;p<d;++p){g=a[p];if(g.global||g.multiline)throw Error(""+g);n.push("(?:"+y(g)+")")}return RegExp(n.join("|"),l?"gi":"g")}function M(a){function m(a){switch(a.nodeType){case 1:if(e.test(a.className))break;for(var g=a.firstChild;g;g=g.nextSibling)m(g);g=a.nodeName;if("BR"===g||"LI"===g)h[s]="\n",t[s<<1]=y++,t[s++<<1|1]=a;break;case 3:case 4:g=a.nodeValue,g.length&&(g=p?g.replace(/\r\n?/g,"\n"):g.replace(/[\t\n\r ]+/g," "),h[s]=g,t[s<<1]=y,y+=g.length,
7
+ t[s++<<1|1]=a)}}var e=/(?:^|\s)nocode(?:\s|$)/,h=[],y=0,t=[],s=0,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=document.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);m(a);return{a:h.join("").replace(/\n$/,""),c:t}}function B(a,m,e,h){m&&(a={a:m,d:a},e(a),h.push.apply(h,a.e))}function x(a,m){function e(a){for(var l=a.d,p=[l,"pln"],d=0,g=a.a.match(y)||[],r={},n=0,z=g.length;n<z;++n){var f=g[n],b=r[f],o=void 0,c;if(typeof b===
8
+ "string")c=!1;else{var i=h[f.charAt(0)];if(i)o=f.match(i[1]),b=i[0];else{for(c=0;c<t;++c)if(i=m[c],o=f.match(i[1])){b=i[0];break}o||(b="pln")}if((c=b.length>=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m),
9
+ l=[],p={},d=0,g=e.length;d<g;++d){var r=e[d],n=r[3];if(n)for(var k=n.length;--k>=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
10
+ q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/,
11
+ q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g,
12
+ "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a),
13
+ a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e}
14
+ for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g<d.length;++g)e(d[g]);m===(m|0)&&d[0].setAttribute("value",
15
+ m);var r=s.createElement("OL");r.className="linenums";for(var n=Math.max(0,m-1|0)||0,g=0,z=d.length;g<z;++g)l=d[g],l.className="L"+(g+n)%10,l.firstChild||l.appendChild(s.createTextNode("\xa0")),r.appendChild(l);a.appendChild(r)}function k(a,m){for(var e=m.length;--e>=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*</.test(m)?"default-markup":"default-code";return A[a]}function E(a){var m=
16
+ a.g;try{var e=M(a.h),h=e.a;a.a=h;a.c=e.c;a.d=0;C(m,h)(a);var k=/\bMSIE\b/.test(navigator.userAgent),m=/\n/g,t=a.a,s=t.length,e=0,l=a.c,p=l.length,h=0,d=a.e,g=d.length,a=0;d[g]=s;var r,n;for(n=r=0;n<g;)d[n]!==d[n+2]?(d[r++]=d[n++],d[r++]=d[n++]):n+=2;g=r;for(n=r=0;n<g;){for(var z=d[n],f=d[n+1],b=n+2;b+2<=g&&d[b+1]===f;)b+=2;d[r++]=z;d[r++]=f;n=b}for(d.length=r;h<p;){var o=l[h+2]||s,c=d[a+2]||s,b=Math.min(o,c),i=l[h+1],j;if(i.nodeType!==1&&(j=t.substring(e,b))){k&&(j=j.replace(m,"\r"));i.nodeValue=
17
+ j;var u=i.ownerDocument,v=u.createElement("SPAN");v.className=d[a+1];var x=i.parentNode;x.replaceChild(v,i);v.appendChild(i);e<o&&(l[h+1]=i=u.createTextNode(t.substring(b,o)),x.insertBefore(i,v.nextSibling))}e=b;e>=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
18
+ "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"],
19
+ H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
20
+ J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+
21
+ I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),
22
+ ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",
23
+ /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),
24
+ ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes",
25
+ hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p<h.length&&l.now()<e;p++){var n=h[p],k=n.className;if(k.indexOf("prettyprint")>=0){var k=k.match(g),f,b;if(b=
26
+ !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p<h.length?setTimeout(m,
27
+ 250):a&&a()}for(var e=[document.getElementsByTagName("pre"),document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],h=[],k=0;k<e.length;++k)for(var t=0,s=e[k].length;t<s;++t)h.push(e[k][t]);var e=q,l=Date;l.now||(l={now:function(){return+new Date}});var p=0,d,g=/\blang(?:uage)?-([\w.]+)(?!\S)/;m()};window.PR={createSimpleLexer:x,registerLangHandler:k,sourceDecorator:u,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",
28
+ PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ"}})();
data/rapid-core.gemspec CHANGED
@@ -23,4 +23,9 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency("activemodel", ">= 3.0")
24
24
  s.add_dependency("i18n")
25
25
  s.add_dependency("erubis")
26
+ s.add_dependency("sinatra")
27
+ s.add_dependency("tzinfo")
28
+ s.add_dependency("sinatra_more")
29
+
30
+ s.add_development_dependency("sinatra-reloader")
26
31
  end
@@ -104,16 +104,23 @@ describe Rapid::Check do
104
104
  @check.error_count.should == 1
105
105
  end
106
106
 
107
+ it "should log values" do
108
+ @check = Rapid::Check.new %(
109
+ Rapid::Check.current.log_value :info, 'foo', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
110
+ ), :console => true
111
+
112
+ Rapid.should_receive(:color_puts).with(:info, %( foo: "abcdefghijklmnopqrstuvwx...defghijklmnopqrstuvwxyz"))
113
+ @check.valid?
114
+ end
115
+
107
116
  end
108
117
 
109
118
  it "should tell whether encounters an error" do
110
119
  @check = Rapid::Check.new ""
111
- Rapid::Check.current = @check
112
- Rapid::Check.encounters_error? { @check.error 'hi', 'hi' }.should == true
120
+ @check.encounters_error? { @check.error 'hi', 'hi' }.should == true
113
121
 
114
122
  @check = Rapid::Check.new ""
115
- Rapid::Check.current = @check
116
- Rapid::Check.encounters_error? { @check.warning 'hi', 'hi' }.should == false
123
+ @check.encounters_error? { @check.warning 'hi', 'hi' }.should == false
117
124
  end
118
125
 
119
126
  end
@@ -19,10 +19,28 @@ describe Rapid do
19
19
  Rapid.color_puts :error, "hi"
20
20
  end
21
21
 
22
+ it "should puts info" do
23
+ Rapid.should_receive(:puts).with("\e[90mhi\e[0m")
24
+ Rapid.color_puts :info, "hi"
25
+ end
26
+
22
27
  it "should raise an error when invalid type" do
23
28
  lambda { Rapid.color_puts(:invalid, "hi") }.should raise_error
24
29
  end
25
30
 
26
31
  end
27
32
 
33
+ describe "middleware" do
34
+
35
+ after do
36
+ Rapid.middleware = nil
37
+ end
38
+
39
+ it "should use" do
40
+ Rapid.use_middleware Object
41
+ Rapid.middleware.should == [Object]
42
+ end
43
+
44
+ end
45
+
28
46
  end
@@ -14,4 +14,75 @@ describe Rapid::Setting::Base do
14
14
  lambda { Rapid::Setting::Base.new("valid") }.should raise_error(ArgumentError)
15
15
  end
16
16
 
17
+ it "should tell its parent namespace it exists" do
18
+ @namespace = mock('namespace', :full_name => 'foo')
19
+ @namespace.should_receive(:add_child)
20
+
21
+ @setting = Rapid::Setting::Base.new('hi', :namespace => @namespace)
22
+ end
23
+
24
+ describe "full_name" do
25
+
26
+ it "should be just the name when no parent" do
27
+ @setting = Rapid::Setting::Base.new("hi")
28
+ @setting.full_name.should == "hi"
29
+ @setting.name.should == :hi
30
+ end
31
+
32
+ it "should be include the parent name when a child" do
33
+ @namespace = mock('parent', :full_name => 'foo', :add_child => nil)
34
+ @setting = Rapid::Setting::Base.new("hi", :namespace => @namespace)
35
+ @setting.full_name.should == "foo.hi"
36
+ @setting.name.should == :hi
37
+ end
38
+
39
+ end
40
+
41
+ describe "default_value" do
42
+
43
+ it "should save the default value" do
44
+ @setting = Rapid::Setting::Base.new("hi", :default => "foo")
45
+ @setting.default_value.should == "foo"
46
+ end
47
+
48
+ end
49
+
50
+ describe "define_helpers" do
51
+
52
+ before do
53
+ Object.class_eval do
54
+ class MyClass
55
+
56
+ end
57
+ end
58
+
59
+ @setting = Rapid::Setting::Base.new("hi")
60
+ @setting.define_helpers MyClass
61
+ @instance = MyClass.new
62
+ end
63
+
64
+ after do
65
+ Object.send(:remove_const, :MyClass) rescue nil
66
+ end
67
+
68
+ it "should define a getter" do
69
+ @instance.should_receive(:[]).and_return("foo")
70
+ @instance.hi.should == "foo"
71
+ end
72
+
73
+ it "should definer a getter with a ?" do
74
+ @instance.should_receive(:[]).and_return("foo")
75
+ @instance.hi?.should == true
76
+
77
+ @instance.should_receive(:[]).and_return(nil)
78
+ @instance.hi?.should == false
79
+ end
80
+
81
+ it "should definer a setter" do
82
+ @instance.should_receive(:[]=).with(:hi, 'foo')
83
+ @instance.hi = "foo"
84
+ end
85
+
86
+ end
87
+
17
88
  end
@@ -0,0 +1,95 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Rapid::Setting::BooleanSetting do
4
+
5
+ describe "load" do
6
+
7
+ before do
8
+ @setting = Rapid::Setting::BooleanSetting.new("foo")
9
+ end
10
+
11
+ it "should know nil" do
12
+ @setting.load(nil).should == nil
13
+ end
14
+
15
+ it "should know blank" do
16
+ @setting.load("").should == nil
17
+ end
18
+
19
+ it "should know 0" do
20
+ @setting.load(0).should == false
21
+ end
22
+
23
+ it "should know '0'" do
24
+ @setting.load("0").should == false
25
+ end
26
+
27
+ it "should know false" do
28
+ @setting.load(false).should == false
29
+ end
30
+
31
+ it "should know 'false'" do
32
+ @setting.load("false").should == false
33
+ end
34
+
35
+ it "should know 1" do
36
+ @setting.load(1).should == true
37
+ end
38
+
39
+ it "should know '1'" do
40
+ @setting.load("1").should == true
41
+ end
42
+
43
+ it "should know true" do
44
+ @setting.load(true).should == true
45
+ end
46
+
47
+ it "should know 'true'" do
48
+ @setting.load("true").should == true
49
+ end
50
+
51
+ it "should not know other values" do
52
+ lambda { @setting.load("foo") }.should raise_error(Rapid::InvalidSettingError)
53
+ end
54
+
55
+ end
56
+
57
+ describe "define_helpers" do
58
+
59
+ before do
60
+ Object.class_eval do
61
+ class MyClass
62
+
63
+ end
64
+ end
65
+
66
+ @setting = Rapid::Setting::BooleanSetting.new("foo")
67
+ @setting.define_helpers MyClass
68
+ @instance = MyClass.new
69
+ end
70
+
71
+ after do
72
+ Object.send(:remove_const, :MyClass) rescue nil
73
+ end
74
+
75
+ it "should redefine get? to only return true when the value is true" do
76
+ @instance.should_receive(:[]).with(:foo).and_return(true)
77
+ @instance.foo?.should == true
78
+
79
+ @instance.should_receive(:[]).with(:foo).and_return('hi')
80
+ @instance.foo?.should == false
81
+ end
82
+
83
+ it "should still define getter" do
84
+ @instance.should_receive(:[]).and_return(true)
85
+ @instance.foo.should == true
86
+ end
87
+
88
+ it "should still define setter" do
89
+ @instance.should_receive(:[]=).with(:foo, true)
90
+ @instance.foo = true
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -79,6 +79,12 @@ describe Rapid::Setting::Definer do
79
79
  @instance.foo.bar?.should == false
80
80
  end
81
81
 
82
+ it "should raise an error when defining a setting under a scalar" do
83
+ @definer.string 'foo'
84
+ lambda { @definer.string 'foo.bar' }.should raise_error(Rapid::SettingError)
85
+ lambda { @definer.string 'foo.bar.baz.foo' }.should raise_error(Rapid::SettingError)
86
+ end
87
+
82
88
  end
83
89
 
84
90
  describe "string" do
@@ -162,6 +168,7 @@ describe Rapid::Setting::Definer do
162
168
  @definer.namespace 'my_namespace', :default => false
163
169
 
164
170
  @instance = MyClass.new
171
+ @instance.my_namespace.on?.should be_false
165
172
  @instance.my_namespace?.should be_false
166
173
  @instance.my_namespace = {}
167
174
  @instance.my_namespace?.should be_true
@@ -222,9 +229,6 @@ describe Rapid::Setting::Definer do
222
229
 
223
230
  @instance = MyClass.new
224
231
  @instance.parent.child.should_not be_nil
225
-
226
- @instance.parent.empty?.should == true
227
- @instance.parent.child.empty?.should == true
228
232
  end
229
233
 
230
234
  it "should define a nested setting with default true" do
@@ -232,15 +236,9 @@ describe Rapid::Setting::Definer do
232
236
 
233
237
  @instance = MyClass.new
234
238
 
235
- @instance.parent.empty?.should == false
236
- @instance.parent.child.empty?.should == false
237
-
238
239
  @instance.parent.child?.should be_true
239
240
  @instance.parent.child = nil
240
241
  @instance.parent.child?.should be_false
241
-
242
- @instance.parent.empty?.should == true
243
- @instance.parent.child.empty?.should == true
244
242
  end
245
243
 
246
244
  it "should define a nested setting with default false" do
@@ -248,15 +246,11 @@ describe Rapid::Setting::Definer do
248
246
 
249
247
  @instance = MyClass.new
250
248
 
251
- @instance.parent.empty?.should == true
252
249
  @instance.parent.child.empty?.should == true
253
250
 
254
251
  @instance.parent.child?.should be_false
255
252
  @instance.parent.child = {}
256
253
  @instance.parent.child?.should be_true
257
-
258
- @instance.parent.empty?.should == false
259
- @instance.parent.child.empty?.should == false
260
254
  end
261
255
 
262
256
  end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Rapid::Setting::IntegerSetting do
4
+
5
+ describe "load" do
6
+
7
+ before do
8
+ @setting = Rapid::Setting::IntegerSetting.new("foo")
9
+ end
10
+
11
+ it "should know nil" do
12
+ @setting.load(nil).should == nil
13
+ end
14
+
15
+ it "should know blank" do
16
+ @setting.load("").should == nil
17
+ end
18
+
19
+ it "should know false" do
20
+ @setting.load(false).should == nil
21
+ end
22
+
23
+ it "should know integers" do
24
+ @setting.load(3).should == 3
25
+ end
26
+
27
+ it "should convert strings" do
28
+ @setting.load("3").should == 3
29
+ end
30
+
31
+ it "should not know unconvertable strings" do
32
+ lambda { @setting.load("asdf") }.should raise_error(Rapid::InvalidSettingError)
33
+ end
34
+
35
+ it "should not know floats" do
36
+ lambda { @setting.load(3.5) }.should raise_error(Rapid::InvalidSettingError)
37
+ end
38
+
39
+ it "should not know arrays" do
40
+ lambda { @setting.load([]) }.should raise_error(Rapid::InvalidSettingError)
41
+ end
42
+
43
+ it "should not know hashes" do
44
+ lambda { @setting.load({}) }.should raise_error(Rapid::InvalidSettingError)
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Rapid::Settings do
4
+
5
+ describe "extract_nested_namespace" do
6
+
7
+ it "should return the namespace and rest" do
8
+ Rapid::Settings.extract_nested_namespace("foo.bar").should == ["foo", "bar"]
9
+ end
10
+
11
+ it "should return nil and original when not namespaced" do
12
+ Rapid::Settings.extract_nested_namespace("foo").should == [nil, "foo"]
13
+ end
14
+
15
+ it "should handle nil" do
16
+ Rapid::Settings.extract_nested_namespace(nil).should == [nil, nil]
17
+ end
18
+
19
+ it "should handle a symbol" do
20
+ Rapid::Settings.extract_nested_namespace(:foo).should == [nil, 'foo']
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -2,90 +2,124 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
2
 
3
3
  describe Rapid::Setting::Namespace::Base do
4
4
 
5
- before do
6
- Object.class_eval do
7
- class MySkeleton
8
-
9
- end
10
- end
5
+ it "should accept a nil name" do
6
+ @setting = Rapid::Setting::Namespace::Base.new(nil)
7
+ @setting.name.should == nil
8
+ @setting.full_name.should == nil
9
+ end
10
+
11
+ it "should define settings" do
12
+ @setting = Rapid::Setting::Namespace::Base.new(nil)
11
13
 
12
- @skeleton = MySkeleton.new
14
+ @string = Rapid::Setting::StringSetting.new('foo', :namespace => @setting)
15
+
16
+ @setting['foo'].should == @string
13
17
  end
14
18
 
15
- after do
16
- Object.send(:remove_const, :MySkeleton) rescue nil
19
+ it "should expose child namespaces" do
20
+ @setting = Rapid::Setting::Namespace::Base.new(nil)
21
+ @child = Rapid::Setting::Namespace::Base.new('foo', :namespace => @setting)
22
+
23
+ @setting.namespaces.should == [@child]
24
+ @setting.scalars.should == []
17
25
  end
18
26
 
19
- describe "accessor class" do
27
+ it "should expose child scalars" do
28
+ @setting = Rapid::Setting::Namespace::Base.new(nil)
20
29
 
21
- before do
22
- @namespace = Rapid::Setting::Namespace::Base.new :app, :class => MySkeleton
23
-
24
- @name = Rapid::Setting::StringSetting.new :name, :namespace => @namespace
25
- @version = Rapid::Setting::StringSetting.new :version, :namespace => @namespace
26
-
27
- @namespace.define_setting @name
28
- @namespace.define_setting @version
29
- end
30
+ @string = Rapid::Setting::StringSetting.new('foo', :namespace => @setting)
30
31
 
31
- it "should know the full name" do
32
- @version.full_name.should == "app.version"
33
- end
32
+ @setting.scalars.should == [@string]
33
+ @setting.namespaces.should == []
34
+ end
35
+
36
+ describe "[]" do
34
37
 
35
- it "should initialize a class to hold the accessor methods" do
36
- lambda { MySkeleton::Settings::App }.should_not raise_error
38
+ it "should work with base children" do
39
+ @parent = Rapid::Setting::Namespace::Base.new(nil)
40
+ @child = Rapid::Setting::Namespace::Base.new('foo', :namespace => @parent)
41
+
42
+ @parent['foo'].should == @child
37
43
  end
38
44
 
39
- it "should set the class's setting_name" do
40
- MySkeleton::Settings::App.setting_name.should == "app"
45
+ it "should work with grandchildren" do
46
+ @parent = Rapid::Setting::Namespace::Base.new(nil)
47
+ @child = Rapid::Setting::Namespace::Base.new('foo', :namespace => @parent)
48
+ @grandchild = Rapid::Setting::Namespace::Base.new('bar', :namespace => @child)
49
+
50
+ @parent['foo.bar'].should == @grandchild
41
51
  end
42
52
 
43
- it "should generate the accessor methods" do
44
- @instance = @namespace.load :name => "Dan", :version => "1.0"
45
- @instance.name.should == "Dan"
46
- @instance.version.should == "1.0"
53
+ it "should return nil when invalid key" do
54
+ @parent = Rapid::Setting::Namespace::Base.new(nil)
55
+
56
+ @parent['foo'].should == nil
57
+ @parent['foo.bar'].should == nil
47
58
  end
48
59
 
49
60
  end
50
61
 
51
- describe "two-deep class" do
62
+ describe "define_helpers" do
52
63
 
53
64
  before do
54
- @namespace = Rapid::Setting::Namespace::Base.new :app, :class => MySkeleton
55
- @author = Rapid::Setting::Namespace::Base.new :author, :namespace => @namespace, :class => MySkeleton
65
+ Object.class_eval do
66
+ class MyClass
67
+
68
+ end
69
+ end
70
+
71
+ @setting = Rapid::Setting::Namespace::Base.new("foo")
72
+ @setting.define_helpers MyClass
73
+ @instance = MyClass.new
74
+ end
75
+
76
+ after do
77
+ Object.send(:remove_const, :MyClass) rescue nil
78
+ end
79
+
80
+ it "should redefine get? to only return true when the namespace isn't empty" do
81
+ @instance.should_receive(:[]).with(:foo).and_return(nil)
82
+ @instance.foo?.should == false
56
83
 
57
- @name = Rapid::Setting::StringSetting.new :name, :namespace => @author
58
- @version = Rapid::Setting::StringSetting.new :version, :namespace => @author
84
+ @instance.should_receive(:[]).with(:foo).and_return(mock(:on? => false))
85
+ @instance.foo?.should == false
59
86
 
60
- @namespace.define_setting @author
61
- @author.define_setting @name
62
- @author.define_setting @version
87
+ @instance.should_receive(:[]).with(:foo).and_return(mock(:on? => true))
88
+ @instance.foo?.should == true
63
89
  end
64
90
 
65
- it "should know the full name" do
66
- @version.full_name.should == "app.author.version"
91
+ it "should still define getter" do
92
+ @instance.should_receive(:[]).and_return(true)
93
+ @instance.foo.should == true
67
94
  end
68
95
 
69
- it "should initialize a class to hold the accessor methods" do
70
- lambda { MySkeleton::Settings::App }.should_not raise_error
71
- lambda { MySkeleton::Settings::AppAuthor }.should_not raise_error
96
+ it "should still define setter" do
97
+ @instance.should_receive(:[]=).with(:foo, true)
98
+ @instance.foo = true
72
99
  end
73
100
 
74
- it "should set the class's setting_name" do
75
- MySkeleton::Settings::App.setting_name.should == "app"
76
- MySkeleton::Settings::AppAuthor.setting_name.should == "author"
101
+ end
102
+
103
+ describe "instance_class" do
104
+
105
+ before do
106
+ Object.class_eval do
107
+ class MyClass
108
+
109
+ end
110
+ end
77
111
  end
78
112
 
79
- it "should generate the accessor methods" do
80
- @instance = @namespace.load :author => {:name => "Dan", :version => "1.0"}, :owner => "hi"
81
- @instance.author.name.should == "Dan"
82
- @instance.author.version.should == "1.0"
113
+ after do
114
+ Object.send(:remove_const, :MyClass) rescue nil
83
115
  end
84
116
 
85
- it "should provide access to the owner" do
86
- @instance = @namespace.load :owner => "hi"
87
- @instance._root.should == "hi"
88
- @instance.author._root.should == "hi"
117
+ it "should define the instance class when given :class" do
118
+ @setting = Rapid::Setting::Namespace::Base.new("foo", :class => MyClass)
119
+ @setting.instance_class.name.should == "MyClass::Settings::Foo"
120
+
121
+ @setting.instance_class.setting_name.should == :foo
122
+ @setting.instance_class.full_setting_name.should == "foo"
89
123
  end
90
124
 
91
125
  end