SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to store html in the database with ror?

    I would like to start my next static 6 pages website in ror so i can use its facilities, caching, templating system etc also for a static only website. My thoughts are on how i store the html in the database so in the future i can for example also make a foreign language version of the site. Maybe i have to store all the html from that for the rails layouts to that of the single .rhtml templates. But how should i sotre it in the database? I put all that html in database rows and then extract it from instance variables in .rhtml templates, partials and layouts? If i do so then my html source will be messy? If i want to have a html source nicely formatted how can i do?

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are doing some internationalization, globalize is probably worth checking out.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm View Post
    If you are doing some internationalization, globalize is probably worth checking out.
    that is ok for sites in more than one language but my concern is on mainteining the code layout in the database

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using Rails for a small static website is an overkill, and it will be much slower. You can easily put .rhtml files in a dir and write a ruby script to run these files to produce .html files that you upload to your site (maybe automatically). The file system is much better for this than a db.

  5. #5
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    Using Rails for a small static website is an overkill, and it will be much slower. You can easily put .rhtml files in a dir and write a ruby script to run these files to produce .html files that you upload to your site (maybe automatically). The file system is much better for this than a db.
    We have seen dozines of debates on this argument and i personally see only benefits form running even the simplest static website in ror. I use it even for a 4-5 pages static website in conjuction with page caching and the db where necessary. Also in the famous book rails recipes it talks about using ror for a simple stati site with page caching.

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Creating a complex solution for a simple problem is simply not the Ruby way.

  7. #7
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it is not complex

  8. #8
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you're basically recreating basic server functionality in Rails ;-).

    Anyway, I'll answer your questions:

    "But how should i sotre it in the database?"

    Blob or Text.

    "I put all that html in database rows and then extract it from instance variables in .rhtml templates, partials and layouts?"

    Yes. You'll have a model page with one attribute content. Your template will look like this:

    Code:
    <html>
    ...
    <&#37;= @page.content %>
    ...
    </html>
    "If i do so then my html source will be messy?"

    The indentation might not be right, but does that matter?

    "If i want to have a html source nicely formatted how can i do?"

    http://tidy.sourceforge.net/

    Have you thought about how to edit pages? Are you going to edit html in a textarea? Are you going to store the .html in files on your computer (so you can edit them with a nice text editor) and upload them to rails/db? Or via ftp?

  9. #9
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    Well, you're basically recreating basic server functionality in Rails ;-).

    Anyway, I'll answer your questions:

    "But how should i sotre it in the database?"

    Blob or Text.

    "I put all that html in database rows and then extract it from instance variables in .rhtml templates, partials and layouts?"

    Yes. You'll have a model page with one attribute content. Your template will look like this:

    Code:
    <html>
    ...
    <%= @page.content %>
    ...
    </html>
    "If i do so then my html source will be messy?"

    The indentation might not be right, but does that matter?

    "If i want to have a html source nicely formatted how can i do?"

    http://tidy.sourceforge.net/

    Have you thought about how to edit pages? Are you going to edit html in a textarea? Are you going to store the .html in files on your computer (so you can edit them with a nice text editor) and upload them to rails/db? Or via ftp?
    Ok, i've done it and it work perfectly with meaningful routes and caching. I edit my pages in a texarea and i was surprised to see that rails automatically escaped all the html content from the database when it output the html in the textarea. (i didn't have to use h())

  10. #10
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't editing html in a textarea a pain (no highlighting, no indenting, ...)? Do you know about textile/markdown?

    What are the advantages of this over a Ruby script?

  11. #11
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    Isn't editing html in a textarea a pain (no highlighting, no indenting, ...)? Do you know about textile/markdown?

    What are the advantages of this over a Ruby script?
    Ok it would be better to have highlight like in the editor but i will use it only to change a little text inside html. The advantage is that i use a system that i already know well and with all its support (layout system, caching etc.) and most important when the client tomorrow will decide to switch to a dynamic site i have all ready to do that. For the html is there any rails relate tool instead of what you mentioned above?

  12. #12
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I find textile and markdown much easier to work with than html (especially in a text area). Textile and markdown are markup languages that are translated into html. For example:

    Code:
    = A title =
    
    This is _Markdown_, a markup language.
    
    * Item
    * Another
    * And another
    This is translated to:

    Code:
    <h1>A title</h1>
    
    <p>This is <em>Markdown</em>, a markup language.</p>
    
    <ul>
    <li>Item</li>
    <li>Another</li>
    <li>And another</li>
    </ul>
    You can embed html in textile/markdown, so you don't lose flexibility.

    Rails has built-in helpers for textile/markdown:

    Code:
    textilize(@page.content)
    markdown(@page.content)
    Code:
    gem install redcloth (for textile)
    gem install bluecloth (for markdown)
    http://hobix.com/textile/
    http://daringfireball.net/projects/markdown/

  13. #13
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    I find textile and markdown much easier to work with than html (especially in a text area). Textile and markdown are markup languages that are translated into html. For example:

    Code:
    = A title =
    
    This is _Markdown_, a markup language.
    
    * Item
    * Another
    * And another
    This is translated to:

    Code:
    <h1>A title</h1>
    
    <p>This is <em>Markdown</em>, a markup language.</p>
    
    <ul>
    <li>Item</li>
    <li>Another</li>
    <li>And another</li>
    </ul>
    You can embed html in textile/markdown, so you don't lose flexibility.

    Rails has built-in helpers for textile/markdown:

    Code:
    textilize(@page.content)
    markdown(@page.content)
    Code:
    gem install redcloth (for textile)
    gem install bluecloth (for markdown)
    http://hobix.com/textile/
    http://daringfireball.net/projects/markdown/
    wow that is wonderful!!I'll try it. Which one do you advise to me? Is there a better one or one with more support to standards? Do they also support colors? Thanks

  14. #14
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A problem arise. If i have already in the database the html content (in normal html markup), as i have for my site, is there a method to convert from normal html markup to Redcloath? I see only the oppsite "redcloth_object.to_html"

  15. #15
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's no problem, you can just leave the HTML. HTML can be embedded in textile. So if you textilize() the HTML that you have in the DB now, textilize() will just return the HTML unmodified.

    I don't think there is an automatic converter.

  16. #16
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    That's no problem, you can just leave the HTML. HTML can be embedded in textile. So if you textilize() the HTML that you have in the DB now, textilize() will just return the HTML unmodified.

    I don't think there is an automatic converter.
    ok thanks. But which is the best? Redcloth or bluecloth? I see that with redcloth ruby library i can use textile and markdown syntax where textile syntax has a higher precedence.
    And for the colored syntax?
    The last problem is that some textile strings like for example "bq." ,to generate a blockquote element, is based on elnglish obviously but my users speak italian Is there any internationalization support for these projects?

  17. #17
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Skyblaze View Post
    ok thanks. But which is the best? Redcloth or bluecloth? I see that with redcloth ruby library i can use textile and markdown syntax where textile syntax has a higher precedence.
    I prefer using Redcloth/textile but that's because I used textile before with blogging systems like Textpattern. It's really a personal preference, or you can allow the user to decide which one to use.
    Quote Originally Posted by Skyblaze
    And for the colored syntax?
    Do you mean like code highlighting? I like Coderay for that.
    Quote Originally Posted by Skyblaze
    The last problem is that some textile strings like for example "bq." ,to generate a blockquote element, is based on elnglish obviously but my users speak italian Is there any internationalization support for these projects?
    Think of textile's markup method as similar to HTML. There's no "cabeza" element in HTML if you're writing a page in Spanish, it's just <head>. Besides, very few textile strings actually use phrases to denote anything. Most of them are symbols like @[code]@ or ![image]!.

  18. #18
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean like code highlighting? I like Coderay for that.
    Ok but i need to highlight the textile syntax for example 'cause that is the output for the user to edit in a textarea that display the database content in textile format.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •