#
Installation

Infusion is built using the static site engine, Hugo, and NPM. The codebase is available to download on Github. Let’s get set up step-by-step.

## Install Hugo

First you need to install Hugo globally.

### OSX users

If you are a Mac user and have Homebrew on your system, installing Hugo is simple:

    brew install hugo

Alternatively, you can manually install Hugo from a package. You can verify the installation was successful by typing:

    hugo version

### Windows users

Installing on Windows is a bit more involved than on OSX. The authors of Hugo provide a guide with instructions for technical and less technical users.

## Install Node & NPM

It is likely you already have Node and NPM installed on your system. If so, you can skip this step. Otherwise, refer to NPM’s own guide, which includes a video tutorial.

## Get the files

Infusion is hosted on Github. To start using it, you’ll need to get the files from there. If you are comfortable with the command line, just fork the github.com/heydon/infusion repository, then do a `git clone` to your local system. Replace `[your username]` in the following:

    git clone https://github.com/[your username]/infusion.git

If the command line is not your thing, fork github.com/heydon/infusion and choose Open in Desktop from Clone or download (see figure 1, below).

The Github web interface

If you do not have a version of the Github desktop client installed, follow the prompts after clicking Open in Desktop.

Once you have your local copy of the files, move to the root of that folder and in your terminal run an npm installation:

    npm install

Now it’s time to consult the
Library setup pattern.

#
Library setup

By now, you should have followed the
Installation instructions. You should have Hugo and Node installed, and a local copy of a forked version of Infusion. You should also have run `npm install` in the root of that codebase.

## “Cleaning” the content folder

Before you can start documenting patterns, there are a few things still to do in order to get set up. At the moment, your version of Infusion is a facsimile of the original, containing all this documentation content. We want to delete that content and replace it with some starter content. There’s a simple `clean` command for this.

If you are contributing to an existing Infusion library, do not run the following command. It will delete all of the patterns in that library. The `clean` command is just for libraries that you are starting from scratch.

      npm run clean

This will leave your `content` folder with just an `_index.md` file and a `patterns` folder containing a single demonstration pattern file. Find out more about these in
Library structure.

## The config file

You’ll also want to name your library and configure one or two other things in the `config.toml` file that’s found at the root of your project. Here’s how that file looks:

    languageCode = "en-us"
    title = "Infusion"
    baseURL = "https://heydon.github.io/infusion/"
    theme = "infusion"

    [params]
      description = "Documentation for the **Infusion** pattern library builder. This documentation is constructed using the builder itself."
      codePenUser = "Heydon"

- title — This is the library’s name, like “Megacorp 5000 Pattern Library”. You don’t have to include the term “pattern library” if you don’t want to. For Infusion’s own version of Infusion, the `title` is, naturally, Infusion :-)
- baseURL — This is the root of the live site. Typically you will publish the site to Github Pages, so this should be the base URL for your Github Pages site.
- theme — This is the theme the library is using. Don’t change this from “infusion”.
- description — This is a short description of the library and comes under the logo. You can include markdown syntax here, like **Infusion** in the above example for making the name of the library bold.
- codePenUser — If you want to embed codePens in your pattern files, you need to supply a codePen username here.

## Including a logo

In the `images/static` folder, you’ll find a `logo.png` file. Replace this file with your own company or project logo. Currently, only the PNG format is supported.

Now that your logo’s in place, everything should be ready. Where next? You can learn about
Library structure to help you get writing, or find out how to serve the library locally and on Github Pages in
Serving.

#
Serving

## Serving locally

While you’re creating content for your library, you’ll probably want to see what the finished product looks like. Fortunately, Infusion is easy to serve locally using the `serve` command:

    npm run serve

This will serve your working library from `localhost:1313`. Whenever you make changes to your library’s files, the site will automatically rebuild. No need to refresh the web page!

## Publishing on Github Pages

Infusion creates a `/docs` folder containing the latest version of your library whenever you do an `npm run build` or a `git commit`. This folder can be made the source for your Github Pages site by selecting it under Settings → Github Pages → Source in the web interface.

