Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Jul 27, 2014
1 parent a114325 commit 52dda06
Showing 1 changed file with 118 additions and 82 deletions.
200 changes: 118 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bible.js

The Bible as a NPM module.

## Installation
# Installation
```sh
$ npm install bible.js
```
Expand All @@ -15,101 +15,137 @@ $ sudo npm install bible -g

For more information and documentation click [here](https://github.com/BibleJS/BibleApp).

## Methods
# Methods

### Constructor: `new Bible (options)`
Creates a new `Bible` instance.
## `new Bible(options)`
Creates a new `Bible` instance

#### Arguments
### Params
* **Object** *options* An object containing the following fields:

- `@options` object containing:
- `language`: the language (currently the supported languages are Romanian (`"RO"`) and English (`"EN"`)
- `language`: the langauge of the Bible instance

#### Example
## `myBible.get(reference, callback)`
This function gets a verse/chapter etc providing the `reference`

```js
var Bible = new (require ("bible.js"))({
language: "EN"
})
```

### `Bible.get (reference, callback)`
This function gets the verses/chapter represented by `@reference` argument. The `@callback` function is called with an error and an array of verses (objects).

#### Arguments
- `@reference`: a string in the following formats:
e.g. Genesis 1:1 - returns one verse
or Genesis 1:1,2 - returns two verses (1 and 2)
or Genesis 1:1-10 - returns the verses 1 - 10
or Genesis 1 - returns the whole chapter
### Params:
* **String** *reference* The verse reference. It can be in the following formats:

- `@callback`: the callback function
- Genesis 1:1 - returns one verse
- Genesis 1:1,2 - returns two verses (1 and 2)
- Genesis 1:1-10 - returns the verses 1 - 10
- Genesis 1 - returns the whole chapter

#### Example
* **Function** *callback* The callback function

```js
Bible.get("Psalm 1:1-6", function (err, data) {
/* do something */
});
```
### Return:
* **Bible** The Bible instance (self)

### `Bible.search (query, callback)`
The method receives a string or a regular expression in the first argument (`@query`). The verses that match the query are fetched.
**NOTE**: right now only searching in json files is implemented.

#### Arguments
- `@query`: string or regular expression
- `@callback`: the callback function

#### Example

```js
Bible.search(/david/i, function (err, verses) {
/* do something with the verses that contain "david" */
});
```
## `search(query, callback)`
This function gets the verses that match to the regular expression
provided.

## Example
```js
// dependencies
var Bible = new (require ("bible.js"))({
language: "EN"
})
### Params:
* **String|RegExp** *query* The string/regular expression that matches the searched verses.
* **Function** *callback* The callback function

// the Bible reference
, reference = "Psalm 1:1-6"
;
### Return:
* **Bible** The Bible instance (self)

// output
console.log(reference);
console.log("-------------");
## `init(config, callback)`
Inits BibleJS module by downloading versions set in configuration
This method should be called when the application is started.

// get verse
Bible.get(reference, function (err, data) {
### Params:
* **Object** *config* BibleJS configuration object. It must contain `versions` field as noted in documentation.
* **Function** *callback* The callback function

// we've get the verses
if (data && data.length) {
### Return:
* **Bible** Bible constructor

// each verse
for (var i in data) {

// output
console.log(data[i].verse + " | " + data[i].text);
# Example
```js
// Dependencies
var Bible = require("../index");

// Init Bible
Bible.init({
versions: {
en: {
source: "https://github.com/BibleJS/bible-english"
, version: "master"
, language: "en"
},
ro: {
source: "https://github.com/BibleJS/bible-romanian"
, version: "master"
, language: "ro"
}

// output
console.log("-------------\n");
}
}, function (err) {
if (err) { throw err; }

// Create Bible instances
var enBible = new Bible({ language: "en" })
, roBible = new Bible({ language: "ro" })
, references = {
en: "Psalm 1:1-6"
, ro: "Psalmi 1:1-6"
}
, responseHandler = function (lang) {
return function (err, data) {
if (err) { throw err; }

// Output
if (lang) {
console.log(references[lang]);
}
console.log("-------------");

if (data && data.length) {

// each verse
for (var i in data) {
console.log(data[i].verse + " | " + data[i].text);
}

console.log("-------------\n");
}
}
}
;

// Get verses
enBible.get(references.en, responseHandler("en"));
roBible.get(references.ro, responseHandler("ro"));

// Search
roBible.search("/meroza/gi", responseHandler());
});
```

### Testing
## Testing

```sh
$ npm test

> bible.js@0.1.1 test /home/.../bible.js
> node test/english
> bible.js@1.0.0 test /home/ionicabizau/Documents/BibleApp/node_modules/bible.js
> node test/index

Psalmi 1:1-6
-------------
1 | Ferice de omul care nu se duce la sfatul celor răi, nu se opreşte pe calea celor păcătoşi şi nu se aşază pe scaunul celor batjocoritori!
2 | Ci îşi găseşte plăcerea în Legea Domnului, şi zi şi noapte cugetă la Legea Lui!
3 | El este ca un pom sădit lângă un izvor de apă, care îşi dă rodul la vremea lui şi ale cărui frunze nu se veştejesc: tot ce începe, duce la bun sfârşit.
4 | Nu tot aşa este cu cei răi: ci ei sunt ca pleava pe care o spulberă vântul.
5 | De aceea cei răi nu pot ţine capul sus în ziua judecăţii, nici păcătoşii în adunarea celor neprihăniţi.
6 | Căci Domnul cunoaşte calea celor neprihăniţi, dar calea păcătoşilor duce la pieire.
-------------

-------------
23 | Blestemaţi pe Meroza, a zis Îngerul Domnului, blestemaţi, blestemaţi pe locuitorii lui; căci n-au venit în ajutorul Domnului, în ajutorul Domnului, printre oamenii viteji.
-------------

Psalm 1:1-6
-------------
Expand All @@ -122,37 +158,37 @@ Psalm 1:1-6
-------------
```

## Changelog
# Changelog

### `1.0.0`
## `1.0.0`
- First stable release with a lot of improvements
- Support custom language submodules (everyone can build one) via `git` and `npm`

### `v0.1.7`
## `v0.1.7`
- Added `search` method
- Removed `mongodb` as dependency

### `v0.1.6`
## `v0.1.6`
- Updated GitHub urls and email address

### `v0.1.5`
## `v0.1.5`
- Convert to uppercase the language field

### `v0.1.4`
## `v0.1.4`
- Get all verses from a chapter (bug when language is RO).

### `v0.1.3`
## `v0.1.3`
- Removed `_books` field.
- Use the new version of [Bible Data](https://github.com/BibleJS/Versions)

### `v0.1.2`
## `v0.1.2`
- added English support using providers

### `v0.1.1`
## `v0.1.1`
- use Bible data v0.1.1

### `v0.1.0`
## `v0.1.0`
- initial release

## License
# License
See LICENSE file.

0 comments on commit 52dda06

Please sign in to comment.