Project

cuba-haml

0.0
No commit activity in last 3 years
No release in over 3 years
Cuba is a microframework for web applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
>= 0
 Project Readme

cuba-haml

A Cuba plugin to use Haml

Configure

Cuba::Haml plugin introduces some keys into Cuba.settings to make easy the way to reander layouts

  # Default layouts directory
  app.settings[:haml][:layout_path] ||= app.settings[:haml][:views]
  
  # Default layout file
  app.settings[:haml][:layout] ||= "layout"

Feel free to overwrite this variables after install the plugin. Following this example

require "cuba/haml"

Cuba.plugin Cuba::Haml
Cuba.settings[:haml][:layout_path] = "some/other/path"
Cuba.settings[:haml][:layout] = "not_default_layout"

Rendering

Cuba ships with a plugin that provides helpers for rendering templates. But if only want to use haml, you can specify this plugin.

require "cuba/haml"

Cuba.plugin Cuba::Haml

Cuba.define do
  on default do

    # Within the partial, you will have access to the local variable `content`,
    # that will hold the value "hello, world".
    res.write render("home.haml", content: "hello, world")
  end
end

Using the method render, you need to provide full path template so there are two methods to do it easy template_path(template_name) and layout_path(layout).

But you can use the haml helper to get a cleaner code

...
  on default do
    haml("home", content: "hello, world")
  end
...

Also if you want to override the default layout you can use the view helper

...
  on default do
    view("home", 'other-layout', content: "hello, world")
  end
...

Don't be afraid and read the tests, there are really simple I promisse!

Note that in order to use this plugin you need to have Haml installed.