├── .npmignore
├── README.md
├── bin
└── styleguide.js
├── client
├── all.html
├── component.html
├── jquery-1.11.1.min.js
├── styleguide.css
├── styleguide.html
├── styleguide.js
├── svg4everybody.ie8.min.js
└── svgdefs.svg
├── hello-world.gif
├── installation.gif
├── package.json
├── screenshot.png
└── server
├── index.js
└── util.js
/.npmignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Component Styleguide
2 |
3 | ## Introduction
4 |
5 | Simple styleguide framework. Install [component-styleguide](https://www.npmjs.com/package/component-styleguide) into your styleguide project, and it will stay out of your way. It's inspired by [http://patternlab.io](http://patternlab.io), but is fundamentally different. And, I would say, much more flexible.
6 |
7 | ## What is it?
8 |
9 | Simple. You start out with a blank project. Your codebase contains just your own HTML templates and CSS stylesheets (and JavaScript if you want to). Put your files in some (configurable) directories, and there you have it.
10 |
11 | See [component-styleguide-example](http://github.com/webpro/component-styleguide-example) for an example setup (you could use this project as a boilerplate), and a [live running example](https://component-styleguide.now.sh).
12 |
13 | You can use it as a development server, and/or host it somewhere as a Node service.
14 |
15 | ## Example Screenshot
16 |
17 | 
18 |
19 | ## Installation Steps
20 |
21 | ### 1. Install component-styleguide
22 |
23 | npm install component-styleguide --save
24 |
25 | ### 2. Structure
26 |
27 | Create a directory structure, like this:
28 |
29 | .
30 | ├── components
31 | │ ├── atoms
32 | │ ├── molecules
33 | │ └── organisms
34 | └── data
35 |
36 | ### 3. Start
37 |
38 | Write a minimal Node script (say `index.js`):
39 |
40 | var styleguide = require('component-styleguide');
41 | styleguide();
42 |
43 | And run it: `node index.js`.
44 |
45 | The styleguide is now running at [http://localhost:3000](http://localhost:3000).
46 |
47 | #### 4. Build Components
48 |
49 | Put templates and partials in the `components` directory and subdirectories (e.g. `atoms`, `molecules`, and `organisms`, but this is not mandatory). They should be files ending with `.html` and contain HTML snippets or Handlebars templates.
50 |
51 | Here is a screencast of a quick & dirty installation:
52 |
53 | 
54 |
55 | And here's the result in the browser:
56 |
57 | 
58 |
59 | ## Configuration
60 |
61 | You can work with the default settings straight away, but you might want to customize some things. By default:
62 |
63 | * Use `atoms`, `molecules`, and `organisms`, `templates` and `pages`, and they will show up in that order and as an icon. But you can name the directories any way you like.
64 | * The extension `html` is expected, but you can configure any other extension.
65 | * If you need [stub data](#stub-data) to feed to your templates, you can put `*.json` files in the `/data` directory.
66 | * To use your stylesheets, put filenames in the `stylesheets` array, and make sure these files are/end up in the `/compiled` directory (also configurable).
67 | * Same for `scripts`.
68 |
69 | To specify alternative settings (showing default values here):
70 |
71 | styleguide({
72 | components: './components',
73 | ext: 'html',
74 | data: './data',
75 | staticLocalDir: './compiled',
76 | staticPath: '/compiled',
77 | stylesheets: ['stylesheet.css'],
78 | scripts: ['bundle.js'],
79 | });
80 |
81 | ## Command Line Interface
82 |
83 | Alternatively, the styleguide can be started directly from the CLI without any scripting involved:
84 |
85 | styleguide
86 |
87 | Here's an example with default settings:
88 |
89 | styleguide --components components --ext html --data data
90 |
91 | You would need to either install it globally (i.e. `npm install -g component-styleguide`), or use it from a `package.json` [script](https://docs.npmjs.com/misc/scripts).
92 |
93 | ## Details
94 |
95 | ### Handlebars
96 |
97 | [Handlebars](http://handlebarsjs.com) is used as the template engine.
98 |
99 | ### Partials
100 |
101 | Each template is automatically registered as a partial (e.g. you can reuse your `{{> atoms/component}}` in templates).
102 |
103 | ### Stub data
104 |
105 | All "data" files are concatenated into one "context" for the templates. E.g. `users.json` containing `[]` and `profile.json` containing `{}` will result in context data for the templates:
106 |
107 | {
108 | "users": [],
109 | "profile": {}
110 | }
111 |
112 | Now, the `{{#users}}` collection can be iterated over in any template.
113 |
114 | If a there is a JSON file with the same name as the HTML file next to it, its data will be loaded
115 | in context data in priority over other data.
116 |
117 | In this example, `header.html` will get data from `header.json`:
118 |
119 | ```
120 | molecules
121 | header.html
122 | header.json
123 | ```
124 |
125 | ### CSS & JS
126 |
127 | You can organize and compile your CSS and JavaScript in any way you want, as long as they end up in e.g. `/compiled` (the `staticLocalDir`) to serve them with the components. I think it's a good idea to work directly in this folder, or compile SASS/LESS/... source files into e.g. `compiled/stylesheet.css` and configure it as `stylesheets: ['stylesheet.css']`.
128 |
129 | ## Doh, yet another styleguide framework!?
130 |
131 | Since I didn't like the approach of most styleguide tools, I created something I actually enjoy to use. It stays out of my way, so I can focus on the components.
132 |
133 | Some solutions generate a styleguide from comments in the CSS. But I like to have separate templates, maybe some stub data, maybe some JavaScript. Other tools provide a boilerplate project, which may work fine at first, but it is hard to change or update the underlying styleguide framework later on.
134 |
135 | As a Node.js dependency, features and bugs can be dealt with separately. You only need to update the `component-styleguide` dependency (`npm update`), without having to fork a repository and/or merge upstream changes, and it will happily continue to just serve your templates and static assets. Simple.
136 |
137 | ## License
138 |
139 | [MIT](http://webpro.mit-license.org)
140 |
--------------------------------------------------------------------------------
/bin/styleguide.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var path = require('path'),
4 | parseArgs = require('minimist'),
5 | styleguide = require('../server');
6 |
7 | var argv = parseArgs(process.argv.slice(2));
8 |
9 | styleguide({
10 | components: argv.components ? path.resolve(argv.components) : null,
11 | ext: argv.ext,
12 | data: argv.data ? path.resolve(argv.data) : null,
13 | static: argv.static ? path.resolve(argv.static) : null
14 | });
15 |
--------------------------------------------------------------------------------
/client/all.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |