jch/html-pipeline — pull request #75 by simeonwillbanks (2013-07-24 02:06:40+00:00)
Title: Generate Table of Contents

In `TableOfContentsFilter`, generate a Table of Contents as a HTML unordered list of links to headers.

* Add test cases for directly using `HTML::Pipeline::TableOfContentsFilter`
* Add test cases for using `HTML::Pipeline::TableOfContentsFilter` within a `HTML::Pipeline`
* Initialize `result[:toc]` to an empty string in `TableOfContentsFilter#call`
* Initialize `@toc` to an empty string in `TableOfContentsFilter#call`
* Set `toc` as an `attr_reader` on `TableOfContentsFilter`
* Extract adding header anchor to `TableOfContentsFilter#add_header_anchor`
* Define `TableOfContentsFilter#append_toc` for adding a toc item
* Define `TableOfContentsFilter#finalize_toc` for wrapping toc items in a container
* Markup from [GitHub Styleguide Styling & CSS Navigation](https://github.com/styleguide/css/8.0), section 8.3.1
* Update TomDoc
* Update README.md explaining generated Table of Contents

```ruby
>> require 'html/pipeline'
=> true
>> TocPipeline =
?> HTML::Pipeline.new [
?> HTML::Pipeline::TableOfContentsFilter
>> ]
=> #
>> orig = %(

Ice cube

is not for the pop chart

)
=> "

Ice cube

is not for the pop chart

"
>> result = {}
=> {}
>> TocPipeline.call(orig, {}, result)
=> {:toc=>"

\n
Ice cube
\n

", :output=>#, #, #] children=[#]>]>, #]>, #]>]>}
>> result[:toc]
=> "

\n
Ice cube
\n

"
>> result[:output].to_s
=> "

\nIce cube

is not for the pop chart

"
```
```
❯ be rake
/Users/simeon/.rbenv/versions/1.9.3-p327-perf/bin/ruby -I"lib:test" -I"/Users/simeon/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib" "/Users/simeon/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/html/pipeline/absolute_source_filter_test.rb" "test/html/pipeline/autolink_filter_test.rb" "test/html/pipeline/camo_filter_test.rb" "test/html/pipeline/emoji_filter_test.rb" "test/html/pipeline/image_max_width_filter_test.rb" "test/html/pipeline/markdown_filter_test.rb" "test/html/pipeline/mention_filter_test.rb" "test/html/pipeline/plain_text_input_filter_test.rb" "test/html/pipeline/sanitization_filter_test.rb" "test/html/pipeline/toc_filter_test.rb" "test/html/pipeline_test.rb"
Run options:

# Running tests:

......................................................................................

Finished tests in 0.064889s, 1325.3402 tests/s, 2034.2431 assertions/s.

86 tests, 132 assertions, 0 failures, 0 errors, 0 skips
```

:musical_note: Thanks to the tests, this Pull Request has a [soundtrack](http://www.youtube.com/playlist?list=PLO7c5XGNkoE0-RiLsenX1pCbETn0BDEEN). :musical_note: