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

Export non-compact HTML? #90

Closed agarzola closed 11 years ago

agarzola commented 11 years ago

Exporting my project results in compacted html (that is, all HTML in one line at the beginning of each document) instead of expanded (that is, respecting new line characters). Is there a way to get serve to convert my templates into HTML files that aren’t compacted?

agarzola commented 11 years ago

In case it’s relevant, I’m using Slim.

jlong commented 11 years ago

Try throwing this in your config.ru file:

# Indent html for pretty debugging and do not sort attributes (Ruby 1.8)
Slim::Engine.set_default_options :pretty => true, :sort_attrs => false

See: http://rdoc.info/github/slim-template/slim#Default_options

agarzola commented 11 years ago

I’m on Ruby 1.9.2p290, so I used:

# Indent html for pretty debugging and do not sort attributes (Ruby 1.9)
Slim::Engine.set_default_options pretty: true, sort_attrs: false

but it’s still generating compact HTML. Does it make a difference where in config.ru this line is?

jlong commented 11 years ago

I'm afraid there is probably not an easy way to change the options then. You could potentially monkey patch DynamicHandler in config.ru, but that requires a lot of Ruby fu.

agarzola commented 11 years ago

That’s too bad. Thanks anyway!

agarzola commented 11 years ago

I reported the issue to the slim team and it seems we were missing require 'slim' in config.ru right before Slim::Engine.set_default_options pretty: true, sort_attrs: false.

Adding this line is making slim produce expanded HTML when running serve, but not when exporting. Does serve export use a different config file where I should add this line?

jlong commented 11 years ago

Have a look here:

https://github.com/jlong/serve/blob/master/lib/serve/export.rb#L66-L86

Export is a fairly new feature. It doesn't use the config as it probably should.

agarzola commented 11 years ago

Do you think adding the above lines to the compile_view of my local server install will do the trick?

jlong commented 11 years ago

Probably.

agarzola commented 11 years ago

That did it. Thank you, jlong!