Skip to content

Commit 413ffd2

Browse files
author
John Doherty
committed
more documentation tweaks
1 parent 2220891 commit 413ffd2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

README.MD

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ You can now argue that your web app can remain synced with the corperate website
1313
$ npm install --save node-iframe-replacement
1414
```
1515

16-
## Example usage
16+
## Usage
17+
18+
### Example server
1719

1820
The example below will request the [BBC News](http://www.bbc.co.uk/news) home page and replace the contents of **div[data-entityid="container-top-stories#1"]** with the contents of our fake-news view:
1921

20-
_I left the express logic out for readability, you can view the actual example [here](example/server.js)_
22+
_express logic excluded to improve readability, you can view the full example implementation [here](example/server.js)_
2123

2224
```js
2325
var iframeReplacement = require('node-iframe-replacement');
@@ -30,16 +32,20 @@ app.get('/', function(req, res){
3032

3133
// respond to this request with our fake-news content embedded within the BBC News home page
3234
res.merge('fake-news', {
33-
sourceUrl: 'http://www.bbc.co.uk/news', // external url to fetch
34-
sourcePlaceholder: 'div[data-entityid="container-top-stories#1"]', // css selector to inject our content into
35-
transform: null // pass function here to intercept the transofrm html prior to merging
35+
// external url to fetch
36+
sourceUrl: 'http://www.bbc.co.uk/news',
37+
// css selector to inject our content into
38+
sourcePlaceholder: 'div[data-entityid="container-top-stories#1"]',
39+
// pass a function here to intercept the source html prior to merging
40+
transform: null
3641
});
3742
});
3843
```
3944

4045
If you pass a function as the transform property ```transform: function($, model) {}``` - the function will be called prior to rendering, allowing you to inject title tags, html attributes etc.
46+
The `$` passed to your transform method is a JQuery like object using [cheerio](https://github.com/cheeriojs/cheerio#cheerio), removing the need to parse strings.
4147

42-
## fake-news html
48+
### Example fake-news html
4349

4450
```html
4551
<div style="margin: 0 0 0 20px; overflow: auto;">
@@ -55,11 +61,11 @@ If you pass a function as the transform property ```transform: function($, model
5561
</div>
5662
```
5763

58-
## Input
64+
### Example input
5965

6066
![alt text](docs/bbc-news-actual-homepage.png "BBC News actual homepage")
6167

62-
## Output
68+
### Example output
6369

6470
![alt text](docs/bbc-news-fake-homepage.png "BBC News actual homepage")
6571

@@ -73,7 +79,7 @@ Because of this, you need to ensure all the links within your conent are absolut
7379

7480
This project is a rethought, rebranded, relaunched version of my badly named [express-render-template](https://www.npmjs.com/package/express-render-template) module released in Arpil 2016.
7581

76-
## Note on Patches/Pull Requests
82+
## Notes on Pull Requests & Patches
7783

7884
* Fork the project
7985
* Make your feature addition or bug fix

0 commit comments

Comments
 (0)