Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*]
charset = utf-8
end_of_line = crlf
insert_final_newline = true
indent_style = space
indent_size = 2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
/coverage
examples/**/*.html
bower_components
npm-debug.log
npm-debug.log
.idea
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ It also generates a JSON object of the parsed comments that can be used to gener
* @hideCode
*/
```

* `@namespace` - Add a namespace class to the example output.

```css
/**
* A namespace is a class added to the parent DOM element of the example
*
* @section namespace Example
* @namespace my-magical-namespace
* @example
* <div class="container">
* <div class="my-awesome-class">Example</div>
* </div>
*/
```

* `@doc` - A file that defines the section name, description, example, or code. Useful if your section description needs to output HTML. The first heading of the file will be used as the section description if one is not defined.

Expand Down
15 changes: 14 additions & 1 deletion lib/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,22 @@ var tags = {
description += file;

this.comment.description += description.trimRight();
},

/**
* Apply a namespace to example code. Multiple namespaces will be applied to the same element.
* Nesting not supported.
* @example
/**
* @section
* @namespace foo
*\/
*/
namespace: function () {
this.block.namespace = this.tag.description;
}
};
tags.code = tags.example; // @code and @example generate the same structure

module.exports = tags;
module.exports.forwardReferenceSections = forwardReferenceSections;
module.exports.forwardReferenceSections = forwardReferenceSections;
7 changes: 6 additions & 1 deletion template/partials/polymer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7709,6 +7709,11 @@ this.fire('dom-change');
var body = document.createElement('body');
body.classList.add(this.is);

// add the namespace of an example to the body
if(this.dataset.namespace) {
body.classList.add(this.dataset.namespace);
}

// add scoped class to all content injected child nodes
var nodes = this.querySelectorAll('*');
for (var i = 0; i < nodes.length; i++) {
Expand All @@ -7725,4 +7730,4 @@ this.fire('dom-change');
}
});
})();
</script>
</script>
4 changes: 2 additions & 2 deletions template/partials/section.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="livingcss__section-description">{{{description}}}</div>

{{#if example}}
<livingcss-example>{{{example.description}}}</livingcss-example>
<livingcss-example{{#if namespace}} data-namespace="{{namespace}}"{{/if}}>{{{example.description}}}</livingcss-example>
{{/if}}

{{#if code}}
<div class="livingcss__section-markup">
<pre class="livingcss__section-code"><code class="language-{{code.type}}">{{code.description}}</code></pre>
</div>
{{/if}}
{{/if}}
3 changes: 3 additions & 0 deletions test/data/namespace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* @namespace test
*/
25 changes: 25 additions & 0 deletions test/tags.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,29 @@ describe('tags', function() {

});

// --------------------------------------------------
// @namespace
// --------------------------------------------------
describe('@namespace', function () {

it('should set namespace property', function (done) {
var file = path.join(__dirname, 'data/namespace.css');
var sections = [];
var pages = [];

fs.readFile(file, 'utf8', function (err, data) {
if (err) {
throw err;
}

parseComments(data, file, tags, {sections: sections, pages: pages}, function (block) {
expect(block.namespace).to.equal('test');
});

done();
});
});

});

});