Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper indentation when using code blocks #507

Closed
ghost opened this issue May 18, 2014 · 5 comments
Closed

Improper indentation when using code blocks #507

ghost opened this issue May 18, 2014 · 5 comments

Comments

@ghost
Copy link

ghost commented May 18, 2014

Hi,

I switched my project to Slim from Haml, Slim has more intuitive syntax and is faster than Haml, but the Pretty renderer is little buggy. My customer requires that HTML output must be intended for readability purposes, so this bug is a deal-breaker for me. I use Nestive gem (https://github.com/rwz/nestive) to manage layout inheritance and extendable areas. Nestive provides an area helper which allows to replace or extend rendered content.

This is example Slim code from real world application:

doctype html
html lang=I18n.locale
  head
    = area :head
      = page_title_tag
      = page_meta_tags
      = csrf_meta_tags

And Slim configuration options:

Slim::Engine.set_default_options pretty: true

Unfortunately, output code have broken indentation:

<!DOCTYPE html>
<html lang="pl">
  <head>
        <title></title>
        <meta content="" name="generator" />
        <meta content="" name="keywords" />
        <meta content="" name="description" />
        <meta content="" name="csrf-token" />

As you can see, all lines following area have a 6 spaces indentation relative to <head> tag. The same code in HAML works as expected, providing proper indent:

!!! 5
%html{ lang: I18n.locale }
  %head
    = area :head do
      = page_title_tag
      = page_meta_tags
      = csrf_meta_tags

Output:

<!DOCTYPE html>
<html lang="pl">
  <head>
    <title></title>
    <meta content="" name="generator" />
    <meta content="" name="keywords" />
    <meta content="" name="description" />
    <meta content="" name="csrf-token" />

Things get even more messed if I want to append or prepend code to area function. With this code:

- prepend :head
  .test-div

doctype html
html lang=I18n.locale
  head
    = area :head
      = page_title_tag
      = page_meta_tags
      = csrf_meta_tags

Slim output is:

<!DOCTYPE html>
<html lang="pl">
  <head><div class="test-div"></div>
        <title></title>
        <meta content="" name="generator" />
        <meta content="" name="keywords" />
        <meta content="" name="description" />
        <meta content="" name="csrf-token" />

When HAML again have a proper indents:

<!DOCTYPE html>
<html lang="pl">
  <head>
    <div class="test-div"></div>
    <title></title>
    <meta content="" name="generator" />
    <meta content="" name="keywords" />
    <meta content="" name="description" />
    <meta content="" name="csrf-token" />

Is there any solution to this problem? I admit that I like Slim more than Haml and want to use it in all my projects, but this bug leaves me with a choise to monkey-patch Pretty renderer or switch back to Haml.

@ghost
Copy link
Author

ghost commented May 18, 2014

May also be related with #440

@minad
Copy link
Member

minad commented May 19, 2014

The pretty renderer is not working well under some circumstances since Slim's focus lies on performance. If you have time please provide patches for the pretty renderer of the temple project https://github.com/judofyr/temple and also provide test cases.

@judofyr
Copy link
Member

judofyr commented May 19, 2014

FYI: The intention was for Temple to ship with three HTML modes:

  • Fast (fast runtime, minimize space)
  • Pretty (pretty HTML, some runtime overhead)
  • PrettyFast (fast runtime, as-pretty-as-possible HTML)

As of today, the current Pretty renderer is working as what PrettyFast was
supposed to be.

On Monday, May 19, 2014, Daniel Mendler notifications@github.com wrote:

The pretty renderer is not working well under some circumstances since
Slim's focus lies on performance. If you have time please provide patches
for the pretty renderer of the temple project
https://github.com/judofyr/temple and also provide test cases.


Reply to this email directly or view it on GitHubhttps://github.com//issues/507#issuecomment-43487190
.

// Magnus Holm

@minad
Copy link
Member

minad commented May 19, 2014

Yes, but Pretty (as you name it PrettyFast) is enough. If you need PrettyPretty just use Nokogiri or some other library to reindent. However this doesn't mean that some easy to fix issues in Pretty mode should just stay there.

@minad
Copy link
Member

minad commented Dec 2, 2014

fixed in temple master

@minad minad closed this as completed Dec 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants