styleguide = Styledown.new(path, [options])
Styledown class.
styleguide = Styledown.new('/path/to/guides')
styleguide.render
styleguide.output
# => {
# 'buttons.html' => { 'contents' => '...' },
# 'forms.html' => { 'contents' => '...' }
# }
styleguide.render
Processes files and updates #output. Styledown keeps a cache, so this will not re-read or re-process if no files have changed. See Styledown class for an example.
styleguide.fast_render
Like #render, but skips checking if any files have been updated. Use this in production.
styleguide.render!
Forces a #render regardless of whether files have changed or not.
styleguide.output
The final transformed files. This is a Hash. See Styledown class for an example.
styleguide.add_data_filter { |data| ... }
Adds a function to be invoked on #render that will transform Styledown raw data. The given block should return a new data
, or the same one if it was mutated.
styleguide.add_file_filter { |filename, file| ... }
Adds a function to be invoked on #render that will transform Styledown file
data. The given block should return a [filename, file]
tuple.
styleguide = Styledown.new('/path/to/guides')
styleguide.add_file_filter do |filename, file|
filename = filename.gsub(/\.html$/, '.htm')
[filename, file]
end
styleguide.render
styleguide.add_section_filter { |section| ... }
Adds a function to be invoked on #render that will transform Styledown section
data. The given block should return a new section
, or the same one if it was mutated.
styleguide = Styledown.new('/path/to/guides')
styleguide.add_section_filter do |section|
# Prefix id's for whatever reason
section['id'] = "sg-#{section['id']}"
section
end
styleguide.render
styleguide.add_part_filter { |part| ... }
Adds a function to be invoked on #render that will transform Styledown part
data. The given block should return a new part
, or the same one if it was mutated.
styleguide = Styledown.new('/path/to/guides')
styleguide.add_part_filter do |part|
part['class'] += ' my-class'
part
end
styleguide.render
styleguide.add_figure_filter(language) { |content| ... }
Adds a function to be invoked on #render for transpiling example figures. The given block should return [language, content]
where language
is the new language it was transformed to, and content
is the transformed result.
styleguide = Styledown.new('/path/to/guides')
styleguide.add_figure_filter('erb') do |contetns|
[ 'html', ERB.render(contents) ]
end
styleguide.render
Invalidates the cache so that the next #render will always run.
Partially invalidates the cache so that the next #render will always run the build step. It will not re-run the read step, however.
Styledown.read(path, [options])
Reads files in path
and returns their contents in a Hash, ready to be processed by styledown.build. This mirrors the styledown.read()
implementation in JavaScript.
Styledown.build(files, [options])
Processes files
(as returned by styledown.read and returns data to be rendered. This mirrors the styledown.build()
implementation in JavaScript.
Styledown.render(data, [options])
Processes data
(as returned by styledown.build and returns output files. This mirrors the styledown.render()
implementation in JavaScript.