Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

hologram

> 编程语言
Open source

A markdown based documentation system for style guides.

2.2K stars0 likes1 views
WebsiteGitHub

About

A markdown based documentation system for style guides.

Hologram

Hologram is a Ruby gem that parses comments in your CSS and helps you turn them into a beautiful style guide.

There are two steps to building a great style guide:

  1. Documenting your css and javascript, and generating html examples.
  2. Styling the output of step 1.

The hologram gem itself is only concerned with step 1. This means you are free to make your style guide look however you would like. If you don't feel like going through this process yourself, you can take a look at the templates in our example repository, and use the assets defined there instead.

Installation

Add this line to your application's Gemfile:

gem 'hologram'

And then execute:

$ bundle

If you don't use bundler you can run gem install hologram.

Quick Start

hologram init

This will create a hologram_config.yml file (more on this below), starter _header.html and _footer.html files, and starter templates for rendering code examples. You can then tweak the config values and start documenting your css.

Add some documentation to one of your stylesheets:

/*doc
---
title: Alert
name: alert
category: basics
---
```html_example
    

```
*/

Building the documentation is simply:

hologram

Command line flags

Hologram has a couple of command line flags:

  • -c or --config - specify the config file, by default hologram looks for hologram_config.yml

Details

There are two things you need to do to start using hologram:

  1. Create a YAML config file for your project.

  2. Go document some code!

Creating a YAML config file

Hologram needs a few configuration settings before it can begin to build your documentation for you. Once this is set up, you can execute hologram by simply running:

hologram path/to/your/config.yml or (using bundler) bundle exec hologram path/to/your/config.yml

Your config file needs to contain the following key/value pairs

  • source: relative path(s) to your source files. Accepts either a single value or an array

  • destination: relative path where you want the documentation to be built

  • documentation_assets: The path that contains supporting assets for the documentation page. This typically includes html fragments (header/footer, etc), style guide specific CSS, javascript and any images. Hologram specifically looks for two files: _header.html and _footer.html. These are used to start and end every html page hologram generates.

    Hologram treats _header.html and _footer.html as ERB files for each page that is generated. You can access the title, file_name, blocks, and categories.

    blocks is a list of each documentation block on the page. Each item in the list has a title, name, category, and optionally a parent. This is useful for, say, building a menu that lists each component.

    categories is a list of all the categories found in the documentation

    Nota Bene: Filenames that begin with underscores will not be copied into the destination folder.

  • code_example_templates: (optional) Hologram uses the files in this folder to format the code examples in the styleguide. The initializer generates 4 files:

    • markup_example_template.html.erb - used for html, haml and slim examples

    • markup_table_template.html.erb - used for multiple html, haml and slim examples layed out in a table (see the tabular layout docs for more information)

    • js_example_template.html.erb - used for js examples

    • jsx_example_template.html.erb - used for jsx examples

    The html in the files will be rendered for every code example in the styleguide. The variable rendered_example represents the html generated by the example, while the variable code_example represents the formatted and escaped code behind the example.

    See the documentation on custom code renderers for more information,

    Nota Bene: If template files are missing, or this folder does not exist, hologram will use default templates.

  • code_example_renderers: (optional) A folder that contains your custom code renderers. For example, if you want to have coffee_examples in your code, write a coffeescript renderer and place it in this folder. See #custom_code_example_renders for more inforamtion on this.

  • custom_markdown: (optional) this is the filename of a class that extends RedCarpet::Render::HTML class. Use this for when you need additional classes or html tags for different parts of the page. See [example_markdown_renderer.rb.example] (example_markdown_renderer.rb.example) for an example of what your class can look like.

  • index: (optional) this is a category (see Documenting your styles section below) that will be used as the index.html.

  • dependencies: a list of relative paths to folders containing any dependencies your style guide has. These folders will be copied over into the documentation output directory. ENSURE THE CSS/JS THAT IS ACTUALLY BEING DOCUMENTED IS LISTED HERE. You will also need to ensure that they are included on your pages. A simple way to do this is to add <link> and <script src=> tags to the _header.html file.

  • ignore_paths: (optional) a list of paths to ignore. This can be a file name or a glob. Be sure to wrap globs in double quotes to keep yaml from getting too upset (ie good:".erb" vs bad:.erb).

  • nav_level: (optional) Sets the level of section navigation desired. section sets it to show sub navigation in top level sections. all sets it to show sub navigation for all sections. all can be a bit much, you'll probably want section.

  • custom_extensions: (optional) Additional file extensions that will be included in the parse. Accepts both a single value and an array. The current supported file extensions are .css, .scss, .less, .sass, .styl, .js, .md, .markdown and .erb.

  • exit_on_warnings: (optional) Hologram displays warnings when there are issues with your docs (e.g. if a component's parent is not found, if the _header.html and/or _footer.html files aren't found) If you want Hologram to exit on these warnings, set the value to 'true' (Default value is 'false')

