jlong / serve

Serve is a small Rack-based web server and rapid prototyping framework for Web applications (specifically Rails apps). Serve is meant to be a lightweight version of the Views part of the Rails MVC. This makes Serve an ideal framework for prototyping Rails applications or creating simple websites. Serve has full support for Rails-style partials and layouts.
http://get-serve.com
Other
836 stars 90 forks source link

Haml config #22

Closed inferno closed 12 years ago

inferno commented 13 years ago

Hi!

How i can set Haml options for render templates?

adamstac commented 13 years ago

I've wanted to do this as well. Specifically to set my views to render with HTML5 and set the default attribute wrapper. For example:

# Default is an empty hash
# http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options
configuration.haml_options = {
  :format => :html5,
  :attr_wrapper => '"'
}
jlong commented 13 years ago

Drop this in your config.ru:

require 'haml'
class Haml::Engine
  alias old_initialize initialize
  def initialize(lines, options)
    options.update(:format => :html5)
    old_initialize(lines, options)
  end
end

I will look at making this a little cleaner for the next version.

inferno commented 13 years ago

Thank, its really helpful.

adamstac commented 13 years ago

Works for me for now. Thanks John ;)

JakeCarter commented 12 years ago

Is the above code snippet still the work-around for making this work? I dropped it in my config.ru and it didn't change the output of my HTML. Any suggestions?

jlong commented 12 years ago

Hrrm. It may require an older version of Haml. Are you using the latest alpha?

JakeCarter commented 12 years ago

I didn't do anything special to install these. I'm running Haml 3.1.4 (Separated Sally) and Serve 1.5.1. Here's my config.ru file. Perhaps I put the snippet in the wrong place? https://gist.github.com/1994453

JakeCarter commented 12 years ago

Ok, I found a problem with my previous config.ru script and have fixed it. Serve is now outputting my Haml as HTML5 when using the Serve server. But when I do a serve export, its still outputting XHTML 1.0 Transitional. Is there a work around for this?

ntalbott commented 12 years ago

That's really odd, since the export is supposed to just load those pages and dump them verbatim. Can you give me a little sample project that reproduces the issue?

JakeCarter commented 12 years ago

Yeah. I'll test it again tonight and post a link here later. Thanks.

JakeCarter commented 12 years ago

Ok, I created a test project here: https://github.com/JakeCarter/html5test

When I use serve to serve the project it will render them as HTML5, but when I use serve export it will render them as XHTML 1.0 Transitional.

Let me know if you need any more info.

Thanks for looking into this for me.

ntalbott commented 12 years ago

I just added a nicer way of configuring templating engines:

Serve::FileTypeHandler.configure(:haml, :format => :html5)

I'd recommend putting it in view_helpers.rb rather than config.ru, as the latter is not loaded when exporting.