Then, whenever you push to master, you will also be updating the site found at your Github Pages URL.

This URL will be in the following format:

    [your user name].github.io/[your library repo name]

You’ll also need to add it to your `config.toml` file as the `baseURL` value. See
Library setup for more information.

#
Library structure

Before you can set about documenting patterns, you need to know where everything goes. The simplest folder structure looks like this:

- content
  - _index.md
  - print-version.md
  - patterns
    - name-of-my-pattern.md
    - name-of-my-other-pattern.md

- /content - This is where all of your content lives. You won’t need to visit any other folders very frequently.
- _index.md — This is the content file for your home page.
- print-version.md — This is a placeholder for the single-page / print-friendly version of you library. Leave this file as it is.
- /patterns — This is the folder where individual pattern files are kept.

## Subsections

You may have noticed that this site’s navigation is divided partly into subsections, with labels like “Writing”. Infusion (or, rather, Hugo) allows you to create such subsections by simply nesting folders under the `/patterns` folder. In the following example, I have a subsection about different types of “popup” pattern.

- content
  - _index.md
  - patterns
    - name-of-my-pattern.md
    - name-of-my-other-pattern.md
    - popups
      - _index.md
      - popup-menu.md
      - tooltips.md

Note that subfolders like `/popups` must each have an `_index.md` file. This file doesn’t need any content except the TOML metadata defining the title (name) of that subsection:

    +++
    title = "Popups"
    +++

The `/patterns` folder itself does not need indexing explicitly in this way.

Infusion does not currently support sub-subsections.

Now that you know where to put everything, it’s time to talk about how to actually write individual patterns. Don’t worry, it’s pretty straightforward. Turn to
Markdown & metadata.

#
Markdown & metadata

In Infusion, design patterns are documented using markdown. To create a new pattern file, just add a file with the `.md` extension to the `/patterns` folder. It’s recommended you use “kebab case” to name the file ( words separated by hyphens). For example, a pattern with the title “Menu button” should probably have the filename `menu-button`. Then you get a nice clean URL: `username.github.io/your-library/patterns/menu-button`.

If you’re not familiar with writing markdown, there are a number of tutorials available. One of the best is Mastering Markdown offered by Github. There’s also a nice cheatsheet here.

## The metadata

Like many static site generators, Hugo lets you add metadata to its markdown files. Hugo’s brand of metadata is called TOML (although YAML is also accepted). The only thing you have to put in the TOML is a `title` — like this:

    +++
    title = "Menu button"
    +++

### Tags

If you like, you can also tag the pattern so that it turns up in lists of similar content. You add tags in an array format. Note that all the TOML data is found at the top of the markdown file, between the `+++` lines.

    +++
    title = "Menu button"
    tags = ["interactive", "popup", "javascript"]
    +++

This will create links to pages listing content tagged with the same terms using the URL schema `/tag/[tag name]`. Some example tags links are provided for this page, which you can see listed under the main heading.

### Weight

By default, patterns are listed in alphabetical order. However, sometimes you might like to change the order around. This is possible by adding a `weight` parameter. To make my menu button pattern appear at the top of its subsection, I would give it a `weight` of `1`:

    +++
    title = "Menu button"
    tags = ["interactive", "popup", "javascript"]
    weight = 1
    +++

The `weight` parameter should be an integer, not a string, so don’t use scare quotes around the value!

#
Expandable sections

In some cases, where there is a lot of content, it’s helpful to collapse certain sections. That way, readers get an overview of what’s in the content and can choose where to focus in. Infusion provides a shortcode method for creating expandable sections which generates accessible markup using `aria-expanded`.

The `expandable` shortcode takes three parameters:

- label — This is the label for the the section heading.
- level — This is the heading level (e.g. `level="2"` for a `<h2>`) that will contain the label. If you omit a level parameter, no heading is used; it’s just a button.
- open — Include this and give it a value of “true” or “yes” to make the section expanded on page load.

