Skip to content

Commit

Permalink
#123: add spec rendering helpers doc
Browse files Browse the repository at this point in the history
  • Loading branch information
robhrt7 committed Sep 20, 2015
1 parent ad17ec3 commit b3bb32b
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/base/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ By default all files are pre-processed with [EJS](http://ejs.co/), so you're fre
<% if (info.title === 'Title') {% > Action! <% } %>
```

<a href="/docs/spec-helpers" class="source_a_hl">Read more about Spec page generation helpers.</a>

### Client-side Templating Engines

For client-side templating you don't need any magic, just link Mustache or any other JS library to your page and use it whenever you want.
Expand Down Expand Up @@ -167,11 +169,12 @@ As a Style Guide Platform we focus on flexibility and ease of integration. All S

Plugins are working in the same way as core modules, but are kept outside the main platform, allowing to separate specific features.

Here is a list of official plugins:
Here is a list of available plugins:

* [sourcejs-md-react](https://www.npmjs.com/package/sourcejs-md-react) (new)
* [sourcejs-slm](https://github.com/venticco/sourcejs-slm) (new)
* [sourcejs-md-react](https://github.com/mik01aj/sourcejs-md-react) (new)
* [sourcejs-contrib-browser-sync](https://github.com/sourcejs/sourcejs-contrib-browser-sync) (new)
* [sourcejs-react](https://www.npmjs.com/package/sourcejs-react) (new)
* [sourcejs-react](https://github.com/szarouski/sourcejs-react) (new)
* [sourcejs-contrib-dss](http://github.com/sourcejs/sourcejs-contrib-dss) (new)
* [sourcejs-spec-status](https://github.com/sourcejs/sourcejs-spec-status)
* [sourcejs-crowd-voice](https://github.com/sourcejs/sourcejs-crowd-voice)
Expand Down
11 changes: 11 additions & 0 deletions docs/spec-helpers/examples/buttons.html
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>
<% }); %>
1 change: 1 addition & 0 deletions docs/spec-helpers/examples/include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Included file from `spec-helpers/examples/include.html`.
1 change: 1 addition & 0 deletions docs/spec-helpers/examples/markdown-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed **Markdown** file.
1 change: 1 addition & 0 deletions docs/spec-helpers/examples/mask-one.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
one<br>
2 changes: 2 additions & 0 deletions docs/spec-helpers/examples/mask-two.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
two<br>
<%- includeFiles('three.html') %>
1 change: 1 addition & 0 deletions docs/spec-helpers/examples/three.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
three<br>
5 changes: 5 additions & 0 deletions docs/spec-helpers/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"keywords": "ejs, include",
"title": "Spec Rendering Helpers",
"template": "doc"
}
103 changes: 103 additions & 0 deletions docs/spec-helpers/readme.md
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
&lt;% if (info.title === 'Title') {% &gt; Action! &lt;% } %&gt;
```

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
&lt;h2&gt;&lt;%- info.title %&gt;&lt;/h2&gt;

&lt;% var buttons = ['btn-group-lg', '', 'btn-group-sm', 'btn-group-xs'] %&gt;

&lt;% buttons.forEach(function(modifier){ %&gt;
&lt;div class="btn-group &lt;%= modifier %&gt;" role="group" aria-label="Default button group"&gt;
&lt;button type="button" class="btn btn-default"&gt;Left&lt;/button&gt;
&lt;button type="button" class="btn btn-default"&gt;Middle&lt;/button&gt;
&lt;button type="button" class="btn btn-default"&gt;Right&lt;/button&gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;
&lt;% }); %&gt;
```

```example
<%- include('examples/buttons.html') %>
```

### Includes

Providing a relative path to current Specs, it's easy to include any file.

```html
&lt;%- include('examples/include.html') %&gt;
```

```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
&lt;%- includeMD('examples/markdown-file') %&gt;
```

```example
<%- includeMD('examples/markdown-file') %>
```

### includeFiles

```html
&lt;%- includeFiles('examples/mask-*.html') %&gt;
```

```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.

0 comments on commit b3bb32b

Please sign in to comment.