|
| 1 | +## Intro |
| 2 | + |
| 3 | +Spec pages in SourceJS engine are the main content units. They provide a proper sandbox for demoing rendered components, usage examples and module documentation. Therefore, it's really important to make Spec pages development process as easy as possible. |
| 4 | + |
| 5 | + Apart from plugins, that allow integrating different technologies for generating Specs pages, the engine provides a set of native helpers based on [EJS](http://ejs.co). |
| 6 | + |
| 7 | + Let's dive deeper into each of available Spec generation features. |
| 8 | + |
| 9 | + ## Plugins |
| 10 | + |
| 11 | + It's really important for us to make SourceJS easy adaptable to any project needs. Having a powerful, and easy-to-develop plugins system hugely improves developers user experience working with Living Style Guides. |
| 12 | + |
| 13 | + Here's a list of all Spec generation focused plugins: |
| 14 | + |
| 15 | +* [sourcejs-slm](https://github.com/venticco/sourcejs-slm) - [Slim](http://slim-lang.com/) templates support |
| 16 | +* [sourcejs-md-react](https://github.com/mik01aj/sourcejs-md-react) - Markdown helpers for rendering React components |
| 17 | +* [sourcejs-react](https://github.com/szarouski/sourcejs-react) - generate specs from JSX files |
| 18 | +* [sourcejs-contrib-dss](http://github.com/sourcejs/sourcejs-contrib-dss) - generating documentation out of CSS comments |
| 19 | +* [sourcejs-jade](https://github.com/sourcejs/sourcejs-jade) - [Jade](http://jade-lang.com/) syntax support |
| 20 | + |
| 21 | +Most of the plugins have [live examples](http://sourcejs.com/specs/example-specs-showcase/) on the project website. |
| 22 | + |
| 23 | + ## Native Templating |
| 24 | + |
| 25 | + SourceJS uses powerful [EJS](http://ejs.co/) templating engine for core UI generation and Specs content processing. This means that any Spec file can use the full power of EJS templating logic. |
| 26 | + |
| 27 | + ```html |
| 28 | +<% if (info.title === 'Title') {% > Action! <% } %> |
| 29 | +``` |
| 30 | + |
| 31 | +Use plain JavaScript for managing conditions and generating demo content through data loops. All `info.json` file contents are by default available in each Spec scope. Apart from common [meta information](/docs/info-json) available in `info.json` files, it's possible to set any of your own custom data. |
| 32 | + |
| 33 | +```html |
| 34 | +<h2><%- info.title %></h2> |
| 35 | + |
| 36 | +<% var buttons = ['btn-group-lg', '', 'btn-group-sm', 'btn-group-xs'] %> |
| 37 | + |
| 38 | +<% buttons.forEach(function(modifier){ %> |
| 39 | + <div class="btn-group <%= modifier %>" role="group" aria-label="Default button group"> |
| 40 | + <button type="button" class="btn btn-default">Left</button> |
| 41 | + <button type="button" class="btn btn-default">Middle</button> |
| 42 | + <button type="button" class="btn btn-default">Right</button> |
| 43 | + </div><br><br> |
| 44 | +<% }); %> |
| 45 | +``` |
| 46 | + |
| 47 | +```example |
| 48 | +<%- include('examples/buttons.html') %> |
| 49 | +``` |
| 50 | + |
| 51 | +### Includes |
| 52 | + |
| 53 | +Providing a relative path to current Specs, it's easy to include any file. |
| 54 | + |
| 55 | +```html |
| 56 | +<%- include('examples/include.html') %> |
| 57 | +``` |
| 58 | + |
| 59 | +```example |
| 60 | +<%- include('examples/include.html') %> |
| 61 | +``` |
| 62 | + |
| 63 | +Note that by default, SourceJS restricts including files outside project directory for security reasons. To disable this restrictions, change `core.sandboxIncludes` configuration. |
| 64 | + |
| 65 | +<a href="https://github.com/sourcejs/Source/tree/master/docs/spec-helpers/examples" class="source_a_hl">View examples source code.</a> |
| 66 | + |
| 67 | + |
| 68 | +## EJS Custom Helpers |
| 69 | + |
| 70 | +Starting from v.0.5.6, SourceJS provides a set of custom EJS helpers: |
| 71 | + |
| 72 | +* `includeMD(path)` - include and process Markdown file |
| 73 | +* `includeFiles(glob)` - include a set of files by mask (uses [glob](https://github.com/isaacs/node-glob)) |
| 74 | + |
| 75 | +Feel free to create Pull Requests with a wider set of helpers. |
| 76 | + |
| 77 | +### includeMD |
| 78 | + |
| 79 | +```html |
| 80 | +<%- includeMD('examples/markdown-file') %> |
| 81 | +``` |
| 82 | + |
| 83 | +```example |
| 84 | +<%- includeMD('examples/markdown-file') %> |
| 85 | +``` |
| 86 | + |
| 87 | +### includeFiles |
| 88 | + |
| 89 | +```html |
| 90 | +<%- includeFiles('examples/mask-*.html') %> |
| 91 | +``` |
| 92 | + |
| 93 | +```example |
| 94 | +<%- includeFiles('examples/mask-*.html') %> |
| 95 | +``` |
| 96 | + |
| 97 | +<a href="https://github.com/sourcejs/Source/tree/master/docs/spec-helpers/examples" class="source_a_hl">View examples source code.</a> |
| 98 | + |
| 99 | +## Extended features |
| 100 | + |
| 101 | +For any other custom Spec content processing, we recommend building own SourceJS plugins. Follow our [instructions](/docs/api/plugins/) and example plugins for fast kick-off. |
| 102 | + |
| 103 | +It's also possible to configure custom build task, that will generate compatible Spec pages via Grunt/Gulp or any other build tool. |
0 commit comments