UNPKG

6.27 kBMarkdownView Raw
1# Bonsai
2_ITHAKA core styling and JavaScript functionality_
3
4## Installation
5
6```shell
7$ npm install @ithaka/bonsai
8```
9
10## Development
11
12### System Dependencies
13
14This project requires [Node.js](https://nodejs.org) and [npm](https://npmjs.com) to be installed prior to development work.
15
16### Package Dependencies
17
18Installing all necessary dependencies for building the package should be as simple as:
19
20```shell
21$ npm install
22```
23
24### Building the package
25
26Once you've installed all the dependencies, building the package can be accomplished with:
27
28```shell
29$ npm run build
30```
31
32To watch for changes:
33
34```shell
35$ npm run watch
36```
37
38To start a local development server with hot reloading:
39
40```shell
41$ npm run start # or simply "npm start"
42```
43
44### Testing
45
46To run tests:
47
48```shell
49$ npm run test # or simply "npm test"
50```
51
52## Style Guide
53
54The Bonsai Style Guide is dynamically generated using the [zurb/supercollider](http://www.github.com/zurb/supercollider)
55library.
56
57To contribute to the Bonsai documentation and style guide, you will want to run it locally.
58
59### Running Locally
60
61You'll need [`node`](https://nodejs.org/en/) and `git` installed on your machine.
62
63```bash
64$ git clone https://github.com/ithaka/bonsai.git
65$ cd bonsai
66$ npm install # this could take a few minutes
67$ npm run start
68```
69
70`$ npm run start` will launch the development server on http://localhost:8080. Navigate there and you will be
71redirected to the index of the style guide
72
73Any time a file change is saved the documentation will recompile. Refresh the page to see your change.
74
75### Making a new page in the style guide
76
77_You might want to write the documentation in Markdown_
78
79[Learn Markdown](https://daringfireball.net/projects/markdown/syntax)
80
81[Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
82
83Let's say that JSTOR is going to create a new feature giving esteemed researchers a plethora of new tools for their study of cats.
84Suddenly the style guide needs a page about cats! Here's how you'd make it.
85
86Create a markdown file (`cats.md`) in `documentation/pages/`. At the very minimum it needs a title, description, and content.
87
88_`documentation/pages/cats.md`_
89
90
91```markdown
92
93---
94title: Cats Cats Cats!
95description: Guidelines for the JSTOR Cats feature set
96---
97
98<!-- here down can be a mix of HTML and Markdown -->
99
100![](kitten.jpeg)
101
102<div class="cat-container">
103 <p class="cat">CAT</p>
104</div>
105```
106
107The bulk of the content for each page can be markdown, html, or a mix of the two
108
109
110If you want to dynamically include the sass or js documentation for the cats component, simply add it in the header of
111the markdown file. Both `sass` and `js` are optional.
112
113```markdown
114
115---
116title: Cats Cats Cats!
117description: Guidelines for the JSTOR Cats feature set
118sass: ./scss/_cats.scss
119js: ./js/bonsai.cats.js
120---
121
122```
123
124Additionally, supercollider allows the creation custom adapters if types of documentation other than html, sass, and js
125need to be dynamically generated.
126
127
128#### HTML Examples
129
130When documenting how to use a component, you may want to include example code. Giving the markdown block
131the language level of `html_example` will insert the rendered html directly after the markdown example.
132
133For example this:
134
135`````markdown
136```html_example
137<button>I am button</button>
138```
139`````
140
141will display the literal code, plus the rendered button afterwards.
142
143#### Routing
144
145After making the markdown file, but probably before you put all your content in there, you should add it to the routes.
146Go to `documentation/routes/js`, and add a line in the array that has the name of your markdown file.
147
148_`routes.js`_ before
149
150```javascript
151module.exports = [
152 "button",
153 "modal"
154]
155```
156
157_`routes.js`_ after
158
159```javascript
160module.exports = [
161 "button",
162 "modal",
163 "cats"
164]
165```
166
167By adding "cats" to this array, we enable hot reloading for the `cats.md` file as well as add an option for "Cats" in the
168navigation of the style guide
169
170## The Style Guide Build System
171
172* webpack
173 * webpack-shell-plugin
174 * raw-loader
175* supercollider
176 * foundation-docs custom markdown interpreter
177* handlebars
178
179### What happens when running `npm run start`?
180
181![](https://i.imgflip.com/1tlvet.jpg)
182
1831. Webpack is run, processing all the files defined in the entry object in `webpack.config.js`
1841. Once all the files are processed, the `WebpackShellPlugin` runs `node generate-docs.js`
1851. `generate-docs.js` contains the SuperCollider configuration and initialization.
1861. SuperCollider generates the html by taking all the markdown templates, running them through the markdown interpreter,
187 getting the sassDocs and jsDocs associated with each markdown file, and running them all through the primary
188 handlebars template. This is then all output as raw html to `documentation/styleguide/`. These settings are all in
189 the `generate-docs.js` file
1901. A development server is launched at localhost:8080
191
192The development server is now watching the sass, javascript, markdown, and main template for changes.
193It does this because all these files are run through webpack (even though they're not all compiled)
194
195In `js/index.js` the main handlebar template is imported, as well as an array of all the names of the
196individual components that are a part of the style guide. Iterating through the array, every markdown file
197is also imported into the `js/index.js`.
198
199We don't tell webpack what to do with these files, but we do **have** to give webpack a loader for `.html` and `.md`
200files. There are rules setup to run html and md through the `raw-loader`. Now webpack is aware of everything,
201and anytime something it's aware of changes it runs through the above steps again, minus launching a duplicate server.
202
203### Publishing to NPM
204
205Everything that gets merged into the `develop` branch will become a `beta` release
206
207Everything that gets merged into the `master` branch will become a `latest` release.
208
209Please note that each pull request that is being merged into either of these branches need to have an updated version
210in the `package.json` file so that the `npm publish` can succeed.
211
212Jenkins jobs that automate these releases exist here:
213http://jenkins.test.cirrostratus.org:8080/job/build-bonsai-develop/
214http://jenkins.test.cirrostratus.org:8080/job/build-bonsai-master/