Skip to content

Client, Shared, and Server Code

conoremclaughlin edited this page Jan 22, 2013 · 1 revision

client, shared, and server directories are commonly reserved for code that modifies Bones itself, whether to change or add functionality. This includes prefix and suffix files wrapped around executing code on either the client or the sever.

Methods

  • utils.aliasWrapperForFile(filename, wrapperName) creates an alias for filename to the prefix and suffix files of wrapperName you with to use.
  • utils.compileWrapper(module, filename) reads the file into memory and compiles it with the prefix and suffix wrappers.
  • utils.loadWrappers(dir) loads wrappers from a directory.
  • utils.loadAllWrappers(pluginDir) loads all wrappers from pluginDir/<client|server> and pluginDir/<client|server>/wrappers
  • utils.loadServerPlugin(pluginDir) loads all files in pluginDir/client and pluginDir/shared.
  • utils.wrapClientAll(content) wraps content with pointers to templates, routers, models, views. To be used with a mirror.
  • utils.wrapClientPlugin(content) wraps content with pointers to templates, routers, models, views, Bones. To be used with a mirror.

How To

How do I load my fancy server-side changes for Bones?

Bones.utils.loadServerPlugin(pluginDir);

index.js

Bones.utils.loadServerPlugin(__dirname);

How do I load my fancy file wrappers?

Bones.utils.loadAllWrappers(pluginDir);

index.js

Bones.utils.loadAllWrappers(__dirname);

Where can I find my wrappers?

Wrappers are read into Bones.utils.wrappersServer[<filebasename>] and Bones.utils.wrappersClient[<filebasename>].

Files ending with .bones.js will automatically be wrapped if any prefix or suffix files exist for that kind of file and code location.

How do I use other prefix and suffix for files other than they intended? I just want to wrap my colorize functions like a model!

utils.aliasWrapperForFile(filename, wrapperName) creates an alias for filename to the prefix and suffix files of wrapperName you wish to use.

$ ls server/wrappers
backbone-marionette.prefix.js
backbone-marionette.suffix.js

server/plugin.js

Bones.utils.aliasWrapperForFile('backbone.marionette/lib/backbone.marionette.js', 'backbone-marionette');

How do I use a wrapper for any file?

If the wrapper has been loaded with the same name of the file, utils.compileWrapper(module, filename) will compile the content, prefix, and suffix files into one. Now just require it and will be wrapped. This is automatically done in require for all '.js' files that have had wrappers loaded with the same name.

$ ls server/wrappers
backbone-marionette.prefix.js
backbone-marionette.suffix.js

server/plugin.js

Bones.utils.aliasWrapperForFile('backbone.marionette/lib/backbone.marionette.js', 'backbone-marionette');
Bones.Backbone.Marionette = require('backbone.marionette/lib/backbone.marionette.js');

How do I custom wrap a file I want to send to the client? It's kind of like a beautiful, one-and-only snowflake I wish to give to the client.

Create a mirror with the file and the wrapper as an option. Please see Assets for further info on exposing files to the client.

Route#initialize()

route.exposeClientPlugin(new mirror([ snowflake ], { type: '.js', wrapper: Bones.utils.wrapSnowflake }));
Clone this wiki locally