RHTML in database?

Hi,
is it possible to store RHTML templates or partials in database?

thanks,
Bojan M.

Bojan M.
Informatika Mihelac, Bojan M. s.p. | www.informatikamihelac.com
→ tools, scripts, tricks from our code lab: http://source.mihelac.org

It is possible to serve all your rhtml from a non-file based location
but
not without a few changes to the Rails core classes. For the MasterView
project we wanted the ability to retrieve rhtml through our own
consolidated
IO layer so that it would allow retrieval from database, alternate
paths, as
well as allowing the content to run through filters. With a little
digging
in the Rails code I was able to hook the right classes to get this to
work
(retrieval from non-file based locations), however I am wanting to
submit a
patch to the Rails core team so that people could hook in easier, right
now
there are File.method calls inside some of the key Rails core methods
which
means there is not a clean way to hook rails. I stubbed out the code
for
doing database based retrieval but didn’t get to finish that yet.

I believe that with regards to rhtml that it was the most difficult to
get
layout rhtml from a non-file location, the other view rhtml and partials
were more easily hooked as I recall. So if you are only doing view or
partials your work should be a little easier.

When I can find some time to put together a more generic patch, then I
will
submit that to the Rails core team so that all rhtml access can be
easily
hooked into other mechanisms.

Also I haven’t checked if edge rails makes this any easier yet,
obviously
one should do that first to see if a change has already been made.

If you would like some pointers on how to go about doing this, I’d be
glad
to point you to the code in my project that accomplished it.

Jeff B.
MasterView Project founder - rails-optimized (x)html-friendly template
engine
http://masterview.org/

Jeff B. wrote:

there is not a clean way to hook rails. I stubbed out the code for

http://masterview.org/
Bojan M.



Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Thanks for your answer Jeff. Do you think it would be possible to use
different input resources (db, filesystem). Something like Smarty PHP
has.

best regards,
Bojan


Bojan M.
Informatika Mihelac, Bojan M. s.p. | www.informatikamihelac.com
→ tools, scripts, tricks from our code lab: http://source.mihelac.org

Bojan,

Once you make the changes like we did for MasterView then theoretically
you
could serve from anywhere. Like I mentioned in MasterView we are able to
easily change to serve from filesystem or a memory hash, and we plan to
add
serving from a db as well. So the short answer is yes, I don’t see any
limitations once you make the code changes.

Jeff

Thanks for your answer Jeff. Do you think it would be possible to use

Seems like storing rhtml in the model is a violation of MVC…

?

On 8/3/06, Brez! !! [email protected] wrote:

Seems like storing rhtml in the model is a violation of MVC…

Doesn’t it depend on whether your RHTML represents an instance of a
model?

If you’re doing a CMS, then wouldn’t it make sense to keep templates
in a database?


Austin G.
Thinking & Making: IA, UX, and IxD
http://thinkingandmaking.com
[email protected]

Well don’t call the MVC cops :slight_smile:

Actually I don’t think the physical location of where you store your
templates would violate anything, in the end you are still applying
the same MVC pattern regardless.

And I would agree if you are creating a CMS then it is a great place
to store them, you have one place to backup for all user data
(templates and content), you can have many versions, you don’t have to
provide users with access to be able to write to your file system,
etc.

Bojan M. <lists@…> writes:

Hi,
is it possible to store RHTML templates or partials in database?

thanks,
Bojan M.

Hi Bojan,

DB2 Express (the free version) and DB2 9.0 allows storing XML documents
(column type XML). So you may encapsulate your partials/RHTML templates
in XML tags and store the document as it is in database.
For details, please refer to
http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0311wong/

DB2 stores the documents as XML documents (does not do thrashing)and
allows Xqueries on the column so that you can retrieve only specific
part of the
document.

There is a starter toolkit for Rails on DB2 available
(http://www.alphaworks.ibm.com/tech/db2onrails) that contains complete
installation of DB2 Express, DB2 adapter for Rails and RoR.

HTH,
Ashutosh