Skip to content

Commit 42ca3de

Browse files
committed
Release v1.0.0
0 parents  commit 42ca3de

File tree

12 files changed

+208
-0
lines changed

12 files changed

+208
-0
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://EditorConfig.org
3+
4+
# No .editorconfig files above the root directory
5+
root = true
6+
7+
[*]
8+
charset = utf-8
9+
indent_size = 4
10+
end_of_line = lf
11+
indent_style = space
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
[*.{bemjson.js,deps.js}]
16+
indent_size = 4
17+
18+
[{bower,package}.json]
19+
indent_size = 2
20+
21+
[*.md]
22+
trim_trailing_whitespace = false

.gitignore

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

.jscsrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"disallowSpacesInCallExpression": true,
3+
"disallowSpaceAfterObjectKeys": true,
4+
"disallowNewlineBeforeBlockStatements": true,
5+
"disallowMultipleLineBreaks": true,
6+
"requireSemicolons": true,
7+
"requireFunctionDeclarations": true,
8+
"requireCommaBeforeLineBreak": true,
9+
"disallowTrailingComma": true,
10+
"disallowTrailingWhitespace": true,
11+
"disallowSpacesInFunction": {
12+
"beforeOpeningRoundBrace": true
13+
},
14+
"requireSpacesInFunction": {
15+
"beforeOpeningCurlyBrace": true
16+
},
17+
"disallowSpacesInConditionalExpression": {
18+
"afterTest": true,
19+
"afterConsequent": true
20+
},
21+
"excludeFiles": [
22+
".git/**",
23+
"node_modules/**"
24+
],
25+
"fileExtensions": [".js"]
26+
}

.jshintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.jshintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"eqeqeq": true,
3+
"expr": true,
4+
"maxlen": 120,
5+
"undef": true,
6+
"unused": true,
7+
"node": true
8+
}

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
test/
3+
npm-debug.log
4+
.editorconfig
5+
.jscsrc
6+
.jshintignore
7+
.jshintrc

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# PostHTML-include
2+
[![npm version](https://badge.fury.io/js/posthtml-include.svg)](http://badge.fury.io/js/posthtml-include)
3+
4+
## Usage
5+
6+
__index.html__
7+
```html
8+
<html>
9+
<head>
10+
<title>index.html</title>
11+
</head>
12+
<body>
13+
<include src="component/button/button.html">
14+
</body>
15+
</html>
16+
```
17+
18+
__component/button/button.html__
19+
```html
20+
<button class="button"><div class="button__text">Button</div></button>
21+
```
22+
23+
```javascript
24+
var posthtml = require('posthtml'),
25+
html = require('fs').writeFileSync('index.html').toString();
26+
27+
posthtml()
28+
.use(require('posthtml-include')({ encoding: 'utf-8' }))
29+
.process(html)
30+
.then(function(result) {
31+
console.log(result.html);
32+
//<html>
33+
//<head>
34+
// <title>index.html</title>
35+
//</head>
36+
//<body>
37+
// <button class="button"><div class="button__text">Text</div></button>
38+
//</body>
39+
//</html>
40+
})
41+
```
42+
43+
## Options
44+
45+
__encoding__: default `utf-8`

index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var toTree = require('posthtml/lib/parser').toTree;
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
module.exports = function(options) {
6+
options = options || {};
7+
8+
return function(tree) {
9+
tree.match({ tag: 'include' }, function(node) {
10+
var src = node.attrs.src || false,
11+
content;
12+
if (src) {
13+
content = toTree(fs.readFileSync(path.resolve(src), options.encoding || 'utf-8'));
14+
}
15+
return {
16+
tag: false,
17+
content: content
18+
};
19+
});
20+
return tree;
21+
};
22+
};

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "posthtml-include",
3+
"version": "1.0.0",
4+
"description": "Include file in HTML",
5+
"main": "index.js",
6+
"dependencies": {
7+
"posthtml": "^0.3.0"
8+
},
9+
"devDependencies": {
10+
"chai": "^3.2.0",
11+
"jscs": "^1.13.1",
12+
"jshint": "^2.8.0",
13+
"mocha": "^2.2.5"
14+
},
15+
"scripts": {
16+
"test": "npm run lint && mocha",
17+
"lint": "jshint . && jscs . -v"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/posthtml/posthtml-include.git"
22+
},
23+
"keywords": [
24+
"html",
25+
"include",
26+
"postproccessor",
27+
"parser",
28+
"transform",
29+
"manipulation"
30+
],
31+
"author": "Ivan Voischev <voischev.ivan@ya.ru>",
32+
"license": "MIT",
33+
"bugs": {
34+
"url": "https://github.com/posthtml/posthtml-include/issues"
35+
},
36+
"homepage": "https://github.com/posthtml/posthtml-include#readme"
37+
}

test/blocks/button/button.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="button"><div class="button__text">Text</div></div>

0 commit comments

Comments
 (0)