veger/ruby-bbcode — pull request #8 by TheNotary (2013-04-04 20:43:07+00:00)
Title: Touchups - youtube auto-parse url feature

Hey, here's another refactor of touchups. I created 2 more classes, ack!

TagCollection (properly named) is a new class that acts pretty much like an array where you but TagNodes (BBTree builds up tag nodes in these collections). Each individual TagNode of course has it's own TagCollection where it's children go. The class also handles the to_html code that once resided in lib/ruby-bbcode.rb. The lib/ruby-bbcode.rb file is very small.

HtmlTemplate is a class that converts the html template described in the tags/tags.rb file and converts it into the appropriate output as specified by whatever BBCode got parsed. This class is inside lib/ruby-bbcode/tag_collection.rb right now because I just feel plain silly about how many classes I spun this code into. I think it should be in it's own file... or maybe I should lookup how folders are typically used in ruby gems (it's really rare that I see folders in projects). This project deserves a class diagram I think... I'll jot one up here for now.

Also, I marked some commits with the words "ATTENTION" when I felt they were such big decisions that they deserved their own issue, but I didn't want to start a million issues at once, I just wanted to get a good sweep through without needed to slow down for coordination purposes. Maybe that will help you, idk, I've never been on your end of the project. I've had ppl create issues, but never had hackers implement adjustments.

So let me know what's on your mind.

And here's a class diagram, how the classes relate to each other.

TagSifter
-BBTree
-TagInfo
-TagCollection
-TagNode
-HtmlTemplate

So that diagram attempts to express that:

The code creates a single TagSifter object, wherein a BBTree element is instantiated.
The BBTree parses the bbcode text, converts that data into discrete TagInfo elements.
The TagInfo elements are then converted into TagNode elements which reside inside TagCollection arrays.

After all of the bbcode text has been parsed and the data has been extracted into TagNodes, the BBTree#to_html method is called, which 'transversly' calls TagNode#to_html on the BBTree's TagNode collection. It's within this method that the TagNodes are placed into the HtmlTemplate form and html is generated in a nearly recursive manor for all child nodes within the @bbtree.

Pretty cool huh? Let me know your thoughts.