Two bugfixes: display output when there are no comments, allow non-UTF-8 encodings #72

wants to merge 3 commits into


None yet
1 participant

lambda commented Jan 5, 2012

I've pushed two bugfixes to my fork; one to make sure that we get output even when there are no comments in the file (issue 71) and one to allow explicit specification of input file encoding so we can properly handle non-UTF-8 input on Ruby 1.9 (issue 73). This pull request also updates .gitignore to properly ignore the generated docs directory.

I had submitted this pull request earlier with some other patches mixed in, but I've now cleaned it up and rebased it on the latest code.

lambda added some commits Jan 9, 2012

@lambda lambda Display output even if there are no comments
Rocco should display the code even if there are no comments.  When there are
no comments, it produces a single section with an empty docs string.
However, to pass it through Markdown, it joins the sections with a
delimiter, munges that, and split the result.  Joining a list continaing the
empty string and splitting it again produces an empty list, not a list
containting the empty string:

 > [""].join("delim").split("delim")
 => []

In Ruby 1.9, this causes us lose the associated code when when try to zip
these lists back together again:

 > [].zip(["something"])
 => []

To fix this, just make sure `docs_html` contains at least a single empty
string if it winds up being empty.

Fixes: #71 (fix rtomayko/rocco#71)
@lambda lambda Allow user to set encoding of files, transcoding to UTF-8
Ruby 1.9 is much more strict about encodings; instead of just reading bytes
into the string and hoping you know how to interpret it, it actually keeps
track of what encoding it expects the file and the string to be and
transcodes between them. This means that we can no longer just read in the
ISO-8859-1 as binary, and kind of hope that everything later on ignores it
or knows how to cope. Instead, we need to explicitly choose to read the
file as ISO-8859-1, and explicitly choose the encoding that we want the
string to be in.  We use UTF-8, because that's what Pygments and at least
some of the Markdown libraries are expecting.

Fixes: #73 (fix rtomayko/rocco#73)
@lambda lambda Add back missing /docs to .gitignore
Commit 854f62c (The default gitignore provided by `bundler gem`) replaced
.gitignore with a generated one, but that blew away the .gitignore line for
/docs.  Add it back in.

lambda commented Jan 9, 2012

Any chance that someone could review these and either pull them or let me know what I should do differently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment