diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..8d465d3
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,6 @@
+[*]
+charset = utf-8
+end_of_line = crlf
+insert_final_newline = true
+indent_style = space
+indent_size = 2
diff --git a/.gitignore b/.gitignore
index 437c59b..aa3417d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@ node_modules
/coverage
examples/**/*.html
bower_components
-npm-debug.log
\ No newline at end of file
+npm-debug.log
+.idea
diff --git a/README.md b/README.md
index fe7cc9c..e32f5c6 100644
--- a/README.md
+++ b/README.md
@@ -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
+ *
+ */
+ ```
* `@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.
diff --git a/lib/tags.js b/lib/tags.js
index f7ed8ec..d791b27 100644
--- a/lib/tags.js
+++ b/lib/tags.js
@@ -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;
\ No newline at end of file
+module.exports.forwardReferenceSections = forwardReferenceSections;
diff --git a/template/partials/polymer.hbs b/template/partials/polymer.hbs
index c2cf799..452496c 100644
--- a/template/partials/polymer.hbs
+++ b/template/partials/polymer.hbs
@@ -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++) {
@@ -7725,4 +7730,4 @@ this.fire('dom-change');
}
});
})();
-
\ No newline at end of file
+
diff --git a/template/partials/section.hbs b/template/partials/section.hbs
index 70d9959..658b12f 100644
--- a/template/partials/section.hbs
+++ b/template/partials/section.hbs
@@ -1,11 +1,11 @@
{{{description}}}
{{#if example}}
-{{{example.description}}}
+{{{example.description}}}
{{/if}}
{{#if code}}
-{{/if}}
\ No newline at end of file
+{{/if}}
diff --git a/test/data/namespace.css b/test/data/namespace.css
new file mode 100644
index 0000000..26cf744
--- /dev/null
+++ b/test/data/namespace.css
@@ -0,0 +1,3 @@
+/**
+ * @namespace test
+ */
diff --git a/test/tags.spec.js b/test/tags.spec.js
index 815f559..b7c3adb 100644
--- a/test/tags.spec.js
+++ b/test/tags.spec.js
@@ -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();
+ });
+ });
+
+ });
+
});