Skip to content

Commit 55379eb

Browse files
authored
Merge pull request #6 from posthtml/jescalan-updates
2 parents 0640dfa + 3464aa5 commit 55379eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+716
-594
lines changed

.editorconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ indent_style = space
88
trim_trailing_whitespace = true
99
insert_final_newline = true
1010

11-
[{bower,package}.json]
12-
indent_size = 2
13-
14-
[*.md]
11+
[*.{md,html}]
1512
trim_trailing_whitespace = false

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
# OS
2-
31
._*
42
.DS_Store
5-
6-
# NODEJS
7-
83
node_modules
94
npm-debug.log

.npmignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
# FILES
2-
31
.editorconfig
42
npm-debug.log
5-
63
test.js
7-
8-
# DIRECTORIES
9-
104
test
115
node_modules

.travis.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
sudo: true
21
language: node_js
2+
sudo: false
33
node_js:
4-
- v6
5-
- v4
6-
cache:
7-
directories:
8-
- node_modules
9-
before_script:
10-
- npm i
11-
script:
12-
- npm test
13-
after_success:
14-
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
4+
- 6
5+
after_script:
6+
- npm run coveralls

CONTRIBUTING.md

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ Contributions welcome!
44

55
**Before spending lots of time on something, ask for feedback on your idea first!**
66

7-
Please search issues and pull requests before adding something new to avoid duplicating
8-
efforts and conversations.
7+
Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations.
98

10-
This project welcomes non-code contributions, too! The following types of contributions
11-
are welcome:
9+
This project welcomes non-code contributions, too! The following types of contributions are welcome:
1210

1311
- **Ideas**: participate in an issue thread or start your own to have your voice heard.
1412
- **Writing**: contribute your expertise in an area by helping expand the included docs.
@@ -25,51 +23,36 @@ to!
2523

2624
## Project Governance
2725

28-
Individuals making significant and valuable contributions are given commit-access to the
29-
project to contribute as they see fit. This project is more like an open wiki than a
30-
standard guarded open source project.
26+
Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
3127

3228
### Rules
3329

3430
There are a few basic ground-rules for contributors:
3531

3632
1. **No `--force` pushes** or modifying the Git history in any way.
3733
2. **Non-master branches** should be used for ongoing work.
38-
3. **Significant modifications** like API changes should be subject to a **pull request**
39-
to solicit feedback from other contributors.
40-
4. **Pull requests** are *encouraged* for all contributions to solicit feedback, but left to
41-
the discretion of the contributor.
34+
3. **Significant modifications** like API changes should be subject to a **pull request** to solicit feedback from other contributors.
35+
4. **Pull requests** are *encouraged* for all contributions to solicit feedback, but left to the discretion of the contributor.
4236

4337
### Releases
4438

4539
Declaring formal releases remains the prerogative of the project maintainer.
4640

4741
### Changes to this arrangement
4842

49-
This is an experiment and feedback is welcome! This document may also be subject to pull-
50-
requests or changes by contributors where you believe you have something valuable to add
51-
or change.
43+
This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change.
5244

5345
## Developer's Certificate of Origin 1.1
5446

5547
By making a contribution to this project, I certify that:
5648

