librelist archives

« back to archive

Liquid Support

Liquid Support

From:
David Long
Date:
2012-04-17 @ 15:25
I want to use Liquid in my new blog setup for the site's views and content
pages (Markdown for blogs). I was wondering if anyone else has done this
before and has instructions or a post somewhere on how to do so.

-- 

Dave Long
Web Application Consultant

(203) 626-1809
www.davejlong.com

Re: [nesta] Liquid Support

From:
Max Sadrieh
Date:
2012-04-25 @ 02:36
On Tue, Apr 17, 2012 at 11:25 AM, David Long <dave@davejlong.com> wrote:
> I want to use Liquid in my new blog setup for the site's views and content
> pages (Markdown for blogs). I was wondering if anyone else has done this
> before and has instructions or a post somewhere on how to do so.

You know I'm actually slightly confused now. You say you want to use
Liquid for views and content. I started writing this simplistic plugin
for content when I realized it didn't really make sense in my head.

For the content, you don't manipulate any ruby variable or (for
example) an object returned by the database. Therefore, except maybe
for repeating text or basic text filters, it wouldn't really be
useful. Without any liquid filters it would simply be HTML.

For the views, it's slightly more complicated. It then makes sense to
use liquid over haml or erb for security reasons but you need to
modify other files I don't know about. The basics are in app.rb. You
see that nesta uses haml by default on line 94. The method 'haml' is
defined in overrides.rb, together with other similar methods. I've
never touched this file and I just glanced at it so I'm not sure
exactly how to modify it. If you do use a different format though, you
need to check which variables you need passed to the liquid template
and create it accordingly (such as @page, @description in page, etc.).
Check layout.haml and page.haml. It's unclear to me how liquid will
use the yield directive (to chain layout, page, and the actual
content). Getting back to the overrides.rb file, the super it calls
are, if I understand correctly, from Sinatra itself. Check [1] and
read "Templates".

Which reminds me (just now), of a discussion between Graham (gma) and
Nathanael (nathanaeljones) on Github [2] [3]. I haven't read the new
Sinatra code Nathanael references but his basic helper method 'liquid'
should work for your purpose.

Overall still confused about how all this works. Using liquid for
content is extremely easy (I can finish the plugin if that's all you
want). Using it for views is slightly more challenging (I might also
look into that but probably in a few weeks).

Hope that helped.

[1] http://sinatra-book.gittr.com/#templates
[2] https://github.com/gma/nesta/issues/73
[3] https://github.com/gma/nesta/issues/74

Re: [nesta] Liquid Support

From:
Graham Ashton
Date:
2012-04-25 @ 07:56
On 25 Apr 2012, at 03:36, Max Sadrieh wrote:

> For the content, you don't manipulate any ruby variable or (for
> example) an object returned by the database. Therefore, except maybe
> for repeating text or basic text filters, it wouldn't really be
> useful. Without any liquid filters it would simply be HTML.

Yeah; using markup languages in the content folder is largely a mistake. 
If you need it a lot, something has probably gone wrong...

> Getting back to the overrides.rb file, the super it calls
> are, if I understand correctly, from Sinatra itself. Check [1] and
> read "Templates".

It is. You'll need a `liquid` method similar to the `haml` and `sass` 
methods in overrides.rb. You can add that in your own app.rb file by 
opening up the Nesta::Navigation module and defining the method. Then add 
your own route handlers and call `liquid` on the last line instead of 
`haml`.

See this thread:


http://librelist.com/browser//nesta/2011/12/4/issues-using-erb-with-nesta/#05429f5b0520c67a7dfdf585af720fbd

> Overall still confused about how all this works. Using liquid for
> content is extremely easy (I can finish the plugin if that's all you
> want).

Good stuff Max. If you complete it I'm not sure that it would be a good 
idea to publish it widely (i.e. I wouldn't release a gem, I'd install 
direct from the GitHub repo), if it is indeed what David wants, as it 
might suggest the wrong path to people. Where the wrong path is putting 
lots of markup in content/pages; I've seen sites that have been built with
that approach before, and they become very hard to maintain. There's 
always been a much better way to organise things.

--
Graham Ashton
Founder, The Agile Planner
http://theagileplanner.com | @agileplanner | @grahamashton


Re: [nesta] Liquid Support

From:
Max Sadrieh
Date:
2012-04-24 @ 18:57
On Tue, Apr 17, 2012 at 11:25 AM, David Long <dave@davejlong.com> wrote:
> I want to use Liquid in my new blog setup for the site's views and content
> pages (Markdown for blogs). I was wondering if anyone else has done this
> before and has instructions or a post somewhere on how to do so.

Hi David,

I don't know whether anyone has done this before but it should be
doable relatively easily if you know some Ruby (and it looks like the
Liquid syntax is close-ish to Ruby so it shouldn't be a problem).
Nesta uses Tilt which acts as a proxy/interface to template engines,
including Liquid.

You will probably have to hack the code of nesta slightly to get it to
work but it should be relatively easy. Search for the string 'haml'
and for the string 'Tilt' in the source and try to adapt the code for
liquid. Most of it should be in lib/nesta/models.rb

An alternative is to use erb directly. The syntax looks similar except
that erb is simple and complete ruby, which probably does have
security implications, depending on your usage.

For more info, check:
https://github.com/gma/nesta (lib/nesta/models.rb)
https://github.com/rtomayko/tilt (ctrl-F 'liquid')

If/when Graham figures out how to organize formats as plugins this
should be much easier.

Cheers.

-Max