omf_web 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/omf_web_server +18 -0
- data/example/bridge/README.md +7 -0
- data/example/bridge/data_sources/sensor-sqlite.rb +15 -15
- data/example/bridge/htdocs/graph/js/bridge.js +35 -45
- data/example/bridge/htdocs/graph/js/event_line_chart.js +20 -18
- data/example/bridge/htdocs/graph/js/event_table.js +26 -28
- data/example/bridge/viz_server.rb +5 -9
- data/example/demo/demo_viz_server.rb +2 -2
- data/example/demo/widgets/linked_graphs_tab.yaml +9 -32
- data/example/openflow-gec15/code_tab.yaml +7 -12
- data/example/openflow-gec15/dashboard_tab.yaml +11 -12
- data/example/openflow-gec15/exp_source.rb +26 -26
- data/example/openflow-gec15/of_viz_server.rb +7 -7
- data/example/simple/simple.yaml +2 -1
- data/example/simple/simple_dynamic.yaml +1 -1
- data/example/web_rtc/web_rtc.yaml +54 -0
- data/example/web_rtc/webrtc-exp_1381786573.sq3 +0 -0
- data/lib/omf-web/config.ru +1 -1
- data/lib/omf-web/content/content_proxy.rb +2 -2
- data/lib/omf-web/content/file_repository.rb +11 -53
- data/lib/omf-web/content/git_repository.rb +1 -1
- data/lib/omf-web/content/irods_repository.rb +1 -1
- data/lib/omf-web/content/repository.rb +5 -3
- data/lib/omf-web/content/static_repository.rb +25 -11
- data/lib/omf-web/data_source_proxy.rb +3 -3
- data/lib/omf-web/rack/content_handler.rb +2 -2
- data/lib/omf-web/rack/session_authenticator.rb +3 -3
- data/lib/omf-web/rack/tab_mapper.rb +2 -2
- data/lib/omf-web/rack/update_handler.rb +2 -2
- data/lib/omf-web/rack/websocket_handler.rb +3 -3
- data/lib/omf-web/rack/widget_mapper.rb +2 -2
- data/lib/omf-web/session_store.rb +2 -2
- data/lib/omf-web/theme/abstract_page.rb +15 -24
- data/lib/omf-web/theme/bright/code_renderer.rb +24 -30
- data/lib/omf-web/theme/bright/data_renderer.rb +7 -5
- data/lib/omf-web/theme/bright/page.rb +2 -1
- data/lib/omf-web/theme/bright/widget_chrome.rb +16 -14
- data/lib/omf-web/theme.rb +1 -1
- data/lib/omf-web/thin/logging.rb +18 -13
- data/lib/omf-web/thin/runner.rb +2 -2
- data/lib/omf-web/thin/server.rb +105 -27
- data/lib/omf-web/version.rb +1 -1
- data/lib/omf-web/widget/abstract_widget.rb +3 -3
- data/lib/omf-web/widget/data_widget.rb +1 -0
- data/lib/omf-web/widget/text/maruku.rb +1 -1
- data/lib/omf-web/widget.rb +22 -22
- data/lib/omf_web.rb +1 -1
- data/omf_web.gemspec +18 -15
- data/share/htdocs/graph/js/abstract_chart.js +69 -68
- data/share/htdocs/graph/js/abstract_nv_chart.js +35 -33
- data/share/htdocs/graph/js/abstract_widget.js +61 -62
- data/share/htdocs/graph/js/axis.js +30 -25
- data/share/htdocs/graph/js/barchart_brush.js +23 -21
- data/share/htdocs/graph/js/code_mirror.js +35 -33
- data/share/htdocs/graph/js/discrete_bar_chart.js +27 -30
- data/share/htdocs/graph/js/histogram2.js +37 -47
- data/share/htdocs/graph/js/line_chart3.js +36 -30
- data/share/htdocs/graph/js/line_chart_with_focus.js +10 -9
- data/share/htdocs/graph/js/multi_barchart.js +33 -30
- data/share/htdocs/graph/js/network2.js +98 -97
- data/share/htdocs/graph/js/pie_chart2.js +25 -23
- data/share/htdocs/graph/js/scatter_plot.js +38 -36
- data/share/htdocs/graph/js/table2.js +60 -54
- data/share/htdocs/js/app.js +43 -0
- data/share/htdocs/js/{data_source2.js → data_source3.js} +44 -73
- data/share/htdocs/js/data_source_repo.js +42 -0
- data/share/htdocs/require/nv_d3.js +2 -0
- data/share/htdocs/theme/abstract/abstract.js +4 -4
- data/share/htdocs/vendor/VERSION_MAP.yaml +2 -0
- data/share/htdocs/vendor/require-2.1.8/require.js +2053 -0
- data/share/htdocs/vendor/require-2.1.8/require.min.js +36 -0
- data/share/htdocs/vendor/require-css-0.0.7/.gitignore +1 -0
- data/share/htdocs/vendor/require-css-0.0.7/LICENSE +10 -0
- data/share/htdocs/vendor/require-css-0.0.7/README.md +231 -0
- data/share/htdocs/vendor/require-css-0.0.7/bower.json +5 -0
- data/share/htdocs/vendor/require-css-0.0.7/css-builder.js +251 -0
- data/share/htdocs/vendor/require-css-0.0.7/css.js +436 -0
- data/share/htdocs/vendor/require-css-0.0.7/normalize.js +138 -0
- data/share/htdocs/vendor/require-css-0.0.7/package.json +5 -0
- data/share/htdocs/vendor/spin/jquery.spin.js +6 -4
- metadata +100 -74
- checksums.yaml +0 -7
- data/bin/omf_web_demo +0 -3
- data/bin/omf_web_demo.sh +0 -7
- data/bin/omf_web_server.rb +0 -157
- data/lib/omf_common/lobject.rb +0 -187
- data/lib/omf_common/log4r_outputter.rb +0 -69
- data/sample.sq3 +0 -0
- data/share/htdocs/js/data_source.js +0 -173
- data/share/htdocs/js/require3.js +0 -292
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
RequireJS 2.1.8 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
3
|
+
Available via the MIT or new BSD license.
|
4
|
+
see: http://github.com/jrburke/requirejs for details
|
5
|
+
*/
|
6
|
+
var requirejs,require,define;
|
7
|
+
(function(Z){function H(b){return"[object Function]"===L.call(b)}function I(b){return"[object Array]"===L.call(b)}function y(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function M(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function s(b,c){return ga.call(b,c)}function l(b,c){return s(b,c)&&b[c]}function F(b,c){for(var d in b)if(s(b,d)&&c(b[d],d))break}function Q(b,c,d,h){c&&F(c,function(c,j){if(d||!s(b,j))h&&"string"!==typeof c?(b[j]||(b[j]={}),Q(b[j],
|
8
|
+
c,d,h)):b[j]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function aa(b){throw b;}function ba(b){if(!b)return b;var c=Z;y(b.split("."),function(b){c=c[b]});return c}function A(b,c,d,h){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=h;d&&(c.originalError=d);return c}function ha(b){function c(a,f,b){var e,m,c,g,d,h,j,i=f&&f.split("/");e=i;var n=k.map,p=n&&n["*"];if(a&&"."===a.charAt(0))if(f){e=l(k.pkgs,f)?i=[f]:i.slice(0,i.length-
|
9
|
+
1);f=a=e.concat(a.split("/"));for(e=0;f[e];e+=1)if(m=f[e],"."===m)f.splice(e,1),e-=1;else if(".."===m)if(1===e&&(".."===f[2]||".."===f[0]))break;else 0<e&&(f.splice(e-1,2),e-=2);e=l(k.pkgs,f=a[0]);a=a.join("/");e&&a===f+"/"+e.main&&(a=f)}else 0===a.indexOf("./")&&(a=a.substring(2));if(b&&n&&(i||p)){f=a.split("/");for(e=f.length;0<e;e-=1){c=f.slice(0,e).join("/");if(i)for(m=i.length;0<m;m-=1)if(b=l(n,i.slice(0,m).join("/")))if(b=l(b,c)){g=b;d=e;break}if(g)break;!h&&(p&&l(p,c))&&(h=l(p,c),j=e)}!g&&
|
10
|
+
h&&(g=h,d=j);g&&(f.splice(0,d,g),a=f.join("/"))}return a}function d(a){z&&y(document.getElementsByTagName("script"),function(f){if(f.getAttribute("data-requiremodule")===a&&f.getAttribute("data-requirecontext")===i.contextName)return f.parentNode.removeChild(f),!0})}function h(a){var f=l(k.paths,a);if(f&&I(f)&&1<f.length)return d(a),f.shift(),i.require.undef(a),i.require([a]),!0}function $(a){var f,b=a?a.indexOf("!"):-1;-1<b&&(f=a.substring(0,b),a=a.substring(b+1,a.length));return[f,a]}function n(a,
|
11
|
+
f,b,e){var m,B,g=null,d=f?f.name:null,h=a,j=!0,k="";a||(j=!1,a="_@r"+(L+=1));a=$(a);g=a[0];a=a[1];g&&(g=c(g,d,e),B=l(r,g));a&&(g?k=B&&B.normalize?B.normalize(a,function(a){return c(a,d,e)}):c(a,d,e):(k=c(a,d,e),a=$(k),g=a[0],k=a[1],b=!0,m=i.nameToUrl(k)));b=g&&!B&&!b?"_unnormalized"+(M+=1):"";return{prefix:g,name:k,parentMap:f,unnormalized:!!b,url:m,originalName:h,isDefine:j,id:(g?g+"!"+k:k)+b}}function q(a){var f=a.id,b=l(p,f);b||(b=p[f]=new i.Module(a));return b}function t(a,f,b){var e=a.id,m=l(p,
|
12
|
+
e);if(s(r,e)&&(!m||m.defineEmitComplete))"defined"===f&&b(r[e]);else if(m=q(a),m.error&&"error"===f)b(m.error);else m.on(f,b)}function v(a,f){var b=a.requireModules,e=!1;if(f)f(a);else if(y(b,function(f){if(f=l(p,f))f.error=a,f.events.error&&(e=!0,f.emit("error",a))}),!e)j.onError(a)}function w(){R.length&&(ia.apply(G,[G.length-1,0].concat(R)),R=[])}function x(a){delete p[a];delete T[a]}function E(a,f,b){var e=a.map.id;a.error?a.emit("error",a.error):(f[e]=!0,y(a.depMaps,function(e,c){var g=e.id,
|
13
|
+
d=l(p,g);d&&(!a.depMatched[c]&&!b[g])&&(l(f,g)?(a.defineDep(c,r[g]),a.check()):E(d,f,b))}),b[e]=!0)}function C(){var a,f,b,e,m=(b=1E3*k.waitSeconds)&&i.startTime+b<(new Date).getTime(),c=[],g=[],j=!1,l=!0;if(!U){U=!0;F(T,function(b){a=b.map;f=a.id;if(b.enabled&&(a.isDefine||g.push(b),!b.error))if(!b.inited&&m)h(f)?j=e=!0:(c.push(f),d(f));else if(!b.inited&&(b.fetched&&a.isDefine)&&(j=!0,!a.prefix))return l=!1});if(m&&c.length)return b=A("timeout","Load timeout for modules: "+c,null,c),b.contextName=
|
14
|
+
i.contextName,v(b);l&&y(g,function(a){E(a,{},{})});if((!m||e)&&j)if((z||da)&&!V)V=setTimeout(function(){V=0;C()},50);U=!1}}function D(a){s(r,a[0])||q(n(a[0],null,!0)).init(a[1],a[2])}function J(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!W?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||W)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function K(){var a;for(w();G.length;){a=
|
15
|
+
G.shift();if(null===a[0])return v(A("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));D(a)}}var U,X,i,N,V,k={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},shim:{},config:{}},p={},T={},Y={},G=[],r={},S={},L=1,M=1;N={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){var b=
|
16
|
+
l(k.pkgs,a.map.id);return(b?l(k.config,a.map.id+"/"+b.main):l(k.config,a.map.id))||{}},exports:r[a.map.id]}}};X=function(a){this.events=l(Y,a.id)||{};this.map=a;this.shim=l(k.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};X.prototype={init:function(a,b,c,e){e=e||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=!0;
|
17
|
+
this.ignore=e.ignore;e.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
|
18
|
+
this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var e=this.exports,m=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(H(m)){if(this.events.error&&this.map.isDefine||j.onError!==aa)try{e=i.execCb(c,m,b,e)}catch(d){a=d}else e=i.execCb(c,m,b,e);this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==
|
19
|
+
this.exports?e=b.exports:void 0===e&&this.usingExports&&(e=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",v(this.error=a)}else e=m;this.exports=e;if(this.map.isDefine&&!this.ignore&&(r[c]=e,j.onResourceLoad))j.onResourceLoad(i,this.map,this.depMaps);x(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=
|
20
|
+
!0)}}else this.fetch()}},callPlugin:function(){var a=this.map,b=a.id,d=n(a.prefix);this.depMaps.push(d);t(d,"defined",u(this,function(e){var m,d;d=this.map.name;var g=this.map.parentMap?this.map.parentMap.name:null,h=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(e.normalize&&(d=e.normalize(d,function(a){return c(a,g,!0)})||""),e=n(a.prefix+"!"+d,this.map.parentMap),t(e,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),
|
21
|
+
d=l(p,e.id)){this.depMaps.push(e);if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else m=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),m.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];F(p,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&x(a.map.id)});v(a)}),m.fromText=u(this,function(e,c){var d=a.name,g=n(d),B=O;c&&(e=c);B&&(O=!1);q(g);s(k.config,b)&&(k.config[d]=k.config[b]);try{j.exec(e)}catch(ca){return v(A("fromtexteval",
|
22
|
+
"fromText eval for "+b+" failed: "+ca,ca,[b]))}B&&(O=!0);this.depMaps.push(g);i.completeLoad(d);h([d],m)}),e.load(a.name,h,m,k)}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){T[this.map.id]=this;this.enabling=this.enabled=!0;y(this.depMaps,u(this,function(a,b){var c,e;if("string"===typeof a){a=n(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=l(N,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;t(a,"defined",u(this,function(a){this.defineDep(b,
|
23
|
+
a);this.check()}));this.errback&&t(a,"error",u(this,this.errback))}c=a.id;e=p[c];!s(N,c)&&(e&&!e.enabled)&&i.enable(a,this)}));F(this.pluginMaps,u(this,function(a){var b=l(p,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){y(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:k,contextName:b,registry:p,defined:r,urlFetched:S,defQueue:G,Module:X,makeModuleMap:n,
|
24
|
+
nextTick:j.nextTick,onError:v,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=k.pkgs,c=k.shim,e={paths:!0,config:!0,map:!0};F(a,function(a,b){e[b]?"map"===b?(k.map||(k.map={}),Q(k[b],a,!0,!0)):Q(k[b],a,!0):k[b]=a});a.shim&&(F(a.shim,function(a,b){I(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);c[b]=a}),k.shim=c);a.packages&&(y(a.packages,function(a){a="string"===typeof a?{name:a}:a;b[a.name]={name:a.name,
|
25
|
+
location:a.location||a.name,main:(a.main||"main").replace(ja,"").replace(ea,"")}}),k.pkgs=b);F(p,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=n(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(Z,arguments));return b||a.exports&&ba(a.exports)}},makeRequire:function(a,f){function d(e,c,h){var g,k;f.enableBuildCallback&&(c&&H(c))&&(c.__requireJsBuild=!0);if("string"===typeof e){if(H(c))return v(A("requireargs",
|
26
|
+
"Invalid require call"),h);if(a&&s(N,e))return N[e](p[a.id]);if(j.get)return j.get(i,e,a,d);g=n(e,a,!1,!0);g=g.id;return!s(r,g)?v(A("notloaded",'Module name "'+g+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[g]}K();i.nextTick(function(){K();k=q(n(null,a));k.skipMap=f.skipMap;k.init(e,c,h,{enabled:!0});C()});return d}f=f||{};Q(d,{isBrowser:z,toUrl:function(b){var d,f=b.lastIndexOf("."),g=b.split("/")[0];if(-1!==f&&(!("."===g||".."===g)||1<f))d=b.substring(f,b.length),b=
|
27
|
+
b.substring(0,f);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return s(r,n(b,a,!1,!0).id)},specified:function(b){b=n(b,a,!1,!0).id;return s(r,b)||s(p,b)}});a||(d.undef=function(b){w();var c=n(b,a,!0),f=l(p,b);delete r[b];delete S[c.url];delete Y[b];f&&(f.events.defined&&(Y[b]=f.events),x(b))});return d},enable:function(a){l(p,a.id)&&q(a).enable()},completeLoad:function(a){var b,c,e=l(k.shim,a)||{},d=e.exports;for(w();G.length;){c=G.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===
|
28
|
+
a&&(b=!0);D(c)}c=l(p,a);if(!b&&!s(r,a)&&c&&!c.inited){if(k.enforceDefine&&(!d||!ba(d)))return h(a)?void 0:v(A("nodefine","No define call for "+a,null,[a]));D([a,e.deps||[],e.exportsFn])}C()},nameToUrl:function(a,b,c){var e,d,h,g,i,n;if(j.jsExtRegExp.test(a))g=a+(b||"");else{e=k.paths;d=k.pkgs;g=a.split("/");for(i=g.length;0<i;i-=1)if(n=g.slice(0,i).join("/"),h=l(d,n),n=l(e,n)){I(n)&&(n=n[0]);g.splice(0,i,n);break}else if(h){a=a===h.name?h.location+"/"+h.main:h.location;g.splice(0,i,a);break}g=g.join("/");
|
29
|
+
g+=b||(/\?/.test(g)||c?"":".js");g=("/"===g.charAt(0)||g.match(/^[\w\+\.\-]+:/)?"":k.baseUrl)+g}return k.urlArgs?g+((-1===g.indexOf("?")?"?":"&")+k.urlArgs):g},load:function(a,b){j.load(i,a,b)},execCb:function(a,b,c,e){return b.apply(e,c)},onScriptLoad:function(a){if("load"===a.type||ka.test((a.currentTarget||a.srcElement).readyState))P=null,a=J(a),i.completeLoad(a.id)},onScriptError:function(a){var b=J(a);if(!h(b.id))return v(A("scripterror","Script error for: "+b.id,a,[b.id]))}};i.require=i.makeRequire();
|
30
|
+
return i}var j,w,x,C,J,D,P,K,q,fa,la=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,ma=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,ea=/\.js$/,ja=/^\.\//;w=Object.prototype;var L=w.toString,ga=w.hasOwnProperty,ia=Array.prototype.splice,z=!!("undefined"!==typeof window&&navigator&&window.document),da=!z&&"undefined"!==typeof importScripts,ka=z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,W="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),E={},t={},R=[],O=
|
31
|
+
!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(H(requirejs))return;t=requirejs;requirejs=void 0}"undefined"!==typeof require&&!H(require)&&(t=require,require=void 0);j=requirejs=function(b,c,d,h){var q,n="_";!I(b)&&"string"!==typeof b&&(q=b,I(c)?(b=c,c=d,d=h):b=[]);q&&q.context&&(n=q.context);(h=l(E,n))||(h=E[n]=j.s.newContext(n));q&&h.configure(q);return h.require(b,c,d)};j.config=function(b){return j(b)};j.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,
|
32
|
+
4)}:function(b){b()};require||(require=j);j.version="2.1.8";j.jsExtRegExp=/^\/|:|\?|\.js$/;j.isBrowser=z;w=j.s={contexts:E,newContext:ha};j({});y(["toUrl","undef","defined","specified"],function(b){j[b]=function(){var c=E._;return c.require[b].apply(c,arguments)}});if(z&&(x=w.head=document.getElementsByTagName("head")[0],C=document.getElementsByTagName("base")[0]))x=w.head=C.parentNode;j.onError=aa;j.createNode=function(b){var c=b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):
|
33
|
+
document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};j.load=function(b,c,d){var h=b&&b.config||{};if(z)return h=j.createNode(h,c,d),h.setAttribute("data-requirecontext",b.contextName),h.setAttribute("data-requiremodule",c),h.attachEvent&&!(h.attachEvent.toString&&0>h.attachEvent.toString().indexOf("[native code"))&&!W?(O=!0,h.attachEvent("onreadystatechange",b.onScriptLoad)):(h.addEventListener("load",b.onScriptLoad,!1),h.addEventListener("error",
|
34
|
+
b.onScriptError,!1)),h.src=d,K=h,C?x.insertBefore(h,C):x.appendChild(h),K=null,h;if(da)try{importScripts(d),b.completeLoad(c)}catch(l){b.onError(A("importscripts","importScripts failed for "+c+" at "+d,l,[c]))}};z&&M(document.getElementsByTagName("script"),function(b){x||(x=b.parentNode);if(J=b.getAttribute("data-main"))return q=J,t.baseUrl||(D=q.split("/"),q=D.pop(),fa=D.length?D.join("/")+"/":"./",t.baseUrl=fa),q=q.replace(ea,""),j.jsExtRegExp.test(q)&&(q=J),t.deps=t.deps?t.deps.concat(q):[q],!0});
|
35
|
+
define=function(b,c,d){var h,j;"string"!==typeof b&&(d=c,c=b,b=null);I(c)||(d=c,c=null);!c&&H(d)&&(c=[],d.length&&(d.toString().replace(la,"").replace(ma,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(O){if(!(h=K))P&&"interactive"===P.readyState||M(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return P=b}),h=P;h&&(b||(b=h.getAttribute("data-requiremodule")),j=E[h.getAttribute("data-requirecontext")])}(j?j.defQueue:
|
36
|
+
R).push([b,c,d])};define.amd={jQuery:!0};j.exec=function(b){return eval(b)};j(t)}})(this);
|
@@ -0,0 +1 @@
|
|
1
|
+
example/www-built
|
@@ -0,0 +1,10 @@
|
|
1
|
+
MIT License
|
2
|
+
-----------
|
3
|
+
|
4
|
+
Copyright (C) 2013 Guy Bedford
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require-css
|
2
|
+
===========
|
3
|
+
|
4
|
+
RequireJS CSS requiring and optimization.
|
5
|
+
|
6
|
+
Useful for writing modular CSS dependencies alongside scripts. For an example of widget rendering see [ZestJS](http://zestjs.org).
|
7
|
+
|
8
|
+
For LESS inclusion, use [require-less](https://github.com/guybedford/require-less), which behaves and builds the css exactly like this module apart from the preprocessing step.
|
9
|
+
|
10
|
+
<a href="http://gittip.com/guybedford" target="_blank"><img src="http://badgr.co/gittip/guybedford.png" align="right"></a>
|
11
|
+
|
12
|
+
Overview
|
13
|
+
--------
|
14
|
+
|
15
|
+
Allows the construction of scripts that can require CSS, using the simple RequireJS syntax:
|
16
|
+
|
17
|
+
```javascript
|
18
|
+
define(['css!styles/main'], function() {
|
19
|
+
//code that requires the stylesheet: styles/main.css
|
20
|
+
});
|
21
|
+
```
|
22
|
+
|
23
|
+
### CSS Requiring
|
24
|
+
* Fully compatible in IE 6 - 10, Chrome 3 - 26, Firefox 3.5 - 19, Opera 10 - 12, iOS, Android
|
25
|
+
* Cross-domain style loading
|
26
|
+
* Line numbers in dev inspector correlate with correct CSS file
|
27
|
+
|
28
|
+
### CSS Building
|
29
|
+
* **CSS builds** When run as part of a build with the RequireJS optimizer, `css!` dependencies are automatically inlined into the built layer within the JavaScript, fully compatible with layering. CSS injection is performed as soon as the layer is loaded.
|
30
|
+
* **Option to build separate layer CSS files** A `separateCSS` build parameter allows for built layers to output their css files separately, instead of inline with the JavaScript, for manual inclusion.
|
31
|
+
* **CSS compression** CSS redundancy compression is supported through the external library, [csso](https://github.com/css/csso).
|
32
|
+
|
33
|
+
Installation and Setup
|
34
|
+
----------------------
|
35
|
+
|
36
|
+
Download the require-css folder manually or use [volo](https://github.com/volojs/volo)(`npm install volo -g`):
|
37
|
+
|
38
|
+
```bash
|
39
|
+
volo add guybedford/require-css
|
40
|
+
```
|
41
|
+
|
42
|
+
To allow the direct `css!` usage, add the following [map configuration](http://requirejs.org/docs/api.html#config-map) in RequireJS:
|
43
|
+
|
44
|
+
```javascript
|
45
|
+
map: {
|
46
|
+
'*': {
|
47
|
+
'css': 'require-css/css' // or whatever the path to require-css is
|
48
|
+
}
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
Use Cases and Benefits
|
53
|
+
----------------------
|
54
|
+
|
55
|
+
### Motivation
|
56
|
+
|
57
|
+
The use case for RequireCSS came out of a need to manage templates and their CSS together.
|
58
|
+
The idea being that a CSS require can be a dependency of the code that dynamically renders a template.
|
59
|
+
When writing a large dynamic application, with templates being rendered on the client-side, it can be beneficial to inject the CSS as templates are required instead
|
60
|
+
of dumping all the CSS together separately. The added benefit of this is then being able to build the CSS naturally with the RequireJS optimizer,
|
61
|
+
which also supports [separate build layers](http://requirejs.org/docs/1.0/docs/faq-optimization.html#priority) as needed.
|
62
|
+
|
63
|
+
### Script-inlined CSS Benefits
|
64
|
+
|
65
|
+
By default, during the build CSS is compressed and inlined as a string within the layer that injects the CSS when run.
|
66
|
+
|
67
|
+
If the layer is included as a `<script>` tag, only one browser request is needed instead of many separate CSS requests with `<link>` tags.
|
68
|
+
|
69
|
+
Even better than including a layer as a `<script>` tag is to include the layer dynamically with a non-blocking require.
|
70
|
+
Then the page can be displayed while the layer is still loading asynchronously in the background.
|
71
|
+
In this case, the CSS that goes with a template being dynamically rendered is loaded with that same script asynchronously.
|
72
|
+
No longer does it need to sit in a `<link>` tag that blocks the page display unnecessarily.
|
73
|
+
|
74
|
+
Modular CSS
|
75
|
+
-----------
|
76
|
+
|
77
|
+
RequireCSS implies a CSS modularisation where styles can be scoped directly to the render code that they are bundled with.
|
78
|
+
|
79
|
+
Just like JS requires, the order of CSS injection can't be guaranteed. The idea here is that whenever there are style overrides, they should
|
80
|
+
be based on using a more specific selector with an extra id or class at the base, and not assuming a CSS load order. Reset and global styles are a repeated dependency of all
|
81
|
+
modular styles that build on top of them.
|
82
|
+
|
83
|
+
Optimizer Configuration
|
84
|
+
-----------------------
|
85
|
+
|
86
|
+
### Basic Usage
|
87
|
+
|
88
|
+
Optimizer configuration:
|
89
|
+
|
90
|
+
```javascript
|
91
|
+
{
|
92
|
+
modules: [
|
93
|
+
{
|
94
|
+
name: 'mymodule'
|
95
|
+
}
|
96
|
+
]
|
97
|
+
}
|
98
|
+
```
|
99
|
+
|
100
|
+
If the contents of 'mymodule' are:
|
101
|
+
|
102
|
+
```javascript
|
103
|
+
define(['css!style', 'css!page'], function(css) {
|
104
|
+
//...
|
105
|
+
});
|
106
|
+
```
|
107
|
+
|
108
|
+
Then the optimizer output would be:
|
109
|
+
|
110
|
+
-mymodule.js containing:
|
111
|
+
style.css and page.css which will be dynamically injected
|
112
|
+
|
113
|
+
### Configuration Notes
|
114
|
+
|
115
|
+
In order for the layer to inject the CSS it will make a runtime require to `css`. It is important to ensure that the
|
116
|
+
map configuration locating `css` is provided before this injection in the script.
|
117
|
+
|
118
|
+
If using the standard configuration pattern:
|
119
|
+
|
120
|
+
main.js:
|
121
|
+
```javascript
|
122
|
+
requirejs.config({
|
123
|
+
map: {
|
124
|
+
'*': {
|
125
|
+
'css': 'require-css/css'
|
126
|
+
}
|
127
|
+
}
|
128
|
+
});
|
129
|
+
require(['app']);
|
130
|
+
```
|
131
|
+
|
132
|
+
then the configuration will be written by the optimizer as the last item in the layer, meaning the `css` module will not be located in
|
133
|
+
time for injection.
|
134
|
+
|
135
|
+
To ensure this doesn't happen, use the following configuration pattern:
|
136
|
+
|
137
|
+
main.js:
|
138
|
+
```javascript
|
139
|
+
require(['config'], function() {
|
140
|
+
require(['app']);
|
141
|
+
});
|
142
|
+
```
|
143
|
+
|
144
|
+
Or build the config first into layer using the `create` and `include` build properties.
|
145
|
+
|
146
|
+
[More details here](https://github.com/jrburke/requirejs/pull/595#issuecomment-16346519)
|
147
|
+
|
148
|
+
### Separate File Output
|
149
|
+
|
150
|
+
To output the CSS to a separate file, use the configuration:
|
151
|
+
|
152
|
+
```javascript
|
153
|
+
{
|
154
|
+
separateCSS: true,
|
155
|
+
modules: [
|
156
|
+
{
|
157
|
+
name: 'mymodule'
|
158
|
+
}
|
159
|
+
]
|
160
|
+
}
|
161
|
+
```
|
162
|
+
|
163
|
+
This will then output all the css to the file `mymodule.css`. This configuration can also be placed on the module object itself for layer-specific settings.
|
164
|
+
|
165
|
+
Optimization is fully compatible with exclude and include.
|
166
|
+
|
167
|
+
**Note: Optimization will only work when using r.js version 2.1.0 or later (released Oct 4 2012)**
|
168
|
+
|
169
|
+
|
170
|
+
CSS Compression
|
171
|
+
---------------
|
172
|
+
|
173
|
+
CSS compression is supported with [csso](https://github.com/css/csso).
|
174
|
+
|
175
|
+
To enable the CSS compression, install csso with npm:
|
176
|
+
|
177
|
+
```
|
178
|
+
npm install csso -g
|
179
|
+
```
|
180
|
+
|
181
|
+
The build log will display the compression results.
|
182
|
+
|
183
|
+
When running the r.js optimizer through NodeJS, sometimes the global module isn't found. In this case install csso as a local node module so it can be found.
|
184
|
+
|
185
|
+
|
186
|
+
Conditional CSS
|
187
|
+
---
|
188
|
+
|
189
|
+
Some styles are conditional on the environment. For example mobile stylesheets and IE-specific stylesheets.
|
190
|
+
|
191
|
+
To manage this, use the [Require-IS](https://github.com/guybedford/require-is) module.
|
192
|
+
|
193
|
+
With Require-IS, one can do:
|
194
|
+
|
195
|
+
```javascript
|
196
|
+
require(['is!mobile?css!mobile-css'], function(css) {
|
197
|
+
//...
|
198
|
+
});
|
199
|
+
```
|
200
|
+
|
201
|
+
Mobile detection can be defined through a detection script in Require-IS, such as:
|
202
|
+
|
203
|
+
mobile.js:
|
204
|
+
```javascript
|
205
|
+
define(function() {
|
206
|
+
return navigator.userAgent.match(/iPhone/); //(just iphone detection as an example)
|
207
|
+
});
|
208
|
+
```
|
209
|
+
|
210
|
+
Separate build layers can then be made for mobile specific use. Read more at the [Require-IS](https://github.com/guybedford/require-is) project page.
|
211
|
+
|
212
|
+
Injection methods
|
213
|
+
-----------------
|
214
|
+
|
215
|
+
* When loading a CSS file or external CSS file, a `<link>` tag is used. Cross-browser support comes through a number of careful browser conditions for this.
|
216
|
+
* When using Require-LESS parsing or when injecting CSS from the built `<script>` tag, a CSS `<style>` injection is used.
|
217
|
+
|
218
|
+
If CSS resources such as images are important to be loaded first, these can be added to the require through a loader plugin that can act as a preloader such as [image](https://github.com/millermedeiros/requirejs-plugins) or [font](https://github.com/millermedeiros/requirejs-plugins). Then a require can be written of the form:
|
219
|
+
|
220
|
+
```javascript
|
221
|
+
require(['css!my-css', 'image!preload-background-image.jpg', 'font!google,families:[Tangerine]']);
|
222
|
+
```
|
223
|
+
|
224
|
+
Roadmap
|
225
|
+
-------
|
226
|
+
* ~~Comprehensive CSS minification including style reduction~~
|
227
|
+
* ~~LESS extension~~
|
228
|
+
* Sprite compilation
|
229
|
+
* Source maps?
|
230
|
+
|
231
|
+
Suggestions always appreciated - feel free to post a feature request.
|
@@ -0,0 +1,251 @@
|
|
1
|
+
define(['require', './normalize'], function(req, normalize) {
|
2
|
+
var nodePrint = function() {};
|
3
|
+
if (requirejs.tools)
|
4
|
+
requirejs.tools.useLib(function(req) {
|
5
|
+
req(['node/print'], function(_nodePrint) {
|
6
|
+
nodePrint = _nodePrint;
|
7
|
+
}, function(){});
|
8
|
+
});
|
9
|
+
|
10
|
+
var cssAPI = {};
|
11
|
+
|
12
|
+
function compress(css) {
|
13
|
+
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
|
14
|
+
try {
|
15
|
+
var csso = require.nodeRequire('csso');
|
16
|
+
var csslen = css.length;
|
17
|
+
css = csso.justDoIt(css);
|
18
|
+
nodePrint('Compressed CSS output to ' + Math.round(css.length / csslen * 100) + '%.');
|
19
|
+
return css;
|
20
|
+
}
|
21
|
+
catch(e) {
|
22
|
+
nodePrint('Compression module not installed. Use "npm install csso -g" to enable.');
|
23
|
+
return css;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
nodePrint('Compression not supported outside of nodejs environments.');
|
27
|
+
return css;
|
28
|
+
}
|
29
|
+
|
30
|
+
//load file code - stolen from text plugin
|
31
|
+
function loadFile(path) {
|
32
|
+
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
|
33
|
+
var fs = require.nodeRequire('fs');
|
34
|
+
var file = fs.readFileSync(path, 'utf8');
|
35
|
+
if (file.indexOf('\uFEFF') === 0)
|
36
|
+
return file.substring(1);
|
37
|
+
return file;
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
var file = new java.io.File(path),
|
41
|
+
lineSeparator = java.lang.System.getProperty("line.separator"),
|
42
|
+
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), 'utf-8')),
|
43
|
+
stringBuffer, line;
|
44
|
+
try {
|
45
|
+
stringBuffer = new java.lang.StringBuffer();
|
46
|
+
line = input.readLine();
|
47
|
+
if (line && line.length() && line.charAt(0) === 0xfeff)
|
48
|
+
line = line.substring(1);
|
49
|
+
stringBuffer.append(line);
|
50
|
+
while ((line = input.readLine()) !== null) {
|
51
|
+
stringBuffer.append(lineSeparator).append(line);
|
52
|
+
}
|
53
|
+
return String(stringBuffer.toString());
|
54
|
+
}
|
55
|
+
finally {
|
56
|
+
input.close();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
function saveFile(path, data) {
|
63
|
+
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
|
64
|
+
var fs = require.nodeRequire('fs');
|
65
|
+
fs.writeFileSync(path, data, 'utf8');
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
var content = new java.lang.String(data);
|
69
|
+
var output = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new java.io.FileOutputStream(path), 'utf-8'));
|
70
|
+
|
71
|
+
try {
|
72
|
+
output.write(content, 0, content.length());
|
73
|
+
output.flush();
|
74
|
+
}
|
75
|
+
finally {
|
76
|
+
output.close();
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
//when adding to the link buffer, paths are normalised to the baseUrl
|
82
|
+
//when removing from the link buffer, paths are normalised to the output file path
|
83
|
+
function escape(content) {
|
84
|
+
return content.replace(/(["'\\])/g, '\\$1')
|
85
|
+
.replace(/[\f]/g, "\\f")
|
86
|
+
.replace(/[\b]/g, "\\b")
|
87
|
+
.replace(/[\n]/g, "\\n")
|
88
|
+
.replace(/[\t]/g, "\\t")
|
89
|
+
.replace(/[\r]/g, "\\r");
|
90
|
+
}
|
91
|
+
|
92
|
+
// NB add @media query support for media imports
|
93
|
+
var importRegEx = /@import\s*(url)?\s*(('([^']*)'|"([^"]*)")|\(('([^']*)'|"([^"]*)"|([^\)]*))\))\s*;?/g;
|
94
|
+
|
95
|
+
var loadCSSFile = function(fileUrl) {
|
96
|
+
var css = loadFile(fileUrl);
|
97
|
+
|
98
|
+
// normalize the css (except import statements)
|
99
|
+
css = normalize(css, fileUrl, baseUrl, cssBase);
|
100
|
+
|
101
|
+
// detect all import statements in the css and normalize
|
102
|
+
var importUrls = [];
|
103
|
+
var importIndex = [];
|
104
|
+
var importLength = [];
|
105
|
+
var match;
|
106
|
+
while (match = importRegEx.exec(css)) {
|
107
|
+
var importUrl = match[4] || match[5] || match[7] || match[8] || match[9];
|
108
|
+
|
109
|
+
// normalize import url
|
110
|
+
if (importUrl.substr(importUrl.length - 5, 5) != '.less' && importUrl.substr(importUrl.length - 4, 4) != '.css')
|
111
|
+
importUrl += '.css';
|
112
|
+
|
113
|
+
// contains a protocol
|
114
|
+
if (importUrl.match(/:\/\//))
|
115
|
+
continue;
|
116
|
+
|
117
|
+
// relative to css base
|
118
|
+
if (importUrl.substr(0, 1) == '/' && cssBase)
|
119
|
+
importUrl = cssBase + importUrl;
|
120
|
+
else
|
121
|
+
importUrl = baseUrl + importUrl;
|
122
|
+
|
123
|
+
importUrls.push(importUrl);
|
124
|
+
importIndex.push(importRegEx.lastIndex - match[0].length);
|
125
|
+
importLength.push(match[0].length);
|
126
|
+
}
|
127
|
+
|
128
|
+
// load the import stylesheets and substitute into the css
|
129
|
+
for (var i = 0; i < importUrls.length; i++)
|
130
|
+
(function(i) {
|
131
|
+
var importCSS = loadCSSFile(importUrls[i]);
|
132
|
+
css = css.substr(0, importIndex[i]) + importCSS + css.substr(importIndex[i] + importLength[i]);
|
133
|
+
var lenDiff = importCSS.length - importLength[i];
|
134
|
+
for (var j = i + 1; j < importUrls.length; j++)
|
135
|
+
importIndex[j] += lenDiff;
|
136
|
+
})(i);
|
137
|
+
|
138
|
+
return css;
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
var baseUrl;
|
143
|
+
var cssBase;
|
144
|
+
var curModule;
|
145
|
+
cssAPI.load = function(name, req, load, config, parse) {
|
146
|
+
if (!baseUrl)
|
147
|
+
baseUrl = config.baseUrl;
|
148
|
+
|
149
|
+
if (!cssBase)
|
150
|
+
cssBase = config.cssBase;
|
151
|
+
|
152
|
+
if (config.modules) {
|
153
|
+
//run through the module list - the first one without a layer set is the current layer we are in
|
154
|
+
//allows to track the current layer number for layer-specific config
|
155
|
+
for (var i = 0; i < config.modules.length; i++)
|
156
|
+
if (config.modules[i].layer === undefined) {
|
157
|
+
curModule = i;
|
158
|
+
break;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
//store config
|
163
|
+
cssAPI.config = cssAPI.config || config;
|
164
|
+
|
165
|
+
name += !parse ? '.css' : '.less';
|
166
|
+
|
167
|
+
var fileUrl = req.toUrl(name);
|
168
|
+
|
169
|
+
//external URLS don't get added (just like JS requires)
|
170
|
+
if (fileUrl.substr(0, 7) == 'http://' || fileUrl.substr(0, 8) == 'https://')
|
171
|
+
return;
|
172
|
+
|
173
|
+
//add to the buffer
|
174
|
+
_cssBuffer[name] = loadCSSFile(fileUrl);
|
175
|
+
|
176
|
+
// parse if necessary
|
177
|
+
if (parse)
|
178
|
+
_cssBuffer[name] = parse(_cssBuffer[name]);
|
179
|
+
|
180
|
+
load();
|
181
|
+
}
|
182
|
+
|
183
|
+
cssAPI.normalize = function(name, normalize) {
|
184
|
+
if (name.substr(name.length - 4, 4) == '.css')
|
185
|
+
name = name.substr(0, name.length - 4);
|
186
|
+
return normalize(name);
|
187
|
+
}
|
188
|
+
|
189
|
+
//list of cssIds included in this layer
|
190
|
+
var _layerBuffer = [];
|
191
|
+
var _cssBuffer = [];
|
192
|
+
cssAPI.write = function(pluginName, moduleName, write, parse) {
|
193
|
+
//external URLS don't get added (just like JS requires)
|
194
|
+
if (moduleName.substr(0, 7) == 'http://' || moduleName.substr(0, 8) == 'https://' || moduleName.substr(0, 2) == '//')
|
195
|
+
return;
|
196
|
+
|
197
|
+
var resourceName = moduleName + (!parse ? '.css' : '.less');
|
198
|
+
_layerBuffer.push(_cssBuffer[resourceName]);
|
199
|
+
|
200
|
+
var separateCSS = false;
|
201
|
+
if (cssAPI.config.separateCSS)
|
202
|
+
separateCSS = true;
|
203
|
+
if (typeof curModule == 'number' && cssAPI.config.modules[curModule].separateCSS !== undefined)
|
204
|
+
separateCSS = cssAPI.config.modules[curModule].separateCSS;
|
205
|
+
if (separateCSS)
|
206
|
+
write.asModule(pluginName + '!' + moduleName, 'define(function(){})');
|
207
|
+
else
|
208
|
+
write("requirejs.s.contexts._.nextTick = function(f){f()}; require(['css'], function(css) { css.addBuffer('" + resourceName + "'); }); requirejs.s.contexts._.nextTick = requirejs.nextTick;");
|
209
|
+
}
|
210
|
+
|
211
|
+
cssAPI.onLayerEnd = function(write, data, parser) {
|
212
|
+
firstWrite = true;
|
213
|
+
//separateCSS parameter set either globally or as a layer setting
|
214
|
+
var separateCSS = false;
|
215
|
+
if (cssAPI.config.separateCSS)
|
216
|
+
separateCSS = true;
|
217
|
+
if (typeof curModule == 'number' && cssAPI.config.modules[curModule].separateCSS !== undefined)
|
218
|
+
separateCSS = cssAPI.config.modules[curModule].separateCSS;
|
219
|
+
curModule = null;
|
220
|
+
|
221
|
+
//calculate layer css
|
222
|
+
var css = _layerBuffer.join('');
|
223
|
+
|
224
|
+
if (separateCSS) {
|
225
|
+
nodePrint('Writing CSS! file: ' + data.name + '\n');
|
226
|
+
|
227
|
+
//calculate the css output path for this layer
|
228
|
+
var path = this.config.appDir ? this.config.baseUrl + data.name + '.css' : cssAPI.config.out.replace(/\.js$/, '.css');
|
229
|
+
|
230
|
+
//renormalize the css to the output path
|
231
|
+
var output = compress(normalize(css, baseUrl, path));
|
232
|
+
|
233
|
+
saveFile(path, output);
|
234
|
+
}
|
235
|
+
else {
|
236
|
+
if (css == '')
|
237
|
+
return;
|
238
|
+
//write the injection and layer index into the layer
|
239
|
+
//prepare the css
|
240
|
+
css = escape(compress(css));
|
241
|
+
|
242
|
+
//the code below overrides async require functionality to ensure instant buffer injection
|
243
|
+
write("requirejs.s.contexts._.nextTick = function(f){f()}; require(['css'], function(css) { css.setBuffer('" + css + (parser ? "', true" : "'") + "); }); requirejs.s.contexts._.nextTick = requirejs.nextTick; ");
|
244
|
+
}
|
245
|
+
|
246
|
+
//clear layer buffer for next layer
|
247
|
+
_layerBuffer = [];
|
248
|
+
}
|
249
|
+
|
250
|
+
return cssAPI;
|
251
|
+
});
|