Skip to content

Commit 380b7ba

Browse files
committed
Merge pull request #166 from varya/features/kss-divider
KSS blocks splitter. Initial edition
2 parents 56e660e + 3f2ab4a commit 380b7ba

File tree

7 files changed

+599
-2
lines changed

7 files changed

+599
-2
lines changed

.jscsrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"test/angular/**",
1212
"bin/**",
1313
"lib/dist/**",
14-
"lib/app/js/components/**"
14+
"lib/app/js/components/**",
15+
"lib/modules/kss-blocks-parser.js",
16+
"test/kss-splitter.js" // Does not allow multiple linebreaks in comments
1517
]
1618
}

gulpfile.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var gulp = require('gulp'),
1010
bower = require('gulp-bower'),
1111
mainBowerFiles = require('main-bower-files'),
1212
path = require('path'),
13+
run = require('gulp-run'),
1314
jscs = require('gulp-jscs'),
1415
runSequence = require('run-sequence'),
1516
styleguide = require('./lib/styleguide'),
@@ -109,6 +110,12 @@ gulp.task('sass', function() {
109110
.pipe(gulp.dest(distPath + '/css'));
110111
});
111112

113+
gulp.task('kss-splitter', function() {
114+
115+
run('./node_modules/ometajs/bin/ometajs2js -i lib/modules/kss-blocks-parser.ometajs -o lib/modules/kss-blocks-parser.js');
116+
117+
});
118+
112119
gulp.task('demo', function() {
113120
options.server = true;
114121
configPath = __dirname + '/lib/app/styleguide_config.json';
@@ -158,7 +165,7 @@ gulp.task('watch', [], function() {
158165
gulp.watch(sourcePath + '/**', ['styleguide']);
159166
});
160167

161-
gulp.task('build', ['sass', 'js:app', 'js:vendor', 'html', 'assets']);
168+
gulp.task('build', ['sass', 'kss-splitter', 'js:app', 'js:vendor', 'html', 'assets']);
162169

163170
gulp.task('changelog', function() {
164171

lib/modules/kss-blocks-parser.js

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/modules/kss-blocks-parser.ometajs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
ometa kssBlocksParser {
2+
3+
lineBreak = seq('\n'),
4+
lineEnd = lineBreak | end,
5+
6+
inlineCommentPrefix = seq('//'),
7+
lineWithNoComments = (~inlineCommentPrefix char)* lineEnd, // every line with no inline comments
8+
9+
// A set of numbers divided with "."
10+
kssReferenceNumber_ = '.' digit+ kssReferenceNumber_*,
11+
kssReferenceNumber = digit+ kssReferenceNumber_*,
12+
13+
// In-comment string mentioning styleguide reference
14+
kssReferenceString = seq(' ')* seq('Styleguide ') kssReferenceNumber seq(' ')*,
15+
16+
// A block of inline comments
17+
inlineComment = inlineCommentPrefix (~lineEnd ~kssReferenceString char)*,
18+
19+
multiLineCommentPrefix = seq('/*'),
20+
multiLineCommentSuffix = seq('*/'),
21+
22+
// A block of multiline comments
23+
multiLineCommentBody = (~multiLineCommentSuffix char)*,
24+
multiLineComment = (multiLineCommentPrefix multiLineCommentBody multiLineCommentSuffix):c -> [#comment, c],
25+
26+
// A block of inline comments with KSS markup
27+
kssLastString = inlineCommentPrefix kssReferenceString lineEnd,
28+
kssMarkupInline = ((~lineWithNoComments inlineComment lineEnd)* kssLastString):k -> [#kss, k],
29+
30+
// A block of multiline comments with KSS markup
31+
kssLastStringMultiline = kssReferenceString lineEnd?,
32+
kssMarkupMultiLineBody = (~multiLineCommentSuffix ~kssLastStringMultiline char)* kssLastStringMultiline,
33+
kssMarkupMultiLine = (multiLineCommentPrefix kssMarkupMultiLineBody multiLineCommentSuffix):k -> [#kss, k],
34+
35+
// KSS markup can be either in any block of comments
36+
kssMarkup = kssMarkupInline | kssMarkupMultiLine,
37+
38+
// A code block is anything which is not KSS markup block
39+
code = (~kssMarkup char)*:c -> [#code, c.join('')],
40+
41+
// A block consists of KSS markup and following code block
42+
block = kssMarkup:k lineEnd* code:c -> [#block, k, c],
43+
44+
any = code? (block)*
45+
46+
}

lib/modules/kss-splitter.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
var kssBlocksParser = require('./kss-blocks-parser').kssBlocksParser;
4+
5+
module.exports = {
6+
7+
getAst: function(source) {
8+
var ast = kssBlocksParser.matchAll(source, 'any');
9+
return ast;
10+
},
11+
getBlocks: function(source) {
12+
var ast = this.getAst(source),
13+
blocks = [];
14+
ast.forEach(function(token) {
15+
var kss, code;
16+
if (token[0] == 'block') {
17+
if (token[1][0] == 'kss') {
18+
kss = token[1][1]
19+
}
20+
if (token[2][0] == 'code') {
21+
code = token[2][1]
22+
}
23+
}
24+
blocks.push({
25+
kss: kss,
26+
code: code
27+
});
28+
});
29+
return blocks;
30+
}
31+
32+
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"gulp-marked": "^1.0.0",
3535
"gulp-mustache": "^1.0.0",
3636
"gulp-rename": "^1.2.0",
37+
"gulp-run": "^1.6.4",
3738
"gulp-sass": "^1.2.2",
3839
"gulp-util": "^3.0.1",
3940
"jade": "^1.7.0",
@@ -45,6 +46,7 @@
4546
"node-bourbon": "^1.2.3",
4647
"node-neat": "^1.3.0",
4748
"node.extend": "^1.1.2",
49+
"ometajs": "^3.3.7",
4850
"run-sequence": "^1.0.1",
4951
"sanitize-html": "^1.4.3",
5052
"serve-favicon": "^2.1.6",

0 commit comments

Comments
 (0)