<commit_before># cartero-node-hook

Node.js run time library for [Cartero](https://github.com/rotundasoftware/cartero).

[![build status](https://secure.travis-ci.org/rotundasoftware/cartero-node-hook.png)](http://travis-ci.org/rotundasoftware/cartero-node-hook)

## Install
```
npm install cartero-node-hook
```

## Usage

```javascript
var hook = require( 'cartero-node-hook' );
var path = require( 'path' );

var h = hook( {
  viewDirPath : path.join( 'views' ),
  outputDirPath : path.join( 'static/assets' )
} );

// get the js and css html to inject into a server side view
h.getViewAssetHTMLTags( viewPath, function( err, tags ) {
  // tags.script is a string of <script> tags
  // tags.style is a string of <link> tags
} );
```

Using Express? [cartero-express-midddleware](https://github.com/rotundasoftware/cartero-express-hook) automatically populates `res.locals` with the `script` and `link` tags for the view being rendered.

## API

### h = hook( viewDirPath, outputDirPath, options );

`viewDirPath` and `outputDirPath` are the absolute paths to your views directory and Cartero output directory, respectively, as passed into Cartero at build time. `options` may contain a `outputDirPath`, which is base url corresponding to the cartero output directory (default `'/'`).

### h.getViewAssetHTMLTags( viewPath, cb )

Get the HTML tags to load the script and style assets for the view at `viewPath`.

`cb` should have the following signature:

```javascript
h.getViewAssetHTMLTags( viewPath, function( err, tags ) {
  // tags.script is a string of <script> tags
  // tags.style is a string of <link> tags
} );
```

### h.getViewAssets( viewPath, options, cb )

Returns a hash of the assets for the view at `viewPath` keyed by asset type. `options` may contain:

  * `paths` - If truthy, asset paths are returned (relative to `outputDirPath`), instead of urls (prepended with `outputDirUrl`)
  * `types` - An array of assets types to return. If not supplied all asset types are returned.

```javascript
h.getViewAssets( viewPath, { [ 'style' ] }, function( err, assets ) {
  function( err, assets ) {
    console.log( assets.style );  // array of urls (ex: [ '/url/to/bundle.css' ])
  }
}
```

### h.getAssetUrl( assetPath )

Returns the url of the asset with the absolute path `assetPath`. (Or more precisely, returns the url of the asset that was at that path at the time Cartero was run.) An error is thrown if the supplied path does not correspond to an asset of any parcel.

## Contributors

* [<NAME>](https://github.com/go-oleg)
* [<NAME>](https://twitter.com/davegbeck)

## License

MIT<commit_msg>changed readme<commit_after># cartero-node-hook

Node.js run time library for [Cartero](https://github.com/rotundasoftware/cartero).

[![build status](https://secure.travis-ci.org/rotundasoftware/cartero-node-hook.png)](http://travis-ci.org/rotundasoftware/cartero-node-hook)

## Install
```
npm install cartero-node-hook
```

## Usage

```javascript
var hook = require( 'cartero-node-hook' );
var path = require( 'path' );

var h = hook( {
  viewDirPath : path.join( 'views' ),
  outputDirPath : path.join( 'static/assets' )
} );

// get the js and css html to inject into a server side view
h.getViewAssetHTMLTags( viewPath, function( err, tags ) {
  // tags.script is a string of <script> tags
  // tags.style is a string of <link> tags
} );
```

Using Express? [cartero-express-midddleware](https://github.com/rotundasoftware/cartero-express-hook) automatically populates `res.locals` with the `script` and `link` tags for the view being rendered.

## API

### h = hook( viewDirPath, outputDirPath, options );

`viewDirPath` and `outputDirPath` are the absolute paths to your views directory and Cartero output directory, respectively, as passed into Cartero at build time. `options` may contain a `outputDirPath`, which is base url corresponding to the Cartero output directory (default `'/'`).

### h.getViewAssetHTMLTags( viewPath, cb )

Get the HTML tags to load the script and style assets for the view at `viewPath`.

```javascript
h.getViewAssetHTMLTags( viewPath, function( err, tags ) {
  // tags.script is a string of <script> tags
  // tags.style is a string of <link> tags
} );
```

### h.getViewAssets( viewPath, options, cb )

Returns a hash of asset urls keyed by asset type. `options` may contain:

  * `paths` - If true, asset paths are returned (relative to `outputDirPath`) insted of urls.
  * `types` - An array of assets types to return. If not supplied all asset types are returned.

```javascript
h.getViewAssets( viewPath, { [ 'style' ] }, function( err, assets ) {
  function( err, assets ) {
    console.log( assets.style );  // array of urls (ex: [ '/url/to/bundle.css' ])
  }
}
```

### h.getAssetUrl( assetPath )

Returns the url of the asset with the absolute path `assetPath`. (Or more precisely, returns the url of the asset that was at that path at the time Cartero was run.) An error is thrown if the supplied path does not correspond to an asset of any parcel.

## Contributors

* [<NAME>](https://github.com/go-oleg)
* [<NAME>](https://twitter.com/davegbeck)

## License

MIT
{'fraction_non_alphanumeric': 0.1287495130502532, 'fraction_numerical': 0.0, 'mean_word_length': 4.135, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1131170', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1615, 'n_words': 582}