[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

convert YAML to HTML?

Phlip

3/26/2005 3:58:00 PM

Rubies:

This has to have been on the YAML thought leader's Do List.

Is there a library, or a snippet, out there that converts YAML to esthetic,
meaningful XHTML?

I don't want to load the document into Ruby variables then stream them with
RedCloth because I'd lose the comments.

Can I load the comments, too, and stream everything?

--
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUser...


4 Answers

Phlip

3/26/2005 5:12:00 PM

0

Phlip wrote:

> This has to have been on the YAML thought leader's Do List.
>
> Is there a library, or a snippet, out there that converts YAML to
esthetic,
> meaningful XHTML?
>
> I don't want to load the document into Ruby variables then stream them
with
> RedCloth because I'd lose the comments.
>
> Can I load the comments, too, and stream everything?

Here's JB's Syntax module:

http://jamisbuck.org/jamis/blog.cgi/programming/ruby/Syntax%200.7_2005032...

Here's a sample output:

<span class="punct">-</span> [ formatWiki, this is ''em''phatic text, this
is &lt;em&gt;em&lt;/em&gt;phatic text ]

That's not cute enough. It's essentially a syntax highlighter for YAML. (And
as such, it missed the [] tags and lexically significant commas , .)

I need <table> output with cute <tr><td> tags around the arrays. To use
Ruby's magical extensiveness on Jamis Buck's Syntax::Convertors::HTML class,
I would also need the lexer to parse [] and , properly.

I might just spark up a TDD session and see how far I get with app-specific
code...

> --
> Phlip
> http://industrialxp.org/community/bin/view/Main/TestFirstUser...


Jamis Buck

3/26/2005 6:17:00 PM

0

On Mar 26, 2005, at 10:14 AM, Phlip wrote:

> Phlip wrote:
>
>> This has to have been on the YAML thought leader's Do List.
>>
>> Is there a library, or a snippet, out there that converts YAML to
> esthetic,
>> meaningful XHTML?
>>
>> I don't want to load the document into Ruby variables then stream them
> with
>> RedCloth because I'd lose the comments.
>>
>> Can I load the comments, too, and stream everything?
>
> Here's JB's Syntax module:
>
> http://jamisbuck.org/jamis/blog.cgi/program...
> Syntax%200.7_20050323235420.tx
>
> Here's a sample output:
>
> <span class="punct">-</span> [ formatWiki, this is ''em''phatic text,
> this
> is &lt;em&gt;em&lt;/em&gt;phatic text ]
>
> That's not cute enough. It's essentially a syntax highlighter for
> YAML. (And
> as such, it missed the [] tags and lexically significant commas , .)

Yes, it is not a complete YAML parser. A patch would be more than
welcome, though. If you (or anyone else) improves an existing lexer or
adds a new one, I would love to add your changes to the Syntax lib.

- Jamis



Phlip

3/26/2005 7:35:00 PM

0

Jamis Buck wrote:

> Yes, it is not a complete YAML parser. A patch would be more than
> welcome, though.

Puh-lease. Patches are so Last Millenium.

We shall do this via the most obnoxious implementation technique yet
discovered: Pair Programming Via USENET.

Here:

def test_list_of_lists
tok = []
@yaml.tokenize( "- [ foo ]" ) { |t| tok << t }
assert_equal [ :punct, "-" ], [ tok.first.group, tok.shift ]
assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
assert_equal [ :punct, "[" ], [ tok.first.group, tok.shift ]
assert_equal [ :normal, " foo " ], [ tok.first.group, tok.shift ]
assert_equal [ :punct, "]" ], [ tok.first.group, tok.shift ]
end

I got each assertion working except the last, by adding this:

class YAML < Tokenizer
....
when scan(/:\w+/)
start_group :symbol, matched

when scan(/(\s*)\[/)
start_group :normal, subgroup(1)
start_group :punct, "["
....

However, now I can't find where to get the closing ] out of the :normal
string " foo ]".

After we do that, we need , working, and we need [ at BOL, without the -.

--
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUser...


Jamis Buck

3/26/2005 8:36:00 PM

0

On Mar 26, 2005, at 12:39 PM, Phlip wrote:

> Jamis Buck wrote:
>
>> Yes, it is not a complete YAML parser. A patch would be more than
>> welcome, though.
>
> Puh-lease. Patches are so Last Millenium.
>
> We shall do this via the most obnoxious implementation technique yet
> discovered: Pair Programming Via USENET.
>
> Here:
>
[snip]

Thanks for the start on this, Philip. After taking what you did here
and working a bit more on it, I'm beginning to think what really needs
to happen is to rework the YAML lexer so that it uses a simple state
machine. That would give much more granular output. Also, where I've
been returning :normal (for "foo" in "bar: foo", for example), it
should probably be :string.

We could continue with the existing lexer, but I fear it will rapidly
become a case of plugging leaks and adding patch after patch...

I'll try to work on this some this afternoon, so the YAML lexer will be
a lot more robust.

- Jamis