-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#123: add spec rendering helpers doc
- Loading branch information
Showing
9 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h2><%- info.title %></h2> | ||
|
||
<% var buttons = ['btn-group-lg', '', 'btn-group-sm', 'btn-group-xs'] %> | ||
|
||
<% buttons.forEach(function(modifier){ %> | ||
<div class="btn-group <%= modifier %>" role="group" aria-label="Default button group"> | ||
<button type="button" class="btn btn-default">Left</button> | ||
<button type="button" class="btn btn-default">Middle</button> | ||
<button type="button" class="btn btn-default">Right</button> | ||
</div><br><br> | ||
<% }); %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Included file from `spec-helpers/examples/include.html`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Processed **Markdown** file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
one<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
two<br> | ||
<%- includeFiles('three.html') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
three<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"keywords": "ejs, include", | ||
"title": "Spec Rendering Helpers", | ||
"template": "doc" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
## Intro | ||
|
||
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. | ||
|
||
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). | ||
|
||
Let's dive deeper into each of available Spec generation features. | ||
|
||
## Plugins | ||
|
||
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. | ||
|
||
Here's a list of all Spec generation focused plugins: | ||
|
||
* [sourcejs-slm](https://github.com/venticco/sourcejs-slm) - [Slim](http://slim-lang.com/) templates support | ||
* [sourcejs-md-react](https://github.com/mik01aj/sourcejs-md-react) - Markdown helpers for rendering React components | ||
* [sourcejs-react](https://github.com/szarouski/sourcejs-react) - generate specs from JSX files | ||
* [sourcejs-contrib-dss](http://github.com/sourcejs/sourcejs-contrib-dss) - generating documentation out of CSS comments | ||
* [sourcejs-jade](https://github.com/sourcejs/sourcejs-jade) - [Jade](http://jade-lang.com/) syntax support | ||
|
||
Most of the plugins have [live examples](http://sourcejs.com/specs/example-specs-showcase/) on the project website. | ||
|
||
## Native Templating | ||
|
||
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. | ||
|
||
```html | ||
<% if (info.title === 'Title') {% > Action! <% } %> | ||
``` | ||
|
||
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. | ||
|
||
```html | ||
<h2><%- info.title %></h2> | ||
|
||
<% var buttons = ['btn-group-lg', '', 'btn-group-sm', 'btn-group-xs'] %> | ||
|
||
<% buttons.forEach(function(modifier){ %> | ||
<div class="btn-group <%= modifier %>" role="group" aria-label="Default button group"> | ||
<button type="button" class="btn btn-default">Left</button> | ||
<button type="button" class="btn btn-default">Middle</button> | ||
<button type="button" class="btn btn-default">Right</button> | ||
</div><br><br> | ||
<% }); %> | ||
``` | ||
|
||
```example | ||
<%- include('examples/buttons.html') %> | ||
``` | ||
|
||
### Includes | ||
|
||
Providing a relative path to current Specs, it's easy to include any file. | ||
|
||
```html | ||
<%- include('examples/include.html') %> | ||
``` | ||
|
||
```example | ||
<%- include('examples/include.html') %> | ||
``` | ||
|
||
Note that by default, SourceJS restricts including files outside project directory for security reasons. To disable this restrictions, change `core.sandboxIncludes` configuration. | ||
|
||
<a href="https://github.com/sourcejs/Source/tree/master/docs/spec-helpers/examples" class="source_a_hl">View examples source code.</a> | ||
|
||
|
||
## EJS Custom Helpers | ||
|
||
Starting from v.0.5.6, SourceJS provides a set of custom EJS helpers: | ||
|
||
* `includeMD(path)` - include and process Markdown file | ||
* `includeFiles(glob)` - include a set of files by mask (uses [glob](https://github.com/isaacs/node-glob)) | ||
|
||
Feel free to create Pull Requests with a wider set of helpers. | ||
|
||
### includeMD | ||
|
||
```html | ||
<%- includeMD('examples/markdown-file') %> | ||
``` | ||
|
||
```example | ||
<%- includeMD('examples/markdown-file') %> | ||
``` | ||
|
||
### includeFiles | ||
|
||
```html | ||
<%- includeFiles('examples/mask-*.html') %> | ||
``` | ||
|
||
```example | ||
<%- includeFiles('examples/mask-*.html') %> | ||
``` | ||
|
||
<a href="https://github.com/sourcejs/Source/tree/master/docs/spec-helpers/examples" class="source_a_hl">View examples source code.</a> | ||
|
||
## Extended features | ||
|
||
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. | ||
|
||
It's also possible to configure custom build task, that will generate compatible Spec pages via Grunt/Gulp or any other build tool. |