# Hologram
[](https://rubygems.org/gems/hologram)
[](https://travis-ci.org/trulia/hologram)
[](https://codeclimate.com/github/trulia/hologram)
[](https://gemnasium.com/trulia/hologram)
[](LICENSE.txt)
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](https://github.com/trulia/hologram-example/tree/master/templates)
in our [example repository](https://github.com/trulia/hologram-example),
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
Hello
```
*/
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](#tabular-layout-for-component-documentation)
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](#custom_code_example_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_example`s in your
code, write a coffeescript renderer and place it in this folder. See
[#custom_code_example_renders](below) 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
`` and `
<%= code_example %>
```
```erb
<% examples.each do |example| %>
<%= example.code_example %>
<% end %>
```
Next, create a custom renderer for coffeescript in the file
`./code_example_renderers/coffee_renderer.rb`.
```ruby
# ./code_example_renderers/coffee_renderer.rb
require 'coffee-script'
Hologram::CodeExampleRenderer::Factory.define('coffee') do
example_template 'my_custom_coffee_example_template'
table_template 'my_custom_coffee_table_template'
lexer { Rouge::Lexer.find(:coffee) }
rendered_example do |code|
CoffeeScript.compile(code)
end
end
```
Now you should be able to render coffeescript examples in your styleguide.
You can render single coffeescript examples...
```coffee_example
$('#myDiv').click ->
alert 'Oh wow we are rendering coffee script'
```
Or you can render coffeescript tables...
```coffee_example_table
$('#myDiv').click ->
alert 'Oh wow we are rendering coffee script'
$('#myOtherDiv').click ->
console.log 'Yeah coffee script!'
$('#yetAnotherDiv').click ->
window.location =
```
Here's some details on the code example renderer factory:
* `Hologram::CodeExampleRenderer::Factory.define(example_type, &block)` -
this is how you declare a custom renderer. `example_type` is the name of the
renderer, and determines the example name. For example, if `example_type`
was "foobar", in your styleguide you can create `foobar_example`s and
`foobar_example_table`s
* `example_template` - the name of the template used to render the example,
minus the `.html.erb` extension (e.g. "markup_example_template"). It
should live in your **code\_example\_templates** folder
* `table_template` - (optional) the name of the template used to render examples in
tabular form, minus the extension (e.g. "markup_table_template").
* `lexer` - (optional) a Rogue Lexer that matches the syntax of your
example (i.e. `Rouge::Lexer.find(:haml)`, `Rouge::Lexer.find(:ruby)`).
Here's a [complete list of possible lexers](http://rouge.jayferd.us/demo).
If this argument is not provided, hologram will guess what the best
one is.
* `rendered_example` - (optional) this is the set of instructions to
"translate" your exaple so it can be rendered. I.e. for coffeescript
to be "rendered" in the browser, you need to transform it to
javascript (as can be seen in the block above).
For haml, you need to transform it to html.
If no block is provided, the code is rendered as is.
## Supported Preprocessors/File Types
The following preprocessors/file types are supported by Hologram:
- Sass (.scss, .sass)
- Less (.less)
- Stylus (.styl)
- Vanilla CSS (.css)
- Javascript (.js)
- Markdown (.md, .markdown)
## Extensions and Plugins
- [Guard Hologram](https://github.com/kmayer/guard-hologram) is a sweet
little gem that uses guard to monitor changes to your hologram project
and rebuilds your style guide on the fly as you make changes.
- [Grunt Hologram](https://github.com/jchild3rs/grunt-hologram/) is a sweet
little grunt task that will generate your hologram style guide.
- [Hologram Plugin for Gulp](https://gist.github.com/jchild3rs/470be49a4bc4caf3ca8a) is a gulp task for hologram.
- [Classname Clicker](https://github.com/bigethan/hologram-addons/) is a handy
UI addition that gives the ability to see rules that apply to a classname by
clicking on them within hologram.
- [Cortana](https://github.com/Yago/Cortana) is a theme for hologram. It also
includes a handy search feature.
- [Hologram Github Theme](https://github.com/wearecube/hologram-github-theme) is a Github Styleguide inspired theme for hologram.
- [Voxel Hologram](https://github.com/rishabhsrao/voxel-hologram) is a minimal theme for Hologram.
- [Acme Styleguide](https://github.com/mattrothenberg/styleguide-boilerplate) is a starter project that helps
[Pivotal Labs Designers](https://pivotal.io/labs) build living styleguides with Sass and Hologram.
## Contributing
1. Fork it
2. Create your feature/bug fix branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## Authors
Hologram is written and maintained by [August
Flanagan](http://github.com/aflanagan) and [JD
Cantrell](http://github.com/jdcantrell).
## Contributors
These fine people have also contributed to making hologram a better gem:
* [Rajan Agaskar](https://github.com/ragaskar)
* Louis Bennett
* [jho406](https://github.com/jho406)
* johny (wrote our initial tests!)
* [Elana Koren](https://github.com/elanakoren)
* [Ken Mayer](https://github.com/kmayer)
* [Roberto Ostinelli](https://github.com/ostinelli)
* [Dominick Reinhold](https://github.com/d-reinhold)
* [Nicole Sullivan](https://github.com/stubbornella)
* [Mike Wilkes](https://github.com/mikezx6r)
* [Vanessa Sant'Anna](https://github.com/vsanta)
* [Geoffrey Giesemann](https://github.com/geoffwa)
## License
[Hologram is licensed under the MIT License](https://github.com/trulia/hologram/blob/master/LICENSE.txt)