~caneypuggies/reformedchurcheslocator/couchapp-backbone

« back to all changes in this revision

Viewing changes to _attachments/js/vendor/requirejs-plugins/README.mdown

  • Committer: Tim Black
  • Date: 2013-09-16 22:50:16 UTC
  • Revision ID: tim@alwaysreformed.com-20130916225016-zk8jiba25z33ew7h
Versioned Bower vendor directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# RequireJS plugins
 
2
 
 
3
Small set of plugins for [RequireJS](http://requirejs.org). Some plugins may
 
4
also work on other AMD loaders (never tested it).
 
5
 
 
6
For more plugins check [RequireJS Wiki](https://github.com/jrburke/requirejs/wiki/Plugins).
 
7
 
 
8
 
 
9
 
 
10
## Plugins
 
11
 
 
12
 - **async** : Useful for JSONP and asynchronous dependencies (e.g. Google Maps).
 
13
 - **font** : Load web fonts using the [WebFont Loader API](https://code.google.com/apis/webfonts/docs/webfont_loader.html)
 
14
   (requires `propertyParser`)
 
15
 - **goog** : Load [Google APIs](http://code.google.com/apis/loader/)
 
16
   asynchronously (requires `async!` plugin and `propertyParser`).
 
17
 - **image** : Load image files as dependencies. Option to "cache bust".
 
18
 - **json** : Load JSON files and parses the result. (Requires `text!` plugin).
 
19
 - **mdown** : Load Markdown files and parses into HTML. (Requires `text!`
 
20
   plugin and a markdown converter).
 
21
 - **noext** : Load scripts without appending ".js" extension, useful for
 
22
   dynamic scripts.
 
23
 
 
24
### Other
 
25
 
 
26
 - **propertyParser** : Just a helper used by some plugins to parse
 
27
   arguments (not a real plugin).
 
28
 
 
29
 
 
30
 
 
31
## Documentation
 
32
 
 
33
check the `examples` folder. All the info you probably need will be inside
 
34
comments or on the example code itself.
 
35
 
 
36
 
 
37
 
 
38
## Basic usage
 
39
 
 
40
Put the plugins inside the `baseUrl` folder (usually same folder as the main.js
 
41
file) or create an alias to the plugin location:
 
42
 
 
43
```js
 
44
require.config({
 
45
    paths : {
 
46
        //create alias to plugins (not needed if plugins are on the baseUrl)
 
47
        async: 'lib/require/async',
 
48
        font: 'lib/require/font',
 
49
        goog: 'lib/require/goog',
 
50
        image: 'lib/require/image',
 
51
        json: 'lib/require/json',
 
52
        noext: 'lib/require/noext',
 
53
        mdown: 'lib/require/mdown',
 
54
        propertyParser : 'lib/require/propertyParser',
 
55
        markdownConverter : 'lib/Markdown.Converter'
 
56
    }
 
57
});
 
58
 
 
59
//use plugins as if they were at baseUrl
 
60
define([
 
61
        'image!awsum.jpg',
 
62
        'json!data/foo.json',
 
63
        'noext!js/bar.php',
 
64
        'mdown!data/lorem_ipsum.md',
 
65
        'async!http://maps.google.com/maps/api/js?sensor=false',
 
66
        'goog!visualization,1,packages:[corechart,geochart]',
 
67
        'goog!search,1',
 
68
        'font!google,families:[Tangerine,Cantarell]'
 
69
    ], function(awsum, foo, bar, loremIpsum){
 
70
        //all dependencies are loaded (including gmaps and other google apis)
 
71
    }
 
72
);
 
73
```
 
74
 
 
75
 
 
76
## Removing plugin code after build
 
77
 
 
78
[r.js](https://github.com/jrburke/r.js/blob/master/build/example.build.js)
 
79
nowadays have the `stubModules` setting which can be used to remove the whole
 
80
plugin code:
 
81
 
 
82
```js
 
83
({
 
84
    // will remove whole source code of "json" and "text" plugins during build
 
85
    // JSON/text files that are bundled during build will still work fine but
 
86
    // you won't be able to load JSON/text files dynamically after build
 
87
    stubModules : ['json', 'text']
 
88
})
 
89
```
 
90
 
 
91
 
 
92
## Notes about the Markdown plugin
 
93
 
 
94
The Markdown plugin was created mainly to be used to compile the markdown files
 
95
into HTML during the build step, if you set `pragmasOnSave.excludeMdown=true`
 
96
it will remove the `Markdown.Converter.js` and `mdown.js` files from the build.
 
97
Example build settings:
 
98
 
 
99
```js
 
100
({
 
101
    baseUrl : './',
 
102
    pragmasOnSave : {
 
103
        excludeMdown : true
 
104
    },
 
105
    paths : {
 
106
        mdown : 'lib/requirejs/mdown',
 
107
        text : 'lib/requirejs/text',
 
108
        markdownConverter : 'lib/Markdown.Converter'
 
109
    },
 
110
    modules : {
 
111
        name : 'main'
 
112
    }
 
113
})
 
114
```
 
115
 
 
116
If `excludeMdown=true` you won't be able to load markdown files dynamically
 
117
after the build.
 
118
 
 
119
 
 
120
 
 
121
## Writing your own plugins
 
122
 
 
123
Check [RequireJS documentation](http://requirejs.org/docs/plugins.html) for
 
124
a basic reference and use other plugins as reference. RequireJS official
 
125
plugins are a good source for learning.
 
126
 
 
127
Also be sure to check [RequireJS Wiki](https://github.com/jrburke/requirejs/wiki/Plugins).
 
128
 
 
129
 
 
130
 
 
131
## Author
 
132
 
 
133
[Miller Medeiros](http://blog.millermedeiros.com/)
 
134
 
 
135
 
 
136
 
 
137
## License
 
138
 
 
139
All the plugins are released under the MIT license.