winton / stasis

Static sites made powerful
http://stasis.me
MIT License
679 stars 56 forks source link

How do I use ruby methods in Stasis? #59

Closed gavinmcfarland closed 12 years ago

gavinmcfarland commented 12 years ago

Hi,

I'm trying to create a helper that escapes html for but unfortunately it says the method html_safe is undefined.

Am I writing this correctly?

This is what I have...

helpers do
    def code
        yield.html_safe
    end
end
winton commented 12 years ago

html_safe is a Rails method, you will need to require string extensions in your controller.rb:

require 'active_support/core_ext/string'
gavinmcfarland commented 12 years ago

I see. Thanks Winton. :)

gavinmcfarland commented 12 years ago

Hi. I required the correct library but found I was having the same problem, where it was saying the method was undefined. I found using html_escape works but only like the following...

def code(code)
    html_escape(code)
end

This unfortunately means I have to write in my views like this...

= code('<div class="test">test</div>')

I'd like to be able to write the view like this...

- code do
    <div class"test">test</div>

When I write it like this the HTML is no longer escaped

This is what I'm using for that block.

def code
    html_escape(yield)
end

Any thoughts on why the method isn't working in the haml view?

winton commented 12 years ago

There are a few ways in HAML to do what you are doing without writing your own helper. Suggest you look here:

http://haml.info/docs/yardoc/file.HAML_REFERENCE.html