File tree Expand file tree Collapse file tree 12 files changed +208
-0
lines changed Expand file tree Collapse file tree 12 files changed +208
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ # OS
2
+ .DS_Store
3
+ ._ *
4
+
5
+ # NODEJS
6
+ node_modules
7
+ npm-debug.log
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ node_modules
Original file line number Diff line number Diff line change
1
+ {
2
+ "eqeqeq" : true ,
3
+ "expr" : true ,
4
+ "maxlen" : 120 ,
5
+ "undef" : true ,
6
+ "unused" : true ,
7
+ "node" : true
8
+ }
Original file line number Diff line number Diff line change
1
+ node_modules /
2
+ test /
3
+ npm-debug.log
4
+ .editorconfig
5
+ .jscsrc
6
+ .jshintignore
7
+ .jshintrc
Original file line number Diff line number Diff line change
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 `
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ < div class ="button "> < div class ="button__text "> Text</ div > </ div >
You can’t perform that action at this time.
0 commit comments