Here’s what the code might look like for a simple expandable section containing markdown:

    {{% expandable label="A section of dummy text" level="2" %}}
    Here is some markdown including [a link](https://twitter.com/heydonworks). Donec erat est, feugiat a est sed, aliquet pharetra ipsum. Vivamus in arcu leo. Praesent feugiat, purus a molestie ultrices, libero massa iaculis ante, sit amet accumsan leo eros vel ligula.
    {{% /expandable %}}

Let’s look at what that outputs:

##

Here is some markdown including a link. Donec erat est, feugiat a est sed, aliquet pharetra ipsum. Vivamus in arcu leo. Praesent feugiat, purus a molestie ultrices, libero massa iaculis ante, sit amet accumsan leo eros vel ligula.

Successive collapsible sections fit snugly together. The second of the following two has `open="true"`.

##

Mauris eget elit ut neque venenatis placerat id nec libero. Nunc accumsan cursus elit nec iaculis. Proin id rutrum magna, a aliquet sem. Sed et tortor id sem eleifend porta vitae eget elit. Cras sodales porta malesuada. Suspendisse at odio ac tortor.

##

Ut vulputate enim ut lorem iaculis, vel faucibus metus iaculis. Aliquam erat volutpat. Aliquam luctus orci vel consectetur dignissim. Nullam et efficitur lorem, et ornare est. Sed tristique porttitor justo, quis malesuada velit. Nullam et elit finibus, sollicitudin velit placerat, ultricies dui.

Unfortunately, it is not currently possible to include shortcodes inside other shortcodes, using the “`%`” notation (which is designated for markdown content). If you use the angle brackets notation (illustrated below) it is possible, but markdown will no longer be permitted. You will have to code HTML inside such a section manually.

    {{<expandable label="A section of dummy text" level="2">}}
    <p>Here is a pattern reference shortcode: {{% pattern "Writing inline demos" %}}.</p>
    {{</expandable>}}

When you go to print a pattern from your library, some print styles take care of collapsible sections, making them appear expanded and like any other section.

#
Notes & warnings

Infusion acknowledges that simple markdown is limiting when it comes to writing compelling documentation, so it provides a number of “shortcodes”. Shortcodes offer a simple syntax for including rich content. For example, Infusion provides shortcodes for including notes and warnings.

## Notes

You may wish to pick out some content in your pattern’s documentation as a note — an aside to the main thrust of the pattern’s description. This is possible using the following syntax:

    {{% note %}}
    This is a note! It's something the reader may like to know about but is supplementary to the main content. Use notes when something may be interesting but not critical.
    {{% /note %}}

Notes render like this:

This is a note! It’s something the reader may like to know about but is supplementary to the main content. Use notes when something may be interesting but not critical.

## Warnings

Warnings are like notes, but with more urgency.

    {{% warning %}}
    This is a warning! It's about something the reader should be careful to do or to avoid doing. Use warnings when something could go wrong.
    {{% /warning %}}

Warnings render like this:

This is a warning! It’s about something the reader should be careful to do or to avoid doing. Use warnings when something could go wrong.

#
References

## Cross-references

Infusion provides an easy mechanism to cross-reference patterns, by title, using the `pattern` shortcode. For example, I can reference the
Notes & warnings pattern. Here’s what the markdown looks like, including the shortcode:

    I can reference the {{% pattern "Notes & warnings" %}} pattern here.

This saves you having to worry about pathing and decorates the generated link with a bookmark icon, identifying the link as a pattern reference visually.

The title argument you supply to the shortcode must be exactly the same as the referenced pattern’s `title` metadata value and is case sensitive.

## WCAG References

WCAG 2.0 is the de facto standard for accessible interfaces. When writing about inclusive design patterns, sometimes you’ll want to refer to WCAG to highlight which success criteria the pattern meets.

Instead of having to copy and paste content and links to WCAG, Infusion provides a shortcode mechanism that lets you simply list the success criteria by number:

    {{% wcag include="1.2.1, 1.3.1, 4.1.2" %}}

This generates a list of references that includes the names of each criterion and links to them directly. Like this:

- 2.1.1 Keyboard (level A)
- 4.1.2 Name, Role, Value (level A)

You don’t have to leave spaces after the comma separators. They are optional.

### Full descriptions

Sometimes, you’ll want to include the full descriptions of the success criteria inline. This is possible by setting `descriptions` to `true`:

    {{% wcag include="1.3.1, 4.1.2" descriptions="true" %}}

Here’s the more verbose output:

- 2.1.1 Keyboard (level A): All functionality of the content is operable through a keyboard interface without requiring specific timings for individual keystrokes, except where the underlying function requires input that depends on the path of the user's movement and not just the endpoints
- 4.1.2 Name, Role, Value (level A): For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies.

## Inclusive Design Principle references

Some inclusive design concepts are not reducible to success or fail criteria. This is why The Paciello Group wrote the Inclusive Design Principles. These can be listed by name.

    {{% principles include="Add value, Be consistent" descriptions="true" %}}

Here’s the output with `descriptions="true"`:

- Be consistent : Use familiar conventions and apply them consistently.

  Familiar interfaces borrow from well-established patterns. These should be used consistently within the interface to reinforce their meaning and purpose. This should be applied to functionality, behavior, editorial, and presentation. You should say the same things in the same way and users should be able to do the same things in the same way.

- Add value : Consider the value of features and how they improve the experience for different users.

  Features should add value to the user experience by providing efficient and diverse ways to find and interact with content. Consider device features such as voice, geolocation, camera and vibration API's, and how integration with connected devices or a second screen could provide choice.

#
Tables of contents

Pattern pages in Infusion that have two or more subheadings — `<h2>`s — automatically get a table of contents: a list of links to the main subsections for the page. This feature is made accessible as a navigation region with the “Table of contents” label and uses an ordered list. The table of contents markup for the
Library setup page looks something like this:

    <nav class="toc" aria-labelledby="toc-heading">
      <h2 id="toc-heading">Table of contents</h2>
      <ol>
        <li>
          <a href="#cleaning-the-content-folder">“Cleaning” the content folder</a>
        </li>
        <li>
          <a href="#the-setup-command">The setup command</a>
        </li>
        <li>
          <a href="#the-config-file">The config file</a>
        </li>
        <li>
          <a href="#including-a-logo">Including a logo</a>
        </li>
      </ol>
    </nav>

Tables of contents are a neat way to break down the content of the page and give users a navigable overview. However, they may not be to your taste. Never fear, you can turn tables of contents off by adding `toc = false` to the TOML metadata for your pattern:

    +++
    title = "My page with a few headings"
    toc = false
    +++

#
Including images

From time to time, you’ll be wanting to include images illustrating the documented pattern in hand. Images live in the static folder, which is a sibling of the `/content` folder you’ll be mostly working in.

    ├── content
    └── static
        └── images
            ├── logo.png
            └── menu-button.gif

When you first make a copy of Infusion, Infusion’s own logo will be included. You should replace this with your own company or project logo.

The path to the `/images` folder should begin with a forward slash, so include that when referencing images in your markdown.

    ![Global Megacorp Ltd](/images/logo.png)

## Figures

Sometimes you will want to include a caption with your illustration. This is what the `<figure>` and `<figcaption>` elements are for. However, Infusion doesn’t ask you to code all that manually. A special shortcode is provided, which takes a `caption` parameter. Note that the image markdown is provided between the opening and closing shortcode tags, and that you can use markdown syntax in the `caption` value.

    {{% figure caption="[Steve Faulkner](https://twitter.com/stevefaulkner) works for The Paciello Group" %}}
    ![Steve Faulkner's face](/images/steve_faulkner.jpg)
    {{% /figure %}}

This will output the following. Note the automatically incremented Figure number.

Steve Faulkner works for The Paciello Group

The generated markup includes special provisions for assistive technology support:

    <figure role="group" aria-describedby="U3RldmUgRmF1bGtuZXIg">
      <p>
        <img src="/images/steve_faulkner.jpg" alt="Steve Faulkner's face">
      </p>
      <figcaption id="U3RldmUgRmF1bGtuZXIg">
        <a href="https://twitter.com/stevefaulkner">Steve Faulkner</a> works for The Paciello Group
      </figcaption>
    </figure>

#
Including videos

Infusion has a lot of its own shortcodes, but you can still use Hugo’s built in shortcodes. These include a simple shortcode for including YouTube videos in your content. The shortcode takes just one parameter — the video’s `id`.

    {{<youtube w7Ft2ymGmfc>}}

#
Code blocks

Markdown already supports code samples both inline (using single backticks like `some code here`) and in blocks. Infusion will syntax highlight HTML, CSS, and JavaScript if you provide the correct language in the formulation of the block.

So, this…

    ```html
    <button aria-pressed="false">toggle me</button>
    ```

… will result in this:

    <button aria-pressed="false">toggle me</button>

Note that the syntax highlighting uses a greyscale theme. Infusion is careful not to use color as part of its own design, because these colors may clash with those of the design being illustrated and discussed.

## Line-numbered code blocks

In addition to the basic markdown support, Infusion provides a mechanism to display code blocks with line numbers. This is via the `codeBlock` shortcode. Here is the code for a block of JavaScript with line numbers:

    {{<codeBlock lang="js" numbered="true">}}
    var toggle = demo.querySelector('[aria-pressed]');

    toggle.addEventListener('click', (e) => {
      let pressed = e.target.getAttribute('aria-pressed') === 'true';
      e.target.setAttribute('aria-pressed', !pressed);
    });
    {{</codeBlock>}}

The output will look like the following. Now you can refer to particular bits of the code by line number, like the arrow function on line `3`.

    var toggle = demo.querySelector('[aria-pressed]');

    toggle.addEventListener('click', (e) => {
      let pressed = e.target.getAttribute('aria-pressed') === 'true';
      e.target.setAttribute('aria-pressed', !pressed);
    });

#
Demo embedding

Sometimes just pictures of the pattern you’re documenting aren’t enough. Interactive patterns benefit from live demos, so that readers can test their functionality.

## CodePen

Infusion offers a couple of ways to do this. The first is by embedding CodePen demos into the content. The `codePen` shortcode takes just one argument: the codePen’s `ID`.

    {{% codePen VpVNKW %}}

This will embed the identified codePen into the content wherever you placed the shortcode, with the result view showing by default:

The compiled site will output an error if your `config.toml` does not include your CodePen username (in the `codePenUser` parameter). This is needed to construct the embed URL.

## jsBin

You can embed JS Bins just like CodePens, supplying a single `id` parameter.

    {{% jsBin juwowaq %}}

However, you can also have finer control over which panes are displayed. Use two parameters: one for the `id` and another, `show`, listing the panes you want to include.

    {{% jsBin id="juwowaq" show="css,output" %}}

The options for the `show` parameter are:

- html
- css
- js
- console
- output

(Note that, under some circumstances, the `html` pane is added whether you select it or not.)

## Inline demos

Infusion also supports the ability to write inline demos directly in markdown files. See
Writing inline demos.

#
Writing inline demos

There are some issues with , like them not working offline. They also come with CodePen branding, which will clash with the pattern you’re trying to illustrate.

Infusion offers another option: a special `demo` shortcode that allows you to write HTML, CSS, and JavaScript directly into the markdown file. The outputted demo is encapsulated using Shadow DOM, so you don’t have to worry about broken styles and global JS.

Here’s the example code for an inline demo of a toggle button:

    {{<demo>}}
    <button aria-pressed="false">Toggle Me</button>
    <style>
    button {
        background: DarkCyan;
        color: white;
        border: 0;
        font-size: 1.5rem;
        padding: 0.5em 1em;
        border-right: 5px solid #000;
        border-bottom: 5px solid #000;
    }

    [aria-pressed="true"] {
      border: 0;
      border-top: 5px solid #000;
      border-left: 5px solid #000;
    }
    </style>
    <script>
    var toggle = demo.querySelector('[aria-pressed]');

    toggle.addEventListener('click', (e) => {
      let pressed = e.target.getAttribute('aria-pressed') === 'true';
      e.target.setAttribute('aria-pressed', !pressed);
    });
    </script>
    {{</demo>}}

Note the `demo.querySelector` on line `21`. Infusion automatically provides `demo`, representing the root node of the demo. It’s like the `document` keyword but for a demo’s subtree.

Here’s a live demo of… the demo:

## Captioned demos

It’s possible to give your demo a caption using an accessible `<figure>` and `<figcaption>` structure. All you need to do is supply a `caption` attribute. For example:

    {{<demo caption="A basic button element">}}
    <!-- demo code here -->
    {{</demo>}}

Along with the standard `figure` shortcodes (described in
Including images), demo figures are numbered automatically according to their order in the page. You can use markdown syntax in the caption text value.

#
Color palettes

There’s no reason why your Infusion-powered pattern library has to be all about functionality. You can include style guide-like information such as color palettes too. The `colors` shortcode makes it easy to exhibit colors and their values together. Just supply a comma-separated list of CSS color values.

    {{% colors "#111111, #cccccc, #ffffff" %}}

The result is a one row strip showing each color supplied in order. The colors for Infusion are greyscale:

- #111111
- #CCCCCC
- #FFFFFF

If you’re wondering whether you need to put a space after the commas in the shortcode, don’t worry: `"#254f7b, #579a6d, #666666"` and `"#254f7b,#579a6d,#666666"` are both accepted. Any CSS color value is acceptable, not just hex colors.

#
Command line

Your pattern documentation may need to include commands for installing packages or using CLIs. Infusion offers the `cmd` shortcode for making code blocks look like terminal commands.

Here’s how you write it:

    {{<cmd>}}
    npm run start
    {{</cmd>}}

And here’s how it looks:

    npm run start

The `cmd` shortcode currently only supports single commands. If you want to show multiple, successive commands use separate `cmd` blocks.

#
File trees

Representing folder/file structures is simple and accessible in Infusion. Which is just as well, because some components may need to conform to a certain folder structure.

The file tree is described using a markdown nested list structure:

    {{% fileTree %}}
    * Level 1 folder
        * Level 2 file
        * Level 2 folder
            * Level 3 file
            * Level 3 folder
                * Level 4 file
            * Level 3 folder
                * Level 4 file
                * Level 4 file
            * Level 3 file
        * Level 2 folder
            * Level 3 file
            * Level 3 file
            * Level 3 file
        * Level 2 file
    * Level 1 file
    {{% /fileTree %}}

This is drawn in the following fashion, but preserves the underlying nested list structure for assistive technologies such as screen readers:

- Level 1 folder
  - Level 2 file
  - Level 2 folder
    - Level 3 file
    - Level 3 folder
      - Level 4 file
    - Level 3 folder
      - Level 4 file
      - Level 4 file
    - Level 3 file
  - Level 2 folder
    - Level 3 file
    - Level 3 file
    - Level 3 file
  - Level 2 file
- Level 1 file

The only reliable way to nest unordered lists in markdown is to indent the nested item by exactly four spaces. Using tabs or less than four spaces are unreliable methods.

#
Tested using...

When you’re an inclusive designer, it’s pertinent to do some testing. Following specs is one thing, but you need to verify that your component works okay for users.

Infusion provided a `tested` shortcode that let’s you show which browsers and assistive technologies you’ve tried your design out in. Here’s an example. Note the commas and “+” signs.

    {{% tested using="Firefox + JAWS, Chrome, Safari iOS + Voiceover, Edge" %}}

This outputs:

Tested using | Firefox with JAWS | Chrome | Safari iOS with Voiceover | Edge

The value for the `using` attribute follows a specific format: each testing setup is separated by a comma (with a space if you like, but it’s not mandatory). If you want to add an assistive technology (or any other “add on”) this needs to follow a “+”. This additional part can be anything, like “A VR headset I borrowed”, but there are only a few browser terms available. These are case sensitive, so you need to write them as below:

- Firefox
- Chrome
- Safari
- IE
- Edge
- Opera
- Chrome Android
- Firefox Android
- Safari iOS

Obviously, this is not a comprehensive list and more may be added over time. But it covers most of the main browsers for pairing with other software — at least for testing purposes.