• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    JavaScript
  • Created almost 10 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple styleguide framework

Component Styleguide

Introduction

Simple styleguide framework. Install component-styleguide into your styleguide project, and it will stay out of your way. It's inspired by http://patternlab.io, but is fundamentally different. And, I would say, much more flexible.

What is it?

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.

See component-styleguide-example for an example setup (you could use this project as a boilerplate), and a live running example.

You can use it as a development server, and/or host it somewhere as a Node service.

Example Screenshot

image

Installation Steps

1. Install component-styleguide

npm install component-styleguide --save

2. Structure

Create a directory structure, like this:

.
β”œβ”€β”€ components
β”‚   β”œβ”€β”€ atoms
β”‚   β”œβ”€β”€ molecules
β”‚   └── organisms
└── data

3. Start

Write a minimal Node script (say index.js):

var styleguide = require('component-styleguide');
styleguide();

And run it: node index.js.

The styleguide is now running at http://localhost:3000.

4. Build Components

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.

Here is a screencast of a quick & dirty installation:

Installation

And here's the result in the browser:

Hello World

Configuration

You can work with the default settings straight away, but you might want to customize some things. By default:

  • 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.
  • The extension html is expected, but you can configure any other extension.
  • If you need stub data to feed to your templates, you can put *.json files in the /data directory.
  • To use your stylesheets, put filenames in the stylesheets array, and make sure these files are/end up in the /compiled directory (also configurable).
  • Same for scripts.

To specify alternative settings (showing default values here):

styleguide({
    components: './components',
    ext: 'html',
    data: './data',
    staticLocalDir: './compiled',
    staticPath: '/compiled',
    stylesheets: ['stylesheet.css'],
    scripts: ['bundle.js'],
});

Command Line Interface

Alternatively, the styleguide can be started directly from the CLI without any scripting involved:

styleguide

Here's an example with default settings:

styleguide --components components --ext html --data data

You would need to either install it globally (i.e. npm install -g component-styleguide), or use it from a package.json script.

Details

Handlebars

Handlebars is used as the template engine.

Partials

Each template is automatically registered as a partial (e.g. you can reuse your {{> atoms/component}} in templates).

Stub data

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:

{
   "users": [],
   "profile": {}
}

Now, the {{#users}} collection can be iterated over in any template.

If a there is a JSON file with the same name as the HTML file next to it, its data will be loaded in context data in priority over other data.

In this example, header.html will get data from header.json:

molecules
  header.html
  header.json

CSS & JS

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'].

Doh, yet another styleguide framework!?

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.

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.

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.

License

MIT

More Repositories

1

awesome-dotfiles

A curated list of dotfiles resources.
8,206
star
2

reveal-md

reveal.js on steroids! Get beautiful reveal.js presentations from any Markdown file
JavaScript
3,365
star
3

programming-principles

Categorized overview of programming principles & design patterns
2,424
star
4

knip

βœ‚οΈ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
TypeScript
1,842
star
5

dotfiles

Dotfiles for macOS
Shell
983
star
6

dyson

Node server for dynamic, fake JSON.
JavaScript
832
star
7

DOMtastic

Small, fast, and modular DOM and event library for modern browsers.
JavaScript
763
star
8

awesome-newsletters

The best (weekly) newsletters
379
star
9

Automated-SPA-Testing

Automated unit & functional testing for web applications
105
star
10

responsive-web-apps

Building Responsive Web Applications
JavaScript
63
star
11

grunt-release-it

Interactive release task for Git repositories. Optionally release a build to distribution/component repository.
JavaScript
48
star
12

versionify

Browserify transform to replace placeholder with package version
JavaScript
33
star
13

react-redux-demo

Fun Fair
JavaScript
30
star
14

baseplate

The baseplate project provides excellent workflow & tooling to develop, build, and test non-trivial SPAs.
JavaScript
24
star
15

bron

πŸƒβ€β™‚οΈ Fast & tiny test runner for Node.js
JavaScript
18
star
16

frameground

Compare JavaScript Frameworks. Please share your knowledge!
JavaScript
17
star
17

dyson-generators

Fake data generators, used by dyson and dyson-image
JavaScript
17
star
18

dyson-demo

Demo package for dyson
JavaScript
14
star
19

requirejs-handlebars

Simple Handlebars plugin for RequireJS
JavaScript
13
star
20

precompiled-templates

Performance, footprint and configuration of template engines and precompiled templates
JavaScript
12
star
21

ts-morph-helpers

Helpers for ts-morph
TypeScript
12
star
22

component-styleguide-example

Example for component-styleguide
CSS
9
star
23

DuckJS

Tiny and powerful module loader to lazy load HTML+CSS+JS
JavaScript
8
star
24

benchrunner

Benchmark Suite Runner for benchmark.js
JavaScript
8
star
25

sandbox

Source files for sandbox.webpro.nl (offline)
JavaScript
6
star
26

dyson-image

JavaScript
6
star
27

webpro.nl

Source code of webpro.nl
Astro
6
star
28

doxstrap

Yet another documentation generator
HTML
5
star
29

vars

Common patterns in Vue, Angular, React and Svelte
JavaScript
5
star
30

parse-openapi

OpenAPI v3 parser
TypeScript
5
star
31

nx-tsc

Nx executor to type-check project source files using `tsc --noEmit`
JavaScript
5
star
32

hyte

HYbrid TEmplating for the browser and Node
JavaScript
4
star
33

Websites-vs-Web-Applications

Responsive Adaptive Rainwebs FTW!
4
star
34

release-it-monorepo

4
star
35

github-pages-example

GitHub Pages Example
3
star
36

bookstore

Simple application to learn GraphQL and Next.js.
JavaScript
3
star
37

markdown-rambler

Yet another opinionated & powerful static site generator.
TypeScript
3
star
38

bump-file

Bump JSON files (e.g. package.json and friends)
JavaScript
3
star
39

openapi-parser

OpenAPI v3 parser
TypeScript
2
star
40

fix-sourcemaps

Fix sources and file in sourcemaps
JavaScript
2
star
41

jaguarundi

Ant build script to optimize and version Javascript, CSS, and HTML files
JavaScript
2
star
42

requirejs-hogan

Simple Hogan plugin for RequireJS
JavaScript
2
star
43

requirejs-dust

Simple Dust plugin for RequireJS
JavaScript
2
star
44

deprecated-obj

Compares deprecations against a configuration object, and returns a compliant object and violations
JavaScript
2
star
45

DOMtastic-release

JavaScript
1
star
46

is-subdir

Check if a directory is a subdirectory
JavaScript
1
star
47

SpringbokJS

Installs modules (traditional object or AMD-style) based on HTML attributes.
JavaScript
1
star
48

last-publish

Get the date of the last published version of a package in the npm registry
JavaScript
1
star