Sha256: 36c4d95ef16011a3117480c9129b35658f1f19468e21186f05c13785135f7c15
Contents?: true
Size: 1.44 KB
Versions: 5
Compression:
Stored size: 1.44 KB
Contents
## Dynamic Content Sometimes you may find useful to generate content dynamically. Maybe you're going to read some configuration file, or maybe you just want to define some helpers. Kitabu has support for ERb files; all you need to do is naming your text file as `.md.erb`. On the previous chapter, we listed all supported Rouge lexers. To do that, I created a helper that looks like this: ```ruby <%= File.read("./config/helper.rb") %> ``` To use it, I just needed to add `<%%= lexers_list %>` to my text file. This allows you to create anything you need! Kitabu comes with some built-in helpers, such as `note`. With this helper, you can create a note that generates a HTML structure, so you can easily style it. The syntax for using the `note` helper is `note(type, &block)`. ```erb <%% note do %> Some text that will be parsed as Markdown. <%% end %> ``` By default, this will generate a `<div class="note info">` tag, but you can use anything you want. ```erb <%% note :warning do %> Some text that will be parsed as Markdown. <%% end %> ``` [Check out the source](https://github.com/fnando/kitabu/blob/cleanup/lib/kitabu/helpers.rb) for a sample on how to create block helpers like `note`. ### Escaping ERb code If you want to write a book about Rails, you're likely to use lots of ERb tags. In this case, make sure you escape the `<%% %>` and `<%%= %>` markers as `<%%% %>` and `<%%%= %>`; otherwise you'll have a syntax error. ``` <%%%= Date.today %> ```
Version data entries
5 entries across 5 versions & 1 rubygems