Example config file
# Hologram will run from same directory where this config file resides
# All paths should be relative to there

# The directory containing the source files to parse recursively
source: ./sass

# You may alternately specify multiple directories.
# source:
#  - ./sass
#  - ./library-sass

# The directory that hologram will build to
destination: ./docs

# The assets needed to build the docs (includes header.html,
# footer.html, etc)
# You may put doc related assets here too: images, css, etc.
documentation_assets: ./doc_assets

# The folder that contains templates for rendering code examples.
# If you want to change the way code examples appear in the styleguide,
# modify the files in this folder
code_example_templates: ./code_example_templates

# The folder that contains custom code example renderers.
# If you want to create additional renderers that are not provided
# by Hologram (i.e. coffeescript renderer, jade renderer, etc)
# place them in this folder
code_example_renderers: ./code_example_renderers

# Any other asset folders that need to be copied to the destination
# folder. Typically this will include the css that you are trying to
# document. May also include additional folders as needed.
dependencies:
  - ./build

# Mark which category should be the index page
# Alternatively, you may have an index.md in the source directory root
# folder instead of specifying this config.
index: basics

# To output navigation for top level sections, set the value to
# 'section'. To output navigation for sub-sections, set the value to `all`
nav_level: all

# Hologram displays warnings when there are issues with your docs
# (e.g. if a component's parent is not found, if the _header.html and/or
#  _footer.html files aren't found)
# If you want Hologram to exit on these warnings, set the value to 'true'
# (Default value is 'false')
exit_on_warnings: false

Documenting your styles and components

Hologram will scan for stylesheets (.css, .scss, .sass, .less, or .styl) and javascript source files (.js) within the source directory defined in your configuration. It will look for comments that match the following:

/*doc
---
title: Buttons
name: button
category: Base CSS
---

Button styles can be applied to any element. Typically you'll want
to use either a `<button>` or an `<a>` element:

```html_example <button class="btn btnDefault">Click</button> <a
class="btn btnDefault" href="trulia.com">Trulia!</a> ```

If your button is actually a link to another page, please use the
`<a>` element, while if your button performs an action, such as
submitting a form or triggering some javascript event, then use a
`<button>` element.

*/

NB: Sass users who are using the .sass flavor of Sass should use //doc style comments with indents to create their comment blocks.

The first section of the comment is a YAML block that defines certain aspects of this documentation block (more on that in the next section). The second part is simply markdown as defined by Redcarpet.

Notice the use of html_example. This tells the markdown renderer that it should treat the example as...well...html. If your project uses haml you can also use haml_example. In that case the output will be html for the example and the code block will show the haml used to generate the html.

For components that require javascript you can use js_example. In addition to outputting the javascript in a <code> block it will also wrap it in a <script> tag for execution.

Additionally, html elements that are generated via markdown will have a class styleguide appended to them. You can use this to apply css to the styleguide itself.

Tabular layout for component documentation

If you want the code snippet next to the rendered component, instead of below, render your component horizontally by applying the html_example_table or haml_example_table modifiers to the code block.

/*doc
---
title: Buttons
name: button
category: Base CSS
---

```html_example_table
<button class="btn btnDefault">Click</button>

<a class="btn btnDefault" href="trulia.com">Trulia!</a>
```

*/

NB: Components separated by a blank line will be rendered as separate table rows.

Referencing other components

For some components, you may want to reference the documentation of another component. As an example, you may want your link components to link to the button documentation.

/*doc
---
title: Links
name: links
category: Other Category
---

...

You may want to use a button for a link.
See [the button documentation][button] for more info.

*/

You can use a reference link of the form [link description][component_name] to link to any other component in the styleguide. These links will even work if the referenced component belongs to a different category.

Document YAML section

The YAML in the documentation block can have any key/value pairs you deem important, but it specifically looks for the following keys:

  • title: The title to display in the documents
  • category/categories: This is the broad categories for the component, al

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言