Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

Commit f95c83d

Browse files
committed
1.4.0
1 parent 3e379e0 commit f95c83d

5 files changed

Lines changed: 104 additions & 55 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.4.0 (2015-01-26)
2+
3+
- Added: Automatically detects sibling markdown documentation
4+
- Added: Forward plugin options when theme-specific options are unspecified
5+
- Updated: Detects documentation relative to the original partial
6+
- Updated: Documentation
7+
18
## 1.3.0 (2015-11-17)
29

310
- Updated: Package dependencies

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,24 @@
66

77
[mdcss] lets you easily create and maintain style guides with CSS comments using Markdown.
88

9-
```css
10-
/*---
11-
title: Buttons
12-
section: Base CSS
13-
---
14-
15-
Button styles can be applied to any element. Typically you'll want to use
16-
either a `<button>` or an `<a>` element:
17-
18-
​```example:html
19-
<button class="btn">Click</button>
20-
<a class="btn" href="/some-page">Some Page</a>
21-
​```
22-
*/
23-
24-
.btn {
25-
background-color: black;
26-
color: white;
27-
}
28-
```
9+
/*---
10+
title: Buttons
11+
section: Base CSS
12+
---
13+
14+
Button styles can be applied to any element. Typically you'll want to use
15+
either a `<button>` or an `<a>` element:
16+
17+
```example:html
18+
<button class="btn">Click</button>
19+
<a class="btn" href="/some-page">Some Page</a>
20+
```
21+
*/
22+
23+
.btn {
24+
background-color: black;
25+
color: white;
26+
}
2927

