Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

adjusting patches to work well when the expanded requires are available adding polyfill supports. #48

Merged
merged 11 commits into from

4 participants

@caridy
Owner

changes:

  • patches do not rely on locator info anymore, only yui modules.
  • remove the server template.get patch since it was depending on locator
  • server and client feature parity for all patches that are common
  • adding cache layer for all patches (e.g.: mod.templatesExpanded)
  • normalizing patches to receive Y and loader in case the patch requires to run before the loader gets ready.
@caridy
Owner

This PR is blocked by yui/yui3#1590

@ekashida
Owner

This PR is self-contained and is not blocked by yui/yui3#1590

@caridy
Owner

guys, this PR is ready to be merged, need a full review.

/cc @ekashida @ericf @juandopazo

P.S.: this is mostly yui patches, and we don't have unit tests for those yet.

@caridy caridy no more differencies between server patches and client patches. yui p…
…atches should not be bound to app instance anymore. removing server-template-get since it depends on locator bundles, and we want to walk away from it
ce1517b
@ekashida
Owner

+1

lib/patches/lang-bundles-requires.js
((23 lines not shown))
if (mod.langBundles) {
- lang = (Y.config.lang && Y.config.lang[0]) || Y.config.lang || 'en'; // TODO: nasty hack
- for (i = 0; i < mod.langBundles.length; i += 1) {
- m = this.getModule(mod.group + '-lang-' + mod.langBundles[i] + '_' + Y.config.lang);
+ len = mod.langBundles.length;
+ // TODO: we are picking up the first lang for now, be we could do better
@ericf Owner
ericf added a note

Would the "do better" mean loading a lang module module for every locale in the array?

@caridy Owner
caridy added a note

yes, that's probably accurate, getting all of them ready in the runtime so the app can decide which one to use depending of the lang passed into Y.Intl.get(), I will do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/patches/optional-requires.js
((30 lines not shown))
- var i, m;
- if (!mod) {
- return [];
- }
- if (mod._parsed) {
- return mod.expanded || [];
+module.exports = function patchOptionalRequires(Y, loader) {
+ var getRequires = loader.getRequires,
+ addModule = loader.addModule,
+ globalOptionalTests = Y.config.optionalTests;
+ // patching `addModule` method to support polyfills
+ loader.addModule = function (mod) {
+ var configFn;
+ if (mod.tests) {
+ configFn = mod.configFn;
+ mod.configFn = function (mod) {
@ericf Owner
ericf added a note

Is it fine to be changing this on the module? Would this have affect on other YUI instances on the page?

@caridy Owner
caridy added a note

I'm doing a doBefore here with the configFn. It is safe since configFn is called once during the lifetime of the global YUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/patches/optional-requires.js
((36 lines not shown))
+module.exports = function patchOptionalRequires(Y, loader) {
+ var getRequires = loader.getRequires,
+ addModule = loader.addModule,
+ globalOptionalTests = Y.config.optionalTests;
+ // patching `addModule` method to support polyfills
+ loader.addModule = function (mod) {
+ var configFn;
+ if (mod.tests) {
+ configFn = mod.configFn;
+ mod.configFn = function (mod) {
+ var i, len = mod.tests;
+ for (i = 0; i <= len; i += 1) {
+ if (typeof mod.tests[i] === 'string') {
+ mod.tests[i] = globalOptionalTests[mod.tests[i]];
+ }
+ if (!mod.tests[i](Y)) {
@ericf Owner
ericf added a note

This could throw if the string test name was wrong. Should we give a useful error in that case that the name was spelled wrong or didn't exist?

@ericf Owner
ericf added a note

I think comments above this line would be good to explain how these differ from the feature tests that are supported in YUI already.

@caridy Owner
caridy added a note

will add the comment and the proper error for missing tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/patches/optional-requires.js
((74 lines not shown))
m = this.getModule(mod.optionalRequires[i]);
if (m) {
- mod.requires.push(m.name);
+ r = [].concat(this.getRequires(m), [m.name], r);
@ericf Owner
ericf added a note

This is confusing to me… which getRequires() is being called here?

@caridy Owner
caridy added a note

loader.getRequires() returns the list of required modules for a particular mod, this line is calling loader.getRequires() for each of the modules in optionalRequires, so we can aggregate those requirements to the final requirements of the host module. I will add some docs around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ericf
Owner

The lang and template patches look similar… would it be worth having a common function that they share that's well documented?

@caridy
Owner

@ericf in the latest revision, lang and templates are definitely different, specially because lang uses the current lang, and template doesn't, but I get the point here is that patches are functions without any sort of abstraction or dependencies, they are just AOP patches.

@ericf
Owner

LGTM

@caridy caridy merged commit 061dc9e into yahoo:master

1 check passed

Details default The Travis CI build passed
@caridy
Owner
  • express-yui@1.1.1
@caridy caridy deleted the caridy:polyfills branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 22, 2014
  1. @bertrandom
  2. @caridy

    Merge pull request #46 from bertrandom/master

    caridy authored
    Fix patch name and require example in docs
Commits on Feb 4, 2014
  1. @caridy

    improving the lang detection on the client side when it comes to atta…

    caridy authored
    …ch the proper lang bundles modules
  2. @caridy
  3. @caridy
Commits on Feb 6, 2014
  1. @caridy

    feature parity between server and client lang bundles resolution. thi…

    caridy authored
    …s add supports for missing bundles on server and client
  2. @caridy

    no more differencies between server patches and client patches. yui p…

    caridy authored
    …atches should not be bound to app instance anymore. removing server-template-get since it depends on locator bundles, and we want to walk away from it
Commits on Feb 11, 2014
  1. @caridy
  2. @caridy
  3. @caridy

    cleaning up optionalRequires

    caridy authored
  4. @caridy
This page is out of date. Refresh to see the latest.
Showing with 390 additions and 182 deletions.
  1. +4 −4 apidocs/api.js
  2. +1 −1  apidocs/assets/css/main.css
  3. +1 −1  apidocs/classes/ExpressYUI.html
  4. +1 −1  apidocs/classes/client.html
  5. +1 −1  apidocs/classes/loader-patch.html
  6. +1 −1  apidocs/classes/middleware.html
  7. +1 −1  apidocs/classes/origin.html
  8. +1 −1  apidocs/classes/seed.html
  9. +1 −1  apidocs/classes/server.html
  10. +1 −1  apidocs/classes/utils.html
  11. +1 −1  apidocs/classes/yui.html
  12. +4 −4 apidocs/data.json
  13. +1 −1  apidocs/files/lib_client.js.html
  14. +1 −1  apidocs/files/lib_index.js.html
  15. +1 −1  apidocs/files/lib_loader-patch.js.html
  16. +1 −1  apidocs/files/lib_middleware.js.html
  17. +1 −1  apidocs/files/lib_origin.js.html
  18. +1 −1  apidocs/files/lib_patches_lang-bundles-requires.js.html
  19. +1 −1  apidocs/files/lib_patches_optional-requires.js.html
  20. +1 −1  apidocs/files/lib_patches_server-intl-get.js.html
  21. +1 −1  apidocs/files/lib_patches_server-template-get.js.html
  22. +3 −3 apidocs/files/lib_patches_templates-requires.js.html
  23. +1 −1  apidocs/files/lib_seed.js.html
  24. +1 −1  apidocs/files/lib_server.js.html
  25. +1 −1  apidocs/files/lib_utils.js.html
  26. +1 −1  apidocs/files/lib_yui.js.html
  27. +1 −1  apidocs/index.html
  28. +1 −1  apidocs/modules/express-yui.html
  29. +1 −1  apidocs/modules/express-yui_lib_client.html
  30. +1 −1  apidocs/modules/express-yui_lib_loader-patches.html
  31. +1 −1  apidocs/modules/express-yui_lib_middleware.html
  32. +1 −1  apidocs/modules/express-yui_lib_origin.html
  33. +1 −1  apidocs/modules/express-yui_lib_patches_lang-bundles-requires.html
  34. +1 −1  apidocs/modules/express-yui_lib_patches_optional-requires.html
  35. +1 −1  apidocs/modules/express-yui_lib_patches_server-intl-get.html
  36. +1 −1  apidocs/modules/express-yui_lib_patches_server-template-get.html
  37. +4 −4 ...ess-yui_lib_patches_templates-bundles-requires.html → express-yui_lib_patches_templates-requires.html}
  38. +1 −1  apidocs/modules/express-yui_lib_seed.html
  39. +1 −1  apidocs/modules/express-yui_lib_server.html
  40. +1 −1  apidocs/modules/express-yui_lib_utils.html
  41. +1 −1  apidocs/modules/express-yui_lib_yui.html
  42. +1 −1  lib/loader-patch.js
  43. +25 −8 lib/patches/lang-bundles-requires.js
  44. +20 −24 lib/patches/optional-requires.js
  45. +16 −33 lib/patches/server-intl-get.js
  46. +0 −54 lib/patches/server-template-get.js
  47. +10 −5 lib/patches/templates-requires.js
  48. +1 −1  lib/server.js
  49. +3 −3 package.json
  50. +0 −1  tests/units/middleware-test.js
  51. +158 −0 tests/units/patches/land-bundles-requires.js
  52. +104 −0 tests/units/patches/templates-requires.js
View
8 apidocs/api.js
@@ -21,7 +21,7 @@ YUI.add("yuidoc-meta", function(Y) {
"express-yui_lib_patches_optional-requires",
"express-yui_lib_patches_server-intl-get",
"express-yui_lib_patches_server-template-get",
- "express-yui_lib_patches_templates-bundles-requires",
+ "express-yui_lib_patches_templates-requires",
"express-yui_lib_seed",
"express-yui_lib_server",
"express-yui_lib_utils",
@@ -74,9 +74,9 @@ YUI.add("yuidoc-meta", function(Y) {
"description": "Patches `Y.Template.get` to use the templates produced by\n`locator-handlebars` or any other similar plugin, and will be available\nthru locator's bundle objects on the server side.\n\n app.yui.patchServer(require('express-yui/lib/patches/server-template-get'));\n\nThen you can use this in your program:\n\n Y.Template.get('foo');\n\nThis will resolve `foo` as a template from the default locator\nbundle, which is normally a file in `templates/foo.handlebars` or any other template\nengine that is available, and that it was transpiled into a module by `locator-handlebars`."
},
{
- "displayName": "express-yui/lib/patches/templates-bundles-requires",
- "name": "express-yui_lib_patches_templates-bundles-requires",
- "description": "Patches `Y.Loader` to support `templates` requirements, which enables you to\nrequire templates easily without having to know the name of the module\ngenerated by the build transpiler/plugin/task while define modules.\n\nYou can write your modules like this:\n\n YUI.add('name', function (Y) {\n // module code...\n }, '0.1', { requires: [], templates: ['foo'] });\n\nAnd you can enable the patch like this:\n\n app.yui.patch(require('express-yui/lib/patches/templates-bundles-requires'));\n\nThis will guarantee, that the template denotated by the logical name `foo`\nwill be loaded. Of course, it will be loaded based on the transpiler\noutput, which generates a more complex module name. If you don't use this patch, you will\nhave to use the full name of the generated module."
+ "displayName": "express-yui/lib/patches/templates-requires",
+ "name": "express-yui_lib_patches_templates-requires",
+ "description": "Patches `Y.Loader` to support `templates` requirements, which enables you to\nrequire templates easily without having to know the name of the module\ngenerated by the build transpiler/plugin/task while define modules.\n\nYou can write your modules like this:\n\n YUI.add('name', function (Y) {\n // module code...\n }, '0.1', { requires: [], templates: ['foo'] });\n\nAnd you can enable the patch like this:\n\n app.yui.patch(require('express-yui/lib/patches/templates-requires'));\n\nThis will guarantee, that the template denotated by the logical name `foo`\nwill be loaded. Of course, it will be loaded based on the transpiler\noutput, which generates a more complex module name. If you don't use this patch, you will\nhave to use the full name of the generated module."
},
{
"displayName": "express-yui/lib/seed",
View
2  apidocs/assets/css/main.css
@@ -98,7 +98,7 @@ code, kbd, pre, samp {
line-height: 1.35;
}
-p code, p kbd, p samp {
+p code, p kbd, p samp, li code {
background: #FCFBFA;
border: 1px solid #EFEEED;
padding: 0 3px;
View
2  apidocs/classes/ExpressYUI.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/client.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/loader-patch.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/middleware.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/origin.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/seed.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/server.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/utils.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/classes/yui.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
8 apidocs/data.json
@@ -45,7 +45,7 @@
"lib/patches/templates-requires.js": {
"name": "lib/patches/templates-requires.js",
"modules": {
- "express-yui/lib/patches/templates-bundles-requires": 1
+ "express-yui/lib/patches/templates-requires": 1
},
"classes": {},
"fors": {},
@@ -196,8 +196,8 @@
"line": 9,
"description": "Patches `Y.Template.get` to use the templates produced by\n`locator-handlebars` or any other similar plugin, and will be available\nthru locator's bundle objects on the server side.\n\n app.yui.patchServer(require('express-yui/lib/patches/server-template-get'));\n\nThen you can use this in your program:\n\n Y.Template.get('foo');\n\nThis will resolve `foo` as a template from the default locator\nbundle, which is normally a file in `templates/foo.handlebars` or any other template\nengine that is available, and that it was transpiled into a module by `locator-handlebars`."
},
- "express-yui/lib/patches/templates-bundles-requires": {
- "name": "express-yui/lib/patches/templates-bundles-requires",
+ "express-yui/lib/patches/templates-requires": {
+ "name": "express-yui/lib/patches/templates-requires",
"submodules": {},
"classes": {},
"fors": {},
@@ -205,7 +205,7 @@
"tag": "module",
"file": "lib/patches/templates-requires.js",
"line": 9,
- "description": "Patches `Y.Loader` to support `templates` requirements, which enables you to\nrequire templates easily without having to know the name of the module\ngenerated by the build transpiler/plugin/task while define modules.\n\nYou can write your modules like this:\n\n YUI.add('name', function (Y) {\n // module code...\n }, '0.1', { requires: [], templates: ['foo'] });\n\nAnd you can enable the patch like this:\n\n app.yui.patch(require('express-yui/lib/patches/templates-bundles-requires'));\n\nThis will guarantee, that the template denotated by the logical name `foo`\nwill be loaded. Of course, it will be loaded based on the transpiler\noutput, which generates a more complex module name. If you don't use this patch, you will\nhave to use the full name of the generated module."
+ "description": "Patches `Y.Loader` to support `templates` requirements, which enables you to\nrequire templates easily without having to know the name of the module\ngenerated by the build transpiler/plugin/task while define modules.\n\nYou can write your modules like this:\n\n YUI.add('name', function (Y) {\n // module code...\n }, '0.1', { requires: [], templates: ['foo'] });\n\nAnd you can enable the patch like this:\n\n app.yui.patch(require('express-yui/lib/patches/templates-requires'));\n\nThis will guarantee, that the template denotated by the logical name `foo`\nwill be loaded. Of course, it will be loaded based on the transpiler\noutput, which generates a more complex module name. If you don't use this patch, you will\nhave to use the full name of the generated module."
},
"express-yui/lib/client": {
"name": "express-yui/lib/client",
View
2  apidocs/files/lib_client.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_index.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_loader-patch.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_middleware.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_origin.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_patches_lang-bundles-requires.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_patches_optional-requires.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_patches_server-intl-get.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_patches_server-template-get.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
6 apidocs/files/lib_patches_templates-requires.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
@@ -151,14 +151,14 @@ <h1 class="file-heading">File: lib/patches/templates-requires.js</h1>
And you can enable the patch like this:
- app.yui.patch(require(&#x27;express-yui/lib/patches/templates-bundles-requires&#x27;));
+ app.yui.patch(require(&#x27;express-yui/lib/patches/templates-requires&#x27;));
This will guarantee, that the template denotated by the logical name &#x60;foo&#x60;
will be loaded. Of course, it will be loaded based on the transpiler
output, which generates a more complex module name. If you don&#x27;t use this patch, you will
have to use the full name of the generated module.
-@module express-yui/lib/patches/templates-bundles-requires
+@module express-yui/lib/patches/templates-requires
**/
module.exports = function (Y) {
var getRequires = Y.Env._loader.getRequires;
View
2  apidocs/files/lib_seed.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_server.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_utils.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/files/lib_yui.js.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/index.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="./modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="./modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="./modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="./modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_client.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_loader-patches.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_middleware.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_origin.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_patches_lang-bundles-requires.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_patches_optional-requires.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_patches_server-intl-get.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_patches_server-template-get.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
8 ...b_patches_templates-bundles-requires.html → ...s-yui_lib_patches_templates-requires.html
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
- <title>express-yui/lib/patches/templates-bundles-requires - express-yui API documentation</title>
+ <title>express-yui/lib/patches/templates-requires - express-yui API documentation</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
@@ -126,7 +126,7 @@ <h2 class="off-left">APIs</h2>
<div class="apidocs">
<div id="docs-main">
<div class="content">
- <h1>express-yui_lib_patches_templates-bundles-requires Module</h1>
+ <h1>express-yui_lib_patches_templates-requires Module</h1>
<div class="box clearfix meta">
@@ -152,7 +152,7 @@ <h2 class="off-left">APIs</h2>
// module code...
}, &#39;0.1&#39;, { requires: [], templates: [&#39;foo&#39;] });</code></pre>
<p>And you can enable the patch like this:</p>
-<pre class="code prettyprint"><code>app.yui.patch(require(&#39;express-yui/lib/patches/templates-bundles-requires&#39;));</code></pre>
+<pre class="code prettyprint"><code>app.yui.patch(require(&#39;express-yui/lib/patches/templates-requires&#39;));</code></pre>
<p>This will guarantee, that the template denotated by the logical name <code>foo</code>
will be loaded. Of course, it will be loaded based on the transpiler
output, which generates a more complex module name. If you don&#39;t use this patch, you will
View
2  apidocs/modules/express-yui_lib_seed.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_server.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_utils.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  apidocs/modules/express-yui_lib_yui.html
@@ -81,7 +81,7 @@ <h2 class="off-left">APIs</h2>
<li><a href="../modules/express-yui_lib_patches_server-template-get.html">express-yui/lib/patches/server-template-get</a></li>
- <li><a href="../modules/express-yui_lib_patches_templates-bundles-requires.html">express-yui/lib/patches/templates-bundles-requires</a></li>
+ <li><a href="../modules/express-yui_lib_patches_templates-requires.html">express-yui/lib/patches/templates-requires</a></li>
<li><a href="../modules/express-yui_lib_seed.html">express-yui/lib/seed</a></li>
View
2  lib/loader-patch.js
@@ -51,7 +51,7 @@ module.exports = {
Adds patches that will be applied to the YUI instance
before the initial `use` statement on the server side.
- app.yui.patchServer(require('express-yui/lib/patches/server-template-get'));
+ app.yui.patchServer(require('express-yui/lib/patches/server-intl-get'));
@method patchServer
@public
View
33 lib/patches/lang-bundles-requires.js
@@ -31,20 +31,37 @@ the `requires` list.
module.exports = function patchLangBundlesRequires(Y, loader) {
var getRequires = loader.getRequires;
loader.getRequires = function (mod) {
- var i, len, m, lang, name,
+ var i, j, m, name, mods,
+ locales = Y.config.lang || [],
r = getRequires.apply(this, arguments);
// expanding requirements with optional requires
- if (mod.langBundles) {
- len = mod.langBundles.length;
- lang = (Y.config.lang && Y.config.lang[0]) || Y.config.lang || 'en'; // TODO: nasty hack
+ if (mod.langBundles && !mod.langBundlesExpanded) {
+ mod.langBundlesExpanded = [];
+ locales = typeof locales === 'string' ? [locales] : locales.concat();
for (i = 0; i < mod.langBundles.length; i += 1) {
+ mods = [];
name = mod.group + '-lang-' + mod.langBundles[i];
- m = this.getModule(name + '_' + Y.config.lang) || this.getModule(name);
- if (m) {
- r = [].concat(this.getRequires(m), [m.name], r);
+ for (j = 0; j < locales.length; j += 1) {
+ m = this.getModule(name + '_' + locales[j].toLowerCase());
+ if (m) {
+ mods.push(m);
+ }
+ }
+ if (!mods.length) {
+ // falling back to the default lang bundle when needed
+ m = this.getModule(name);
+ if (m) {
+ mods.push(m);
+ }
+ }
+ // adding requirements for each lang bundle
+ // (duplications are not a problem since they will be deduped)
+ for (j = 0; j < mods.length; j += 1) {
+ mod.langBundlesExpanded = mod.langBundlesExpanded.concat(this.getRequires(mods[j]), [mods[j].name]);
}
}
}
- return r;
+ return mod.langBundlesExpanded && mod.langBundlesExpanded.length ?
+ [].concat(mod.langBundlesExpanded, r) : r;
};
};
View
44 lib/patches/optional-requires.js
@@ -11,8 +11,12 @@ Patches `Y.Loader` to support `optionalRequires`, which enables you to
require modules that might not be available in a runtime, and avoid to
throw when that happens.
+!IMPORTANT/TODO: this patch can be removed once we get [PR1629][] merged
+into YUI.
+[PR1629]: https://github.com/yui/yui3/pull/1629
+
It also add support for modules that are essencially polyfills,
-this means that some modules can only be used if some tests are passed first
+this means that some modules can only be used if the test is passed first
otherwise they should be ignored.
This helps when it comes to define modules that are only available on
@@ -21,11 +25,9 @@ them as optionals.
app.yui.patch(require('express-yui/lib/patches/optional-requires'));
-When this patch is applied, you can add a new entry called `tests` in the
-metas for a module, this entry is an array of strings or functions, strings
-are used for named tests that were previously attached under `Y.config.tests`,
-in case you want to reuse those tests between different modules. If any of the
-tests fails, the module will be automatically discarded.
+When this patch is applied, you can add a new entry called `test` in the
+metas for a module, this entry is a functions. If the test fails, the module
+will be automatically discarded.
Note that the `optional` implementation in YUI does not cover this case,
and it only covers the case where the module was required or not by another
@@ -35,26 +37,18 @@ module in the `use` statement, which is not quite the same.
**/
module.exports = function patchOptionalRequires(Y, loader) {
var getRequires = loader.getRequires,
- addModule = loader.addModule,
- globalOptionalTests = Y.config.optionalTests;
+ addModule = loader.addModule;
// patching `addModule` method to support polyfills
loader.addModule = function (mod) {
- var configFn;
- if (mod.tests) {
- configFn = mod.configFn;
+ var configFn = mod && mod.configFn;
+ if (mod && mod.test) {
mod.configFn = function (mod) {
- var i, len = mod.tests;
- for (i = 0; i <= len; i += 1) {
- if (typeof mod.tests[i] === 'string') {
- mod.tests[i] = globalOptionalTests[mod.tests[i]];
- }
- if (!mod.tests[i](Y)) {
- // if a test fails, the polyfill should be dropped
- return false;
- }
+ if (!mod.test(Y)) {
+ // if a test fails, the module should be dropped from the registry
+ return false;
}
if (configFn) {
- // falling back to the original configFn if all tests passed
+ // falling back to the original configFn if the test passed
return configFn.apply(this, arguments);
}
};
@@ -66,15 +60,17 @@ module.exports = function patchOptionalRequires(Y, loader) {
var i, len, m,
r = getRequires.apply(this, arguments);
// expanding requirements with optional requires
- if (mod.optionalRequires) {
+ if (mod.optionalRequires && !mod.optionalRequiresExpanded) {
+ mod.optionalRequiresExpanded = [];
len = mod.optionalRequires.length;
for (i = 0; i < len; i += 1) {
m = this.getModule(mod.optionalRequires[i]);
if (m) {
- r = [].concat(this.getRequires(m), [m.name], r);
+ mod.optionalRequiresExpanded = mod.optionalRequiresExpanded.concat(this.getRequires(m), [m.name]);
}
}
}
- return r;
+ return mod.optionalRequiresExpanded && mod.optionalRequiresExpanded.length ?
+ [].concat(mod.optionalRequiresExpanded, r) : r;
};
};
View
49 lib/patches/server-intl-get.js
@@ -15,46 +15,29 @@ objects on the server side. You can apply this patch like this:
Then you can use this in your program:
- Y.Intl.get('foo');
+ Y.Intl.get('<bundleName>/foo');
-This will resolve `foo` as a language bundle from the default locator
-bundle, which is normally a file in `lang/foo.json` or `lang/foo.yrb`
+This will resolve `foo` as a language bundle from the bundle specified by name,
+which is normally a file in `lang/foo.json` or `lang/foo.yrb`
that was transpiled into a module by `locator-lang`.
@module express-yui/lib/patches/server-intl-get
**/
-module.exports = function patchIntlGet(Y, loader, app) {
- // monkey patching Y.Intl
- var locator = app.get('locator'),
- // looking in the root bundle (hermes has only one bundle)
- // that's the most common use-case where the app bundle holds all lang bundles
- rootBundle = locator.getRootBundle(),
- originalInltGet = Y.use('intl').Intl.get;
+module.exports = function patchIntlGet(Y, loader) {
+ // monkey patching Y.Intl.get
+ var originalInltGet = Y.use('intl').Intl.get,
+ checked = {}; // internal hash for perf reasons since `loader.getModule()` might be expensive
Y.Intl.get = function (name, key, lang) {
- var pos = name.indexOf('/'),
- bundleName,
- bundle,
- langBundle = name;
-
- function output(entries) {
- // returning a specific key or all entries (todo: should be make a copy?)
- return (key ? entries[key] : entries);
- }
-
- if (pos > 0) {
- bundleName = name.slice(0, pos);
- langBundle = name.slice(pos + 1, name.length);
+ var modName, i,
+ locales = (typeof lang === 'string' ? [lang] : (lang || [])).concat();
+ for (i = 0; i < locales.length; i += 1) {
+ // infering the name of the module from the lang bundle name
+ modName = name.replace('/', '-lang-') + '_' + locales[i].toLowerCase();
+ if (!checked[modName] && loader.getModule(modName)) {
+ Y.use(modName); // useSync should be set
+ }
+ checked[modName] = true;
}
- bundle = bundleName ? locator.getBundle(bundleName) : rootBundle;
- if (bundle.lang && bundle.lang[lang] && bundle.lang[lang][langBundle]) {
- return output(bundle.lang[lang][langBundle]);
- }
- // if the lang bundle is not in the specified bundle, look for a global/root lang bundle
- if (bundle !== rootBundle && rootBundle.lang && rootBundle.lang[lang] && rootBundle.lang[lang][name]) {
- return output(rootBundle.lang[lang][name]);
- }
-
- // fallbacking back to the original implementation
return originalInltGet.apply(this, arguments);
};
};
View
54 lib/patches/server-template-get.js
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2013, Yahoo! Inc. All rights reserved.
- * Copyrights licensed under the New BSD License.
- * See the accompanying LICENSE file for terms.
- */
-
-/*jslint node:true, nomen: true */
-
-/**
-Patches `Y.Template.get` to use the templates produced by
-`locator-handlebars` or any other similar plugin, and will be available
-thru locator's bundle objects on the server side.
-
- app.yui.patchServer(require('express-yui/lib/patches/server-template-get'));
-
-Then you can use this in your program:
-
- Y.Template.get('foo');
-
-This will resolve `foo` as a template from the default locator
-bundle, which is normally a file in `templates/foo.handlebars` or any other template
-engine that is available, and that it was transpiled into a module by `locator-handlebars`.
-
-@module express-yui/lib/patches/server-template-get
-**/
-module.exports = function patchTemplateGet(Y, loader, app) {
- // monkey patching Y.Template
- var locator = app.get('locator'),
- // looking in the root bundle (hermes has only one bundle)
- // that's the most common use-case where the app bundle holds all templates
- rootBundle = locator.getRootBundle(),
- originalTemplateGet = Y.use('template-base').Template.get;
-
- Y.Template.get = function (name) {
- var pos = name.indexOf('/'),
- bundleName,
- bundle,
- template = name;
- if (pos > 0) {
- bundleName = name.slice(0, pos);
- template = name.slice(pos + 1, name.length);
- }
- bundle = bundleName ? locator.getBundle(bundleName) : rootBundle;
- if (bundle.template && bundle.template[template]) {
- return bundle.template[template];
- }
- // if the template is not in the specified bundle, look for a global/root template
- if (bundle !== rootBundle && rootBundle.template && rootBundle.template[name]) {
- return rootBundle.template[name];
- }
- // falling back to the original implementation
- return originalTemplateGet.apply(this, arguments);
- };
-};
View
15 lib/patches/templates-requires.js
@@ -19,14 +19,14 @@ You can write your modules like this:
And you can enable the patch like this:
- app.yui.patch(require('express-yui/lib/patches/templates-bundles-requires'));
+ app.yui.patch(require('express-yui/lib/patches/templates-requires'));
This will guarantee, that the template denotated by the logical name `foo`
will be loaded. Of course, it will be loaded based on the transpiler
output, which generates a more complex module name. If you don't use this patch, you will
have to use the full name of the generated module.
-@module express-yui/lib/patches/templates-bundles-requires
+@module express-yui/lib/patches/templates-requires
**/
module.exports = function patchTemplatesRequires(Y, loader) {
var getRequires = loader.getRequires;
@@ -34,15 +34,20 @@ module.exports = function patchTemplatesRequires(Y, loader) {
var i, len, m,
r = getRequires.apply(this, arguments);
// expanding requirements with templates required
- if (mod.templates) {
+ if (mod.templates && !mod.templatesExpanded) {
len = mod.templates.length;
+ mod.templatesExpanded = [];
for (i = 0; i < len; i += 1) {
m = this.getModule(mod.group + '-template-' + mod.templates[i]);
if (m) {
- r = [].concat(this.getRequires(m), [m.name], r);
+ mod.templatesExpanded = mod.templatesExpanded.concat(this.getRequires(m), [m.name]);
+ } else {
+ throw new Error('Invalid template [' + mod.templates[i] + '], module [' +
+ mod.group + '-template-' + mod.templates[i] + '] is not registered.');
}
}
}
- return r;
+ return mod.templatesExpanded && mod.templatesExpanded.length ?
+ [].concat(mod.templatesExpanded, r) : r;
};
};
View
2  lib/server.js
@@ -197,7 +197,7 @@ module.exports = {
// patching serverside Y
if (this._patches && this._patches.length) {
this._patches.forEach(function (patch) {
- patch(Y, Y.Env._loader, this._app);
+ patch(Y, Y.Env._loader);
}, this);
}
}
View
6 package.json
@@ -55,9 +55,9 @@
"url": "https://github.com/yahoo/express-yui/issues"
},
"scripts": {
- "pretest": "jshint {lib,tests/units}/*.js",
- "test": "node ./node_modules/ytestrunner/lib/cli.js -c --include tests/units/**/*.js",
- "unit": "node ./node_modules/ytestrunner/lib/cli.js --include tests/units/**/*.js",
+ "pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/",
+ "test": "node ./node_modules/ytestrunner/lib/cli.js -c --include tests/units/**/**/*.js",
+ "unit": "node ./node_modules/ytestrunner/lib/cli.js --include tests/units/**/**/*.js",
"lint": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/",
"docs": "node ./node_modules/.bin/yuidoc --config ./conf/yuidoc.json ./lib"
}
View
1  tests/units/middleware-test.js
@@ -127,7 +127,6 @@ suite.add(new YUITest.TestCase({
callCount: 2,
run: function (data, ns) {
if (ns === 'window.YUI_config') {
- console.log(data);
A.areEqual(config, data, 'exposed data should');
} else {
A.areEqual('window.app.yui', ns, 'exposed data should');
View
158 tests/units/patches/land-bundles-requires.js
@@ -0,0 +1,158 @@
+/*
+* Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+* Copyrights licensed under the New BSD License.
+* See the accompanying LICENSE file for terms.
+*/
+
+/*jslint node:true, nomen:true*/
+
+'use strict';
+
+var YUITest = require('yuitest'),
+ Assert = YUITest.Assert,
+ patch = require('../../../lib/patches/lang-bundles-requires.js'),
+ Y,
+ loader,
+ suite;
+
+suite = new YUITest.TestSuite('patches/lang-bundles-requires test suite');
+
+suite.add(new YUITest.TestCase({
+ name: 'Y.config.lang tests',
+
+ setUp: function () {
+ loader = {
+ _mockGetModule: function () {},
+ _mockGetRequires: function () {
+ return ['bar'];
+ },
+ getRequires: function () { return this._mockGetRequires.apply(this, arguments); },
+ getModule: function () { return this._mockGetModule.apply(this, arguments); }
+ };
+ Y = { config: {} };
+ },
+
+ tearDown: function () {
+ loader = null;
+ Y = null;
+ },
+
+ 'test undefined lang': function () {
+ var p = patch(Y, loader);
+ var r = loader.getRequires({ name: 'foo', requires: [], langBundles: ['unkown'] });
+ Assert.areEqual(1, r.length, 'Foo only requires bar');
+ },
+
+ 'test empty lang': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = '';
+ var r = loader.getRequires({ name: 'foo', requires: [], langBundles: ['unkown'] });
+ Assert.areEqual(1, r.length, 'Foo only requires bar');
+ },
+
+ 'test unknown lang': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = 'cu-CU';
+ var r = loader.getRequires({ name: 'foo', requires: [], langBundles: ['unkown'] });
+ Assert.areEqual(1, r.length, 'Foo only requires bar');
+ },
+
+ 'test empty array lang': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = [];
+ var r = loader.getRequires({ name: 'foo', requires: [], langBundles: ['unkown'] });
+ Assert.areEqual(1, r.length, 'Foo only requires bar');
+ },
+
+ 'test array lang with unkown lang': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = ['cu-CU'];
+ var r = loader.getRequires({ name: 'foo', requires: [], langBundles: ['unkown'] });
+ Assert.areEqual(1, r.length, 'Foo only requires bar');
+ }
+
+}));
+
+suite.add(new YUITest.TestCase({
+ name: 'fallback to default bundles tests',
+
+ setUp: function () {
+ loader = {
+ _mockGetModule: function (name) {
+ return {
+ 'all-lang-bar': {
+ name: 'all-lang-bar'
+ },
+ 'all-lang-bar_fr-fr': {
+ name: 'all-lang-bar_fr-fr'
+ }
+ }[name];
+ },
+ _mockGetRequires: function (mod) {
+ return {
+ 'foo': ['original', 'extra'],
+ 'all-lang-bar': ['intl'],
+ 'all-lang-bar_fr-fr': ['intl']
+ }[mod.name] || [];
+ },
+ getRequires: function () { return this._mockGetRequires.apply(this, arguments); },
+ getModule: function () { return this._mockGetModule.apply(this, arguments); }
+ };
+ Y = { config: {} };
+ },
+
+ tearDown: function () {
+ loader = null;
+ Y = null;
+ },
+
+ 'test simple langBundle with undefined lang': function () {
+ var p = patch(Y, loader);
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ langBundles: ['bar']
+ });
+ Assert.areEqual([ 'intl', 'all-lang-bar', 'original', 'extra'].join(','), r.join(','),
+ 'default lang bundle should be picked');
+ },
+
+ 'test simple langBundle with unavailable lang': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = 'cu-CU';
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ langBundles: ['bar']
+ });
+ Assert.areEqual([ 'intl', 'all-lang-bar', 'original', 'extra'].join(','), r.join(','),
+ 'default lang bundle should be picked');
+ },
+
+ 'test simple langBundle with a good lang': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = 'fr-FR';
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ langBundles: ['bar']
+ });
+ Assert.areEqual([ 'intl', 'all-lang-bar_fr-fr', 'original', 'extra'].join(','), r.join(','),
+ 'fr-FR lang bundle should be picked');
+ },
+
+ 'test simple langBundle with a good array of langs': function () {
+ var p = patch(Y, loader);
+ Y.config.lang = ['fr-FR'];
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ langBundles: ['bar']
+ });
+ Assert.areEqual([ 'intl', 'all-lang-bar_fr-fr', 'original', 'extra'].join(','), r.join(','),
+ 'fr-FR lang bundle should be picked');
+ }
+
+}));
+
+YUITest.TestRunner.add(suite);
View
104 tests/units/patches/templates-requires.js
@@ -0,0 +1,104 @@
+/*
+* Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+* Copyrights licensed under the New BSD License.
+* See the accompanying LICENSE file for terms.
+*/
+
+/*jslint node:true, nomen:true*/
+
+'use strict';
+
+var YUITest = require('yuitest'),
+ Assert = YUITest.Assert,
+ patch = require('../../../lib/patches/templates-requires.js'),
+ Y,
+ loader,
+ suite;
+
+suite = new YUITest.TestSuite('patches/templates-requires test suite');
+
+suite.add(new YUITest.TestCase({
+ name: 'fallback to default bundles tests',
+
+ setUp: function () {
+ loader = {
+ _mockGetModule: function (name) {
+ return {
+ 'all-template-bar': {
+ name: 'all-template-bar'
+ },
+ 'all-template-baz': {
+ name: 'all-template-baz'
+ }
+ }[name];
+ },
+ _mockGetRequires: function (mod) {
+ return {
+ 'foo': ['original', 'extra'],
+ 'all-template-bar': ['template-base'],
+ 'all-template-baz': ['template-base']
+ }[mod.name] || [];
+ },
+ getRequires: function () { return this._mockGetRequires.apply(this, arguments); },
+ getModule: function () { return this._mockGetModule.apply(this, arguments); }
+ };
+ Y = { config: {} };
+ },
+
+ tearDown: function () {
+ loader = null;
+ Y = null;
+ },
+
+ _should: {
+ error: {
+ "test invalid template": true
+ }
+ },
+
+ 'test empty template': function () {
+ var p = patch(Y, loader);
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ templates: []
+ });
+ Assert.areEqual(['original', 'extra'].join(','), r.join(','),
+ 'default requirements for foo');
+ },
+
+ 'test one template': function () {
+ var p = patch(Y, loader);
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ templates: ['bar']
+ });
+ Assert.areEqual(['template-base', 'all-template-bar', 'original', 'extra'].join(','), r.join(','),
+ 'bar and its requirements should be included');
+ },
+
+ 'test two templates': function () {
+ var p = patch(Y, loader);
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ templates: ['bar', 'baz']
+ });
+ Assert.areEqual(['template-base', 'all-template-bar', 'template-base', 'all-template-baz', 'original', 'extra'].join(','), r.join(','),
+ 'bar, baz and their requirements should be included');
+ },
+
+ 'test invalid template': function () {
+ var p = patch(Y, loader);
+ var r = loader.getRequires({
+ name: 'foo',
+ group: 'all',
+ templates: ['invalid']
+ });
+ // this should throw
+ }
+
+}));
+
+YUITest.TestRunner.add(suite);
Something went wrong with that request. Please try again.