57-
- (a) The contribution was created in whole or in part by me and I have the right to
58-
submit it under the open source license indicated in the file; or
49+
- (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
5950

60-
- (b) The contribution is based upon previous work that, to the best of my knowledge, is
61-
covered under an appropriate open source license and I have the right under that license
62-
to submit that work with modifications, whether created in whole or in part by me, under
63-
the same open source license (unless I am permitted to submit under a different
64-
license), as indicated in the file; or
51+
- (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
6552

66-
- (c) The contribution was provided directly to me by some other person who certified
67-
(a), (b) or (c) and I have not modified it.
53+
- (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
6854

69-
- (d) I understand and agree that this project and the contribution are public and that a
70-
record of the contribution (including all personal information I submit with it,
71-
including my sign-off) is maintained indefinitely and may be redistributed consistent
72-
with this project or the open source license(s) involved.
55+
- (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
7356

74-
[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
75-
[standard-url]: https://github.com/feross/standard
57+
[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
58+
[standard-url]: https://github.com/feross/standard

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License (MIT)
22

3-
Copyright (c) 2016 Michael Ciniawsky
3+
Copyright (c) 2016 Jeff Escalante, Michael Ciniawsky
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 24 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
1+
# PostHTML Expressions <img align="right" width="220" height="200" title="PostHTML logo" src="http://posthtml.github.io/posthtml/logo.svg">
2+
13
[![NPM][npm]][npm-url]
24
[![Deps][deps]][deps-url]
35
[![Tests][travis]][travis-url]
46
[![Coverage][cover]][cover-url]
57
[![Standard Code Style][style]][style-url]
68

7-
<div align="center">
8-
<img width="220" height="150" title="PostHTML" src="http://posthtml.github.io/posthtml/logo.svg">
9-
<h1>Expressions Plugin</h1>
10-
<p>Local variables, expressions, loops, conditionals and unicorns 👍</p>
11-
</div>
12-
13-
<h2 align="center">Install</h2>
9+
Local variables, expressions, loops, and conditionals in your html.
1410

15-
```bash
16-
npm i -D posthtml-exp
17-
```
11+
## Installation
1812

19-
<h2 align="center">Usage</h2>
13+
First, install from npm with `npm i posthtml-exp --save`, then add it as a plugin to your posthtml pipeline:
2014

2115
```js
22-
const { readFileSync } = require('fs')
23-
2416
const posthtml = require('posthtml')
2517
const exp = require('posthtml-exp')
18+
const {readFileSync} = require('fs')
2619

2720
posthtml(exp({ locals: { foo: 'bar' } }))
28-
.process(readFileSync('index.html', 'utf8'))
29-
.then((result) => console.log(result.html))
21+
.process(readFileSync('exampleFile.html', 'utf8'))
22+
.then(console.log)
3023
```
3124

25+
## Usage
26+
3227
This plugin provides a syntax for including local variables and expressions in your templates, and also extends custom tags to act as helpers for conditionals and looping.
3328

3429
You have full control over the delimiters used for injecting locals, as well as the tag names for the conditional and loop helpers, if you need them. All options that can be passed to the `exp` plugin are shown below:
@@ -47,22 +42,22 @@ You can inject locals into any piece of content in your html templates, other th
4742

4843
```js
4944
exp({
50-
locals: { class: 'intro', name: 'Jeff' }
45+
locals: { myClassName: 'introduction', myName: 'Jeff' }
5146
})
5247
```
5348

5449
And compiled with the following template:
5550

5651
```html
57-
<div class="{{class}}">
58-
My name is {{name}}
52+
<div class="{{ myClassName }}">
53+
My name is {{ myName }}
5954
</div>
6055
```
6156

6257
You would get this as your output:
6358

6459
```html
65-
<div class="intro">
60+
<div class="introduction">
6661
My name is Jeff
6762
</div>
6863
```
@@ -73,14 +68,14 @@ By default, special characters will be escaped so that they show up as text, rat
7368

7469
```js
7570
exp({
76-
locals: { statement: '<strong>wow!</strong>' }
71+
locals: { strongStatement: '<strong>wow!</strong>' }
7772
})
7873
```
7974

8075
And you rendered it into a tag like this:
8176

8277
```html
83-
<p>The fox said, {{ statement }}</p>
78+
<p>The fox said, {{ strongStatement }}</p>
8479
```
8580

8681
You would see the following output:
@@ -92,8 +87,7 @@ You would see the following output:
9287
In your browser, you would see the angle brackets, and it would appear as intended. However, if you wanted it instead to be parsed as html, you would need to use the `unescapeDelimiters`, which by default are three curly brackets, like this:
9388

9489
```html
95-
<p>The fox said, {{{ statement }}}</p>
96-
90+
<p>The fox said, {{{ strongStatement }}}</p>
9791
```
9892

9993
In this case, your code would render as html:
@@ -112,7 +106,6 @@ You are not limited to just directly rendering local variables either, you can i
112106

113107
With this in mind, it is strongly recommended to limit the number and complexity of expressions that are run directly in your template. You can always move the logic back to your config file and provide a function to the locals object for a smoother and easier result. For example:
114108

115-
116109
```js
117110
exp({
118111
locals: {
@@ -159,7 +152,7 @@ Your result would be only this:
159152

160153
Anything in the `condition` attribute is evaluated directly as an expression.
161154

162-
It should be noted that this is slightly cleaner-looking if you are using the [SugarML](https://github.com/posthtml/sugarml). But then again so is every other part of html.
155+
It should be noted that this is slightly cleaner-looking if you are using the [SugarML parser](https://github.com/posthtml/sugarml). But then again so is every other part of html.
163156

164157
```sml
165158
if(condition="foo === 'bar'")
@@ -177,8 +170,8 @@ You can use the `each` tag to build loops. It works with both arrays and objects
177170
```js
178171
exp({
179172
locals: {
180-
array: ['foo', 'bar'],
181-
object: { foo: 'bar' }
173+
anArray: ['foo', 'bar'],
174+
anObject: { foo: 'bar' }
182175
}
183176
})
184177
```
@@ -199,7 +192,7 @@ Output:
199192
And an example using an object:
200193

201194
```html
202-
<each loop="key, value in anObject">
195+
<each loop="value, key in anObject">
203196
<p>{{ key }}: {{ value }}</p>
204197
</each>
205198
```
@@ -222,57 +215,10 @@ So this would also be fine:
222215

223216
So you don't need to declare all the available variables (in this case, the index is skipped), and the expression after `in` doesn't need to be a local variable, it can be any expression.
224217

225-
<h2 align="center">Example</h2>
226-
227-
```js
228-
const { readFileSync } = require('fs')
229-
230-
const posthtml = require('posthtml')
231-
const exp = require('posthtml-exp')
232-
233-
const html = readFileSync('./index.html', 'utf8')
234-
235-
posthtml([ exp ])
236-
.process(html)
237-
.then(result => console.log(result.html))
238-
```
239-
240-
###### Input
241-
242-
```html
243-
244-
```
245-
246-
###### Output
247-
248-
```html
249-
250-
```
251-
252-
<h2 align="center">LICENSE</h2>
253-
254-
> MIT License (MIT)
255-
256-
> Copyright (c) 2016 PostHTML Jeff Escalante
257-
Michael Ciniawsky <[email protected]>
258-
259-
> Permission is hereby granted, free of charge, to any person obtaining a copy
260-
of this software and associated documentation files (the "Software"), to deal
261-
in the Software without restriction, including without limitation the rights
262-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
263-
copies of the Software, and to permit persons to whom the Software is
264-
furnished to do so, subject to the following conditions:
265-
266-
> The above copyright notice and this permission notice shall be included in all
267-
copies or substantial portions of the Software.
218+
### License & Contributing
268219

269-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
270-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
271-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
272-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
273-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
274-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
275-
SOFTWARE.
220+
- Licensed under [MIT](LICENSE)
221+
- See [guidelines for contribution](CONTRIBUTING.md)
276222

277223
[npm]: https://img.shields.io/npm/v/posthtml-exp.svg
278224
[npm-url]: https://npmjs.com/package/posthtml-exp

0 commit comments

Comments
 (0)