[LRUG] Proffer and introducing constraints to Rails
Arek Turlewicz
quirek at gmail.com
Thu Apr 5 02:01:55 PDT 2012
On 05/04/12 15:59, Andrew Stewart wrote:
> On 4 Apr 2012, at 23:58, mudge wrote:
>
>> Perhaps if we could
>> simplify the view part to simply be:
>>
>> 1. Take some state;
>> 2. Return a string.
>>
>> Then views and helpers would be practically the same thing and we
>> could tackle some of these problems more easily.
> I think Mustache goes some way towards this:
>
> https://github.com/defunkt/mustache
>
Interesting. btw. I think I try to do something similar using what, we
already got in Rails like erb templates and by adding simple Widget
(View) class.
My goal is to be able to see structure of the page directly in the ruby
code like this:
def build_page
nav_bar = Widget.new("navigation_bar") do |nav_bar|
nav_bar << Container.new(:menu) do |menu|
menu << Widget.new("link", :label=> "Product list", :target =>
"/products")
menu << Widget.new("link", :label=> "About", :target => "/about")
end
nav_bar << Widget.new("search_field")
end
column_left = Container.new(:column_left) do |column_grid|
column_grid << ProductView.new(@product) if @product
column_grid << ProductListView.new(@products) if @products
column_grid << Container.new('picture_row') do |picture_row|
picture_row << Widget.new("sample_picture")
picture_row << Widget.new("sample_picture")
picture_row << Widget.new("sample_picture")
end
end
column_right = Container.new(:column_right) do |column_grid|
column_grid << Widget.new("sample_picture")
column_grid << Widget.new("sample_picture")
column_grid << Widget.new("sample_picture")
end
row_container = Container.new(:row_container) do |row_container|
row_container << column_left
row_container << column_right
end
@page = ::WebPage.build do |p|
p << nav_bar
p << row_container
p << Container.new(:footer)
end
end
Then I can call @page.render to generate page. I still use html.erb
templates to render single widgets.
So this extra layer is mostly as a design plan for programmer.
Example that use bootstrap is here:
https://github.com/arekt/rendering_view
Everything is in very early stage, but example works, so it could be
useful for someone.
cheers,
Arek Turlewicz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120405/60f46095/attachment-0003.html>
More information about the Chat
mailing list