Skip to content

Commit 91b16cf

Browse files
committed
enhance documentation
1 parent ab8c185 commit 91b16cf

File tree

6 files changed

+77
-14
lines changed

6 files changed

+77
-14
lines changed

docs/css.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
---
2-
layout: default
2+
layout: doc
33
title: requirejs-dplugins/css
44
---
55

66
# requirejs-dplugins/css!
77

88
This plugin will load and wait for a css file. This can be handy to load the css
9-
specific to a widget.
9+
specific to any AMD module (like a widget) .
1010

11-
CSS loaded with this plugin can be overwritten by user-defined style sheet, using `<link>` or `<style>` tag.
11+
This plugin uses `<link>` tags to load CSS files and those tags are inserted as the first child of the
12+
`<head>` tag. This guarantees that CSS loaded with this plugin will not overwrite CSS inserted manually using
13+
`<link>` or `<style>` tag.
1214

1315
This plugin will return the path of the inserted css file relative to requirejs baseUrl.
1416

1517
## Example
1618

1719
To load the css file `myproj/comp.css` you can use:
20+
1821
```
1922
require(["requirejs-dplugins/css!myproj/comp.css"], function (){
2023
// Code placed here will wait for myproj/comp.css before running.
@@ -29,3 +32,8 @@ define(["requirejs-dplugins/css!myproj/comp.css"], function (){
2932
});
3033
```
3134

