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 |
|
14 | This project requires [Node.js](https://nodejs.org) and [npm](https://npmjs.com) to be installed prior to development work.
|
15 |
|
16 | ### Package Dependencies
|
17 |
|
18 | Installing 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 |
|
26 | Once you've installed all the dependencies, building the package can be accomplished with:
|
27 |
|
28 | ```shell
|
29 | $ npm run build
|
30 | ```
|
31 |
|
32 | To watch for changes:
|
33 |
|
34 | ```shell
|
35 | $ npm run watch
|
36 | ```
|
37 |
|
38 | To start a local development server with hot reloading:
|
39 |
|
40 | ```shell
|
41 | $ npm run start # or simply "npm start"
|
42 | ```
|
43 |
|
44 | ### Testing
|
45 |
|
46 | To run tests:
|
47 |
|
48 | ```shell
|
49 | $ npm run test # or simply "npm test"
|
50 | ```
|
51 |
|
52 | ## Style Guide
|
53 |
|
54 | The Bonsai Style Guide is dynamically generated using the [zurb/supercollider](http://www.github.com/zurb/supercollider)
|
55 | library.
|
56 |
|
57 | To contribute to the Bonsai documentation and style guide, you will want to run it locally.
|
58 |
|
59 | ### Running Locally
|
60 |
|
61 | You'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
|
71 | redirected to the index of the style guide
|
72 |
|
73 | Any 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 |
|
83 | Let's say that JSTOR is going to create a new feature giving esteemed researchers a plethora of new tools for their study of cats.
|
84 | Suddenly the style guide needs a page about cats! Here's how you'd make it.
|
85 |
|
86 | Create 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 | ---
|
94 | title: Cats Cats Cats!
|
95 | description: 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 |
|
107 | The bulk of the content for each page can be markdown, html, or a mix of the two
|
108 |
|
109 |
|
110 | If you want to dynamically include the sass or js documentation for the cats component, simply add it in the header of
|
111 | the markdown file. Both `sass` and `js` are optional.
|
112 |
|
113 | ```markdown
|
114 |
|
115 | ---
|
116 | title: Cats Cats Cats!
|
117 | description: Guidelines for the JSTOR Cats feature set
|
118 | sass: ./scss/_cats.scss
|
119 | js: ./js/bonsai.cats.js
|
120 | ---
|
121 |
|
122 | ```
|
123 |
|
124 | Additionally, supercollider allows the creation custom adapters if types of documentation other than html, sass, and js
|
125 | need to be dynamically generated.
|
126 |
|
127 |
|
128 | #### HTML Examples
|
129 |
|
130 | When documenting how to use a component, you may want to include example code. Giving the markdown block
|
131 | the language level of `html_example` will insert the rendered html directly after the markdown example.
|
132 |
|
133 | For example this:
|
134 |
|
135 | `````markdown
|
136 | ```html_example
|
137 | <button>I am button</button>
|
138 | ```
|
139 | `````
|
140 |
|
141 | will display the literal code, plus the rendered button afterwards.
|
142 |
|
143 | #### Routing
|
144 |
|
145 | After making the markdown file, but probably before you put all your content in there, you should add it to the routes.
|
146 | Go 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
|
151 | module.exports = [
|
152 | "button",
|
153 | "modal"
|
154 | ]
|
155 | ```
|
156 |
|
157 | _`routes.js`_ after
|
158 |
|
159 | ```javascript
|
160 | module.exports = [
|
161 | "button",
|
162 | "modal",
|
163 | "cats"
|
164 | ]
|
165 | ```
|
166 |
|
167 | By adding "cats" to this array, we enable hot reloading for the `cats.md` file as well as add an option for "Cats" in the
|
168 | navigation 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 |
|
183 | 1. Webpack is run, processing all the files defined in the entry object in `webpack.config.js`
|
184 | 1. Once all the files are processed, the `WebpackShellPlugin` runs `node generate-docs.js`
|
185 | 1. `generate-docs.js` contains the SuperCollider configuration and initialization.
|
186 | 1. 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
|
190 | 1. A development server is launched at localhost:8080
|
191 |
|
192 | The development server is now watching the sass, javascript, markdown, and main template for changes.
|
193 | It does this because all these files are run through webpack (even though they're not all compiled)
|
194 |
|
195 | In `js/index.js` the main handlebar template is imported, as well as an array of all the names of the
|
196 | individual components that are a part of the style guide. Iterating through the array, every markdown file
|
197 | is also imported into the `js/index.js`.
|
198 |
|
199 | We don't tell webpack what to do with these files, but we do **have** to give webpack a loader for `.html` and `.md`
|
200 | files. There are rules setup to run html and md through the `raw-loader`. Now webpack is aware of everything,
|
201 | and 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 |
|
205 | Everything that gets merged into the `develop` branch will become a `beta` release
|
206 |
|
207 | Everything that gets merged into the `master` branch will become a `latest` release.
|
208 |
|
209 | Please note that each pull request that is being merged into either of these branches need to have an updated version
|
210 | in the `package.json` file so that the `npm publish` can succeed.
|
211 |
|
212 | Jenkins jobs that automate these releases exist here:
|
213 | http://jenkins.test.cirrostratus.org:8080/job/build-bonsai-develop/
|
214 | http://jenkins.test.cirrostratus.org:8080/job/build-bonsai-master/
|