redcloth and dynamic content

D

Dick Davies

I've sat down to write a data-driven webapp. Nice steep
learning curve for me (I'm on my last week here so thought
I'd waste it productively).

So far FastCGI and PostGreSQL (this is an excuse for me
to finally spend time learning SQL in detail, trolls please stfu).

Few questions at the bottom of this, but it'd help to explain
how I got into this mess first...

[ Can I also place a hearty plug for Subversion here - I've
changed designs three or four times over the weekend and
renaming files/classes and nesting libs has been a dream
with it. Definitely a refactoring-friendly VCS..]

The db connection is wrapped in a class, Cnps, which I start up
outside the fcgi mainloop, and is the only thing that is SQL
savvy. The mainloop just calls methods on that class to get data
on demand.

It all works great - thanks to Carl and Ara for their
rubygarden wiki discussions on fastcgi - but
I'm coming to the stage where I have had enough of

out=<<"EOO"
<html><body>
#{cnps.champ} is winning with a score of #{cnps.score(cnps.champ)}
</body>
</html>
EOO


and want to use some kind of template thing.

First go was erb. Works well enough, but pretty verbose for
the Wiki Generation :) So plan B was to use redcloth and erb,
to generate eruby from redcloth templates, store them in another
class and eval them when the requests come in.


Problem with *that* is that I need placeholders in the Textile
for each thing Eruby can parse , so I end up with a lot of <% %>
noise in the templates.

(Doing it the other way round seemed hard to do, since I want to
actually evaluate the dynamic tags at request time, but still preload
the templates).

So, Plan C. Use the ability of RedCloth to create id tags to hook up
to Amrita.

So now we have

request comes in,
fcgi decides what to display,
asks a helper class to get the template,
executes the template using Amrita
and returns the output.

the helper class is responsible for converting the
requested template (textile, (blue|red)cloth, whatever)
to Amrita-ready html.

Problem here is that Amrita doesn't duck type at all, and
it'd really like a Hash. I was hoping to have Cnps just quack
like a Hash, but it isn't going to happen. Arse.


So a few questions:

Is there a way to delay evaluation of tags?
In a 'do the simplest thing' frame of mind, is there a way to
have ruby "" strings evaluated *after* construction?

Amrita seems a bit musty, has it got a successor? Does Kwartz
help me any?

[ This would be my personal preference ]
Is there a facility to extend RedCloth with custom tags?
I could avoid the whole 'do a template from redcloth, then
evaluate template' step that way, and create some kind of unholy
crossbreed of erb/amrita with redcloth?

Something like '>instance.method<' , then these tags get
processed first and return *more* Textile, which finally
gets converted... I'd need to do the evaluation during
to_html(), but that's kind of neat.

Obviously I don't expect anyone else to
put up with that, but if I could add my own tag, that'd be
great. I could see it having lots of uses for others too.


Am I reinventing a wheel here?
 
C

Carl Youngblood

--------------ms070108060207050503020303
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I haven't looked into it much but I too am not very satisfied with
amrita for templating. I'd like something more like PHP's Smarty.
Haven't had much time to work on ruby web apps lately but when I get
back to my on-hold web app I will probably look into other options.

Carl

Dick said:
I've sat down to write a data-driven webapp. Nice steep
learning curve for me (I'm on my last week here so thought
I'd waste it productively).

So far FastCGI and PostGreSQL (this is an excuse for me
to finally spend time learning SQL in detail, trolls please stfu).

Few questions at the bottom of this, but it'd help to explain
how I got into this mess first...

[ Can I also place a hearty plug for Subversion here - I've
changed designs three or four times over the weekend and
renaming files/classes and nesting libs has been a dream
with it. Definitely a refactoring-friendly VCS..]

The db connection is wrapped in a class, Cnps, which I start up
outside the fcgi mainloop, and is the only thing that is SQL
savvy. The mainloop just calls methods on that class to get data
on demand.

It all works great - thanks to Carl and Ara for their
rubygarden wiki discussions on fastcgi - but
I'm coming to the stage where I have had enough of

out=<<"EOO"
<html><body>
#{cnps.champ} is winning with a score of #{cnps.score(cnps.champ)}
</body>
</html>
EOO


and want to use some kind of template thing.

First go was erb. Works well enough, but pretty verbose for
the Wiki Generation :) So plan B was to use redcloth and erb,
to generate eruby from redcloth templates, store them in another
class and eval them when the requests come in.


