Skip to content

Commit 5488472

Browse files
committed
change loaders output structure, and remove props loader
1 parent 1fe97fc commit 5488472

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

loaders/examples.loader.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,25 @@ var _ = require('lodash');
22
var marked = require('marked');
33

44
var evalPlaceholder = '<%{#eval#}%>';
5-
var codePlaceholder = '<%{#code#}%>';
65

76
var requireAnythingRegex = /require\s*\(([^)]+)\)/g;
87
var simpleStringRegex = /^"([^"]+)"$|^'([^']+)'$/;
98

109
function readExamples(markdown) {
1110
var codeChunks = [];
12-
1311
var renderer = new marked.Renderer();
14-
renderer.heading = function(text, level, raw) {
15-
var tag = 'h' + (level + 2);
16-
return '<' + tag + '>' + text + '</' + tag + '>\n';
17-
};
18-
renderer.code = function(code) {
19-
codeChunks.push(code);
20-
return codePlaceholder;
21-
};
2212

23-
var html = marked(markdown, {renderer: renderer});
13+
renderer.code = function(code, language) {
14+
if (language && language === 'jsx') {
15+
codeChunks.push({type: 'code', content: code, evalInContext: evalPlaceholder});
16+
}
2417

25-
var chunks = [];
26-
var textChunks = html.split(codePlaceholder);
27-
textChunks.forEach(function(chunk) {
28-
if (chunk) {
29-
chunks.push({type: 'html', content: chunk});
30-
}
31-
var code = codeChunks.shift();
32-
if (code) {
33-
chunks.push({type: 'code', content: code, evalInContext: evalPlaceholder});
34-
}
35-
});
18+
return code;
19+
};
20+
21+
marked(markdown, {renderer: renderer});
3622

37-
return chunks;
23+
return codeChunks;
3824
}
3925

4026
// Returns a list of all strings used in require(...) calls in the given source code.

loaders/props.loader.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

loaders/styleguide.loader.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function processComponent(filepath) {
1212
'filepath: ' + JSON.stringify(filepath),
1313
'relativePath: ' + JSON.stringify(path.relative(config.rootDir, filepath)),
1414
'module: ' + requireIt(filepath),
15-
'props: ' + requireIt('!!props!' + filepath),
1615
'examples: ' + (hasExamples ? requireIt('examples!' + examplesFile) : null)
1716
].join(',') + '}';
1817
}
@@ -40,7 +39,14 @@ module.exports.pitch = function() {
4039
console.log();
4140
}
4241

43-
var components = componentSources.map(processComponent);
42+
var specPah;
43+
var specId;
44+
var components = componentSources.map(function(item){
45+
specPah = config.getExampleFilename(item);
46+
specId = path.dirname(specPah.replace(global.userPath, '')).replace(/^\//, '').toLowerCase();
47+
48+
return '"' + specId + '":' + processComponent(item);
49+
});
4450

4551
var simplifiedConfig = _.pick(config, [
4652
'title',
@@ -50,7 +56,7 @@ module.exports.pitch = function() {
5056
return [
5157
'module.exports = {',
5258
' config: ' + JSON.stringify(simplifiedConfig) + ',',
53-
' components: [' + components.join(',') + ']',
59+
' components: {' + components.join(',') + '}',
5460
'};'
5561
].join('\n');
5662
};

0 commit comments

Comments
 (0)