3028
![screenshot](https://cloud.githubusercontent.com/assets/188426/11217538/cfeb322a-8d1e-11e5-9a64-2c5373968663.png)
3129

@@ -125,6 +123,14 @@ require('mdcss')({
125123
})
126124
```
127125

126+
Theme-specific options may also be passed in from the theme module itself, but note that any global options would then be ignored.
127+
128+
```js
129+
require('mdcss')({
130+
theme: require('mdcss-theme-github')(/* options */)
131+
})
132+
```
133+
128134
#### `destination`
129135

130136
Type: `String`
@@ -187,15 +193,16 @@ either a <code>&lt;button&gt;</code> or an <code>&lt;a&gt;</code> element:</p>
187193
The contents of a section may also be imported from another file.
188194

189195
**buttons.md**:
190-
```md
191-
Button styles can be applied to **any** element. Typically you'll want to use
192-
either a `<button>` or an `<a>` element:
193196

194-
​```html
195-
<button class="btn">Click</button>
196-
<a class="btn" href="/some-page">Some Page</a>
197-
​```
198-
```
197+
Button styles can be applied to **any** element. Typically you'll want to use
198+
either a `<button>` or an `<a>` element:
199+
200+
```html
201+
<button class="btn">Click</button>
202+
<a class="btn" href="/some-page">Some Page</a>
203+
​```
204+
205+
**base.css**:
199206

200207
```css
201208
/*---
@@ -204,6 +211,8 @@ import: buttons.md
204211
---*/
205212
```
206213

214+
The contents of a section may be automatically imported as well. For example, had the `import` been omitted, a sibling file of `base.buttons.md` or `base.md` would have been used (in that order of preference) if they existed.
215+
207216
### Details
208217

209218
Additional heading details are added before a second set of three dashes `---` in a section. These heading details are parsed and added to the [`documentation` object](#documentation-object).

index.js

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs-promise');
22
var marked = require('marked');
33
var path = require('path');
44

5-
var isDoc = /^\s*-{3,}\n(?:([\W\w]*?)\n\s*-{3,})?/;
5+
var isDoc = /^\s*-{3,}\n((?:[A-z][\w-]*\s*:\s*[\w-][^\n]*\n*)*)(?:\s*-{3,})?/;
66
var isMeta = /([A-z][\w-]*)\s*:\s*([\w-][^\n]*)/g;
77

88
module.exports = require('postcss').plugin('mdcss', function (opts) {
@@ -19,15 +19,17 @@ module.exports = require('postcss').plugin('mdcss', function (opts) {
1919
if (typeof opts.theme !== 'function') throw Error('The theme failed to load');
2020

2121
// conditionally set theme as executed theme
22-
if (opts.theme.type === 'mdcss-theme') opts.theme = opts.theme();
22+
if (opts.theme.type === 'mdcss-theme') opts.theme = opts.theme(opts);
2323

2424
// set destination path
2525
opts.destination = path.join(process.cwd(), opts.destination || 'styleguide');
2626

2727
// return plugin
28-
return function (css) {
29-
// set directory, documentation list, hash, and unique identifier
30-
var dir = css.source.input.file ? path.dirname(css.source.input.file) : process.cwd();
28+
return function (css, result) {
29+
// set current css directory or current directory
30+
var dir = css.source.input.file ? path.dirname(css.source.input.file) : process.cwd();
31+
32+
// set documentation list, hash, and unique identifier
3133
var list = [];
3234
var hash = {};
3335
var uniq = 0;
@@ -50,19 +52,54 @@ module.exports = require('postcss').plugin('mdcss', function (opts) {
5052
return '';
5153
}, opts.marked).trim());
5254

55+
// conditionally set the closest documentation name
56+
if (doc.title && !doc.name) doc.name = titleToName(doc.title);
57+
5358
// conditionally import external content
54-
if (!doc.content && doc.import) try {
55-
doc.content = marked(fs.readFileSync(path.join(dir, doc.import), 'utf8').trim());
56-
} catch (error) {
57-
comment.warn('Imported content could not be read');
59+
if (!doc.content) {
60+
// get comment source path
61+
var src = comment.source.input.file;
62+
63+
// if the comment source path exists
64+
if (src) {
65+
// get the closest matching directory for this comment
66+
var localdir = src ? path.dirname(src) : dir;
67+
68+
var mdbase = doc.import;
69+
var mdspec;
70+
71+
// conditionally use a sibling md files if no import exists
72+
if (!mdbase) {
73+
mdbase = mdspec = path.basename(src, path.extname(src));
74+
75+
if (doc.name) {
76+
mdspec += '.' + doc.name;
77+
}
78+
79+
mdbase += '.md';
80+
mdspec += '.md';
81+
}
82+
83+
// try to read the closest matching documentation
84+
try {
85+
if (mdspec) {
86+
doc.content = fs.readFileSync(path.join(localdir, mdspec), 'utf8');
87+
} else throw new Error();
88+
} catch (error1) {
89+
try {
90+
doc.content = fs.readFileSync(path.join(localdir, mdbase), 'utf8');
91+
} catch (error2) {
92+
doc.content = '';
93+
94+
comment.warn(result, 'Documentation comment could not be read.');
95+
}
96+
}
97+
}
5898
}
5999

60100
// set documentation context
61101
doc.context = comment;
62102

63-
// conditionally set documentation name
64-
if (doc.title && !doc.name) doc.name = titleToName(doc.title);
65-
66103
// insure documentation has unique name
67104
var name = doc.name || 'section' + --uniq;
68105
var uniqname = name;

package.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdcss",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Easily create and maintain style guides with CSS comments using Markdown",
55
"keywords": [
66
"postcss",
@@ -21,25 +21,20 @@
2121
],
2222
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
2323
"license": "CC0-1.0",
24-
"repository": {
25-
"type": "git",
26-
"url": "https://github.com/jonathantneal/mdcss.git"
27-
},
24+
"repository": "jonathantneal/mdcss",
2825
"homepage": "https://github.com/jonathantneal/mdcss",
29-
"bugs": {
30-
"url": "https://github.com/jonathantneal/mdcss/issues"
31-
},
26+
"bugs": "https://github.com/jonathantneal/mdcss/issues",
3227
"dependencies": {
33-
"fs-extra": "^0.26.2",
28+
"fs-extra": "^0.26.4",
3429
"fs-promise": "^0.3.1",
3530
"marked": "^0.3.5",
36-
"mdcss-theme-github": "^2.0.1",
37-
"postcss": "^5.0.12"
31+
"mdcss-theme-github": "^2.1.0",
32+
"postcss": "^5.0.14"
3833
},
3934
"devDependencies": {
40-
"eslint": "^1.9.0",
41-
"tap-spec": "^4.1.0",
42-
"tape": "^4.2.2"
35+
"eslint": "^1.10.3",
36+
"tap-spec": "^4.1.1",
37+
"tape": "^4.4.0"
4338
},
4439
"scripts": {
4540
"lint": "eslint . --ignore-path .gitignore",

test/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var tests = {
99
examples: {
1010
css: ['../fixtures/basic.css']
1111
}
12-
}
12+
},
13+
warning: 1
1314
}
1415
}
1516
};

0 commit comments

Comments
 (0)