Problem with *that* is that I need placeholders in the Textile
for each thing Eruby can parse , so I end up with a lot of <% %>
noise in the templates.

(Doing it the other way round seemed hard to do, since I want to
actually evaluate the dynamic tags at request time, but still preload
the templates).

So, Plan C. Use the ability of RedCloth to create id tags to hook up
to Amrita.

So now we have

request comes in,
fcgi decides what to display,
asks a helper class to get the template,
executes the template using Amrita
and returns the output.

the helper class is responsible for converting the
requested template (textile, (blue|red)cloth, whatever)
to Amrita-ready html.

Problem here is that Amrita doesn't duck type at all, and
it'd really like a Hash. I was hoping to have Cnps just quack
like a Hash, but it isn't going to happen. Arse.


So a few questions:

Is there a way to delay evaluation of tags?
In a 'do the simplest thing' frame of mind, is there a way to
have ruby "" strings evaluated *after* construction?

Amrita seems a bit musty, has it got a successor? Does Kwartz
help me any?

[ This would be my personal preference ]
Is there a facility to extend RedCloth with custom tags?
I could avoid the whole 'do a template from redcloth, then
evaluate template' step that way, and create some kind of unholy
crossbreed of erb/amrita with redcloth?

Something like '>instance.method<' , then these tags get
processed first and return *more* Textile, which finally
gets converted... I'd need to do the evaluation during
to_html(), but that's kind of neat.

Obviously I don't expect anyone else to
put up with that, but if I could add my own tag, that'd be
great. I could see it having lots of uses for others too.


Am I reinventing a wheel here?

--------------ms070108060207050503020303
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIPxjCC
BMgwggQxoAMCAQICBAIAApswDQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCVVMxGDAWBgNV
BAoTD0dURSBDb3Jwb3JhdGlvbjEcMBoGA1UEAxMTR1RFIEN5YmVyVHJ1c3QgUm9vdDAeFw0w
MjA4MjcxOTA3MDBaFw0wNjAyMjMyMzU5MDBaMIHcMQswCQYDVQQGEwJHQjEXMBUGA1UEChMO
Q29tb2RvIExpbWl0ZWQxHTAbBgNVBAsTFENvbW9kbyBUcnVzdCBOZXR3b3JrMUYwRAYDVQQL
Ez1UZXJtcyBhbmQgQ29uZGl0aW9ucyBvZiB1c2U6IGh0dHA6Ly93d3cuY29tb2RvLm5ldC9y
ZXBvc2l0b3J5MR8wHQYDVQQLExYoYykyMDAyIENvbW9kbyBMaW1pdGVkMSwwKgYDVQQDEyND
b21vZG8gQ2xhc3MgMyBTZWN1cml0eSBTZXJ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XSDSVmaMZAYRnur
xVO1NWAtQmq23FQphU9iJ8HIAMcSYI3BifCIZTell6MkbQhXZ6D4ytwzI3ZpuH+VYSgxoKrI
bUu4NTzY6CNHFw4qWOTuQswm7o8Z8zzPnMOCsgAAAAAAAA==
--------------ms070108060207050503020303--
 
W

why the lucky stiff

Its said:
[ This would be my personal preference ]
Is there a facility to extend RedCloth with custom tags?

This would be great, specially if those tags can be nested.
Expect this in RedCloth 2.1.0. I think the idea will be:

- You can add new block tags. (i.e. bq., h1., h2., etc.)
- You can add new markup. (i.e. * -> <em>, ** -> <b>, etc.)
- You can add new entities. (i.e. -- -> &mdash;)
- RedCloth will come with a set of extended syntax that can be loaded,
if desired. (per DHH's suggestion that --- => <hr /> and cd. =>
<pre><code> be added.)

Yeah, cool.

_why
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top