Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from mulesoft-labs/raml-1
Browse files Browse the repository at this point in the history
Updated to RAML 1.0 AST
  • Loading branch information
blakeembrey committed Mar 23, 2016
2 parents 1117a26 + dc8f070 commit bcbaedc
Show file tree
Hide file tree
Showing 29 changed files with 427 additions and 1,098 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
bower_components
coverage
/node_modules/
/bower_components/
/coverage/
.DS_Store
npm-debug.log
/typings/
/dist/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ notifications:
on_failure: change

node_js:
- "0.12"
- "stable"

after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

Generate files from a RAML document and Handlebars templates.
> Generate files from a RAML document and templates.
## Installation

Expand All @@ -15,36 +15,28 @@ npm install raml-generator --save

## Usage

The module accepts a map of Handlebars templates, partials and helpers, and exports a function that can be used to generate files from a RAML object and user data. For an example module, take a look at the [raml-javascript-generator](https://github.com/mulesoft-labs/raml-javascript-generator).
The module accepts a map of functions (usually compiled templates, such as Handlebars), and returns a function that will generate files given an instance of the RAML 1 parser JSON.

For an example module, take a look at the [raml-javascript-generator](https://github.com/mulesoft-labs/raml-javascript-generator).

Why use this? It's just a simple, high level API for creating generators with a standard API.

### JavaScript Usage

Create the generator function from an object specification. The returned object accepts two parameters, the RAML object and user package information.
Create the generator function from config. The returned object accepts two arguments, the RAML object and user config.

```js
var fs = require('fs')
var Handlebars = require('handlebars')
var generator = require('raml-generator')

module.exports = generator({
templates: {
'index.js': fs.readFileSync(__dirname + '/templates/index.js.hbs', 'utf8')
},
helpers: {
stringify: require('javascript-stringify')
'index.js': Handlebars.compile(fs.readFileSync(__dirname + '/templates/index.js.hbs', 'utf8'))
}
}) //=> [Function]
```

### Handlebars

Inside the Handlebars templates, the [RAML interface](https://github.com/mulesoft-labs/js-raml-object-interface) is exposed as Handlebars data.

```hbs
var baseUri = {{stringify baseUri}}
```

The user data is automatically provided as the Handlebars compile context.

### Bin Script

A `bin` script is provided for you to use with your custom generator. Just require `raml-generator/bin` and pass in the generator function (from above), package information (`package.json`) and `process.argv`.
Expand All @@ -59,6 +51,15 @@ var generator = /* The generator function */
bin(generator, require('./package.json'), process.argv)
```

Generated CLI:

```sh
generator --out [directory]

--data, -d Path to JSON configuration file
--include, -i Include additional RAML files (E.g. extensions)
```

## License

Apache License 2.0
Expand Down
7 changes: 7 additions & 0 deletions annotations.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#%RAML 1.0 Library

annotationTypes:
methodName:
type: string
displayName:
type: string
1 change: 1 addition & 0 deletions bin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/bin'
1 change: 1 addition & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/bin')
99 changes: 0 additions & 99 deletions bin/index.js

This file was deleted.

25 changes: 0 additions & 25 deletions bower.json

This file was deleted.

8 changes: 8 additions & 0 deletions custom_typings/raml-1-parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Promise } from 'es6-promise'

export interface Options {
rejectOnErrors?: boolean
}

export function loadApi (path: string, extensions?: string[], options?: Options): Promise<any>;
export function loadApiSync (path: string, extensions?: string[], options?: Options): any;
14 changes: 0 additions & 14 deletions lib/context/documentation.js

This file was deleted.

107 changes: 0 additions & 107 deletions lib/context/index.js

This file was deleted.

Loading

0 comments on commit bcbaedc

Please sign in to comment.