I create something like this

Which produces a partial - creates the code elements and renders the code partial I would like to wrap this all into one tidy element - ie calling the code partial will automatically render the partials inside the code block... so avoiding the replication

-# Text
= partial "./forms/input",
           :locals => { :name        => "text",
                        :label       => [ "Text Input" ],
                        :placeholder => "Enter Text",
                        :required    => true }

-# Code
:ruby
    code = %Q{
    partial "./forms/input",
               :locals => { :name        => "text",
                            :label       => [ "Text Input" ],
                            :placeholder => "Enter Text",
                            :required    => true }}

= partial "./scaffolding/code", :locals => { :code => code }

I thought it may be something like:

- haml_engine = Haml::Engine.new( code )
- output = haml_engine.render
- puts output

But I get undefined method `partial'

Any help appreciated

Thanks

Ian

有帮助吗?

解决方案

Basically the following is what I wanted.

-# Code
:ruby
    code = %{partial "./forms/input",
               :locals => { :name        => "text",
                            :label       => [ "Text Input" ],
                            :placeholder => "Enter Text",
                            :required    => true }}

= eval( code )

-# Code
:code
    #lang: #{ lang }
    = code
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top