35+
## Build
36+
37+
During the build, this plugin will collect all the CSS files required and create a layer with all the CSS
38+
files concatenated. This layer will be optimized using
39+
[clean-css](https://github.com/jakubpawlowicz/clean-css) if it is installed.

docs/has.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: default
2+
layout: doc
33
title: requirejs-dplugins/has
44
---
55

@@ -10,13 +10,14 @@ title: requirejs-dplugins/has
1010

1111
It is based on the conventions in the [has.js project](https://github.com/phiggins42/has.js).
1212

13-
Note: This plugin does NOT include any feature tests.
13+
__Note:__ This plugin does NOT include any feature tests.
1414

1515
##### Table of Contents
1616
[Features](#features)
1717
[Adding tests](#adding-tests)
1818
[Use as module](#use-as-module)
1919
[Use as plugin](#use-as-plugin)
20+
[Build](#build)
2021

2122
<a name="features"></a>
2223
## Features
@@ -58,6 +59,7 @@ define(["requirejs-dplugins/has"], function (has) {
5859
});
5960
```
6061

62+
<a name="using-static-configuration"></a>
6163
### Using static configuration
6264

6365
The plugin will look for static configuration in a hashmap provided through
@@ -101,9 +103,11 @@ Note that `moduleA` and `moduleB` are optional and if the expression doesn't res
101103
`undefined`.
102104

103105
Ternary operation can be chained to run another test if the first one fails.
106+
104107
```
105108
test1?moduleA:test2?moduleB:moduleC
106109
```
110+
107111
If `test1` is true, the plugin loads `moduleA`.
108112
If `test1` is false but `test2` is true, the plugin loads `moduleB`.
109113
If `test1` is false and `test2` is false, the plugin loads `moduleC`.
@@ -114,3 +118,11 @@ define(["requirejs-dplugins/has!bidi?./bidiWidget:./Widget"], function (widget)
114118
// Do something with the widget
115119
});
116120
```
121+
122+
<a name="build"></a>
123+
## Build
124+
125+
Has flag can be specified at build time using the [static configuration](#using-static-configuration).
126+
If a flag is `undefined` at build time, then all the possible modules will be added to the layer.
127+
If a flag was set to `true` or `false`, the build will resolve the ternary condition and include only the
128+
needed modules in the layer.

docs/i18n.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: default
2+
layout: doc
33
title: requirejs-dplugins/i18n
44
---
55

@@ -20,15 +20,17 @@ title: requirejs-dplugins/i18n
2020
If an application is not built, this plugin will behave exactly like RequireJS i18n plugin.
2121
The only difference is the way they build i18n bundles.
2222

23-
While RequireJS i18n plugin adds bundles of a specified locale to the layer,
23+
While RequireJS i18n plugin adds bundles of a specified locale to the common layer,
2424
`requirejs-dplugins/i18n` will create specific nls layers for each locale specified in the `localesList` option. The
2525
plugin will then load the appropriate nls layer depending on the user locale.
2626

2727

2828
<a name="creating-an-i18n-bundle"></a>
2929
## Creating an i18n bundle
3030

31-
Assume a `my` package, containing a `lamp` module. This module provides a string representing the color of the lamp.
31+
Assume a `my` package, containing a `lamp` module. This module provides a string representing the color of
32+
the lamp.
33+
3234
```js
3335
// my/lamp.js
3436
define([], function() {
@@ -60,6 +62,7 @@ define({
6062
```
6163

6264
This leads to the following directory structure:
65+
6366
```
6467
└── my/
6568
├── nls/
@@ -106,6 +109,7 @@ define({
106109
```
107110

108111
And the following directory structure:
112+
109113
```
110114
└── my/
111115
├── nls/
@@ -119,6 +123,7 @@ And the following directory structure:
119123
* The plugin uses the browser's `navigator.language` or `navigator.userLanguage` property to determine the required
120124
locale. Then it selects the most suitable locale from the root bundle. The locale can also be set using
121125
RequireJS config:
126+
122127
```
123128
require.config({
124129
config: {
@@ -142,6 +147,7 @@ Once the `nls` bundle is setup, the plugin can be used to load the bundle. There
142147
* `requirejs-dplugins/i18n!./nls/locale/bundle` loads the bundle for the `locale` specified in the path.
143148

144149
In the previous setup, if one want to display the color in a user's locale, `my/lamp` need to be updated to:
150+
145151
```js
146152
// my/lamp.js
147153
define(["requirejs-plugins/i18n!./nls/colors"], function(colors) {
@@ -164,6 +170,7 @@ During a build, all i18n bundles required by modules from a layer are concatenat
164170
`nls/layername_locale.js`.
165171

166172
In the previous setup, building a layer `my` containing `my/lamp` results in:
173+
167174
```
168175
└── my/
169176
├── nls/
@@ -222,6 +229,7 @@ Layers can be used in various situation so the plugin offers three options to ad
222229
In this situation, individual bundles are not deployed so the i18n plugin should not look for them.
223230

224231
Hence the runtime configuration should be:
232+
225233
```
226234
requirejs.config({
227235
config: {
@@ -237,6 +245,7 @@ requirejs.config({
237245
In this situation, some individual bundles are deployed but not those already included in a layer.
238246

239247
Hence the runtime configuration should be:
248+
240249
```
241250
requirejs.config({
242251
config: {
@@ -253,6 +262,7 @@ Runtime environment is low-latency so the `languagePack` option can be used to a
253262
in the future.
254263

255264
Hence the runtime configuration should be:
265+
256266
```
257267
requirejs.config({
258268
config: {

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
layout: doc
2+
layout: docMain
33
---
4-
Requirejs-dplugins provides a set of AMD plugins compatible with requirejs.
4+
Requirejs-dplugins provides a set of AMD plugins compatible with requirejs and grunt-amd-build.
55

66
## Plugins
77

docs/jquery.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
layout: default
2+
layout: doc
33
title: requirejs-dplugins/jquery
44
---
55

66
# requirejs-dplugins/jquery!
77

88

9-
This plugin will load load the specified jQuery module(s), unless the application has loaded the whole jQuery
9+
This plugin will load load the specified jQuery AMD module(s), unless the application has loaded the whole jQuery
1010
library via a `<script>` tag, in which case it just returns a pointer to the already loaded jQuery.
1111

1212
It's useful to avoid loading jQuery twice.
@@ -26,3 +26,26 @@ require(["requirejs-dplugins/jquery!attributes/classes,effects"], function ($) {
2626
$(myNode).animate(...);
2727
});
2828
```
29+
30+
## Build
31+
This plugin needs the following AMD loader configuration to work at build time:
32+
33+
```js
34+
{
35+
map: {
36+
jquery: {
37+
"jquery/src/selector": "jquery/src/selector-native" // don't pull in sizzle
38+
}
39+
}
40+
}
41+
```
42+
43+
If the build of this plugin is enabled, it will add the needed AMD jQuery modules to the layer.
44+
If you don't want to include jQuery modules you can add this plugin to the `runtimePlugins` array in
45+
`grunt-amd-build` configuration like this:
46+
47+
```js
48+
{
49+
runtimePlugins: ["requirejs-dplugins/jquery"]
50+
}
51+
```

docs/maybe.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
2-
layout: default
2+
layout: doc
33
title: requirejs-dplugins/maybe
44
---
55

66
# requirejs-dplugins/maybe
77

88
`requirejs-dplugins/maybe` allows to require modules that may or may not exist.
9-
If the module is not found, there is an expected 404 in the console and the module will be `undefined`.
9+
If the module is not found, the loader will not crash (like it would do without this plugin) but there is an
10+
expected 404 and the return value for the module will be `undefined`.
11+
12+
__Note:__ You should use this plugin with caution as requiring multiple nonexistent files will have an impact on
13+
performances.
14+
1015

1116
## Sample
1217
```
@@ -18,3 +23,8 @@ require(["requirejs-dplugins/maybe!a/module/id"], function(module){
1823
}
1924
});
2025
```
26+
27+
## Build
28+
29+
This plugin is not doing anything special at the build. Nothing is added to the layer even if the module
30+
exists.

0 commit comments

Comments
 (0)