Haml: Absence of indentation in the output file

Created on 23 Jun 2017  路  14Comments  路  Source: haml/haml

After upgrading to 5.0.1, I observe no indentation in output files. For example, I get

<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
</head>
</html>
<body>
<main>
<div>
<p>This is a sample.</p>
</div>
</main>
</body>

after running haml sample.haml sample.html with the following file as an input:

!!!5
%html
  %head
    %title Sample
%body
  %main
    %div
      %p This is a sample.

Linux (Arch); Ruby 2.4.1p111; Haml 5.0.1

Most helpful comment

I ran into this issue as well. We compare HAML generated XML files with stored XML files in our tests. Not having the indentation anymore meant we had to rewrite the tests. Also it makes it harder to just read the files. It would be great if a new modifier --beautiful (or --with-indentation) would be introduced.

All 14 comments

Ugly option has been removed since version 5.
Consider the discussion: https://github.com/haml/haml/pull/894

Do I understand correctly that in the ugly mode (which is now the default) the program just removes the HTML indentation, but preserves newlines and the indentation of embedded JavaScript and CSS? Is there anything else one should know regarding what is being removed and what is being remained?

We need to update the reference.md & faq.md docs to reflect the new default HTML format.

I'm kind of against the dropping of the --ugly option, but if "ugly" mode is on by default, why even bother with new lines?

I second that that's not coherent.

I ran into this issue as well. We compare HAML generated XML files with stored XML files in our tests. Not having the indentation anymore meant we had to rewrite the tests. Also it makes it harder to just read the files. It would be great if a new modifier --beautiful (or --with-indentation) would be introduced.

One of my developers had this issue. For anyone that gets to the end of this thread and wants to know another way, we didn't rely on the output of haml to do what we wanted. We were able to indent by piping the output of haml to tidy with the -i option. That should solve the issue for some.

I have no idea any dev is watching this issue (due to long time not having any response from repository contributors), but I'm just want to ask if there is any way to restore this option, or you are strongly opinionated against ugly option. Partially because some of us not like / not use browsers own inspectors but instead watching the "show source" output (and this is not prettified automagically), partially because some of us use HAML to different stuffs than HTML where is harder to automatically get indented output during the development. I read the discussion at #894 but cannot find a technical reason for removing the possibility for non-ugly output.

I always say less code is better code, but maybe someone else said this before me. I _assume_ the reasoning for their decision is as follows. If there is already another open source tool to achieve the
"edge use case" that works sufficiently and is actively maintained, you probably don't need to support it in your project. I suppose you are frusterated the same way we were originally, which is that it feels like part of the workflow and you don't want another tool. However, the workflow is usually: 1. write haml, 2. uglify, 3. test, 4. deploy. In other words, uglification is the best practice. A solid reason to want indentation is because you either don't trust HAML or you don't trust your abilities with it. I would agree these are use cases, but more on the edge instead of the "happy path". As I mentioned, developers can run this transformation fairly easily with tidy which is readily available in common package management systems. See: http://tidy.sourceforge.net/

@cboynton-cweil No, there is a third reason to why not want to uglify HAML in development and this is because at the beginning of the projects I have to port a HTML design to HAML and sometimes the output is just tear apart. It's easier to compare two well-formed HTML line-by-line in the browser than using tools that not designed to do this (like, web developer toolbars in Chrome/Firefox) or pasting the whole source code into some online stuffs. You know, browsers has this wonderful "View source" feature for years ago, and I just want to enjoy the benefits of it.

You have described an additional case for seeing the indentation in output. I do think there are many more use cases and that my list was not exhaustive. I assume you need a solution to an active problem and aren't here to just complain that feature X isn't in the code. Therefore, if you would like to discuss using Tidy, could you frame your question somewhere on the StackOverflow platform and I'll do my best to help? This really isn't the best place to discuss it. Feel free to link to your question so that other people can find it.

@cboynton-cweil Yes, I have an active problem that was solved by Haml previously by silently tidying/indenting HTML output in development environment without any further tool or inconvenience. Meanwhile I trying and checking out alternative workarounds and try to fit them into my workflow, but at the current state, I really miss Haml's autoformatting.

Also I still not get why this feature was removed. If Haml just uglify the output automagically by default, why not let users to disable it? Was it a security issue? You restructured the code and indentation broke? Or why?

As I mentioned already, please post a link to a question on a question/answer platform and I'll do my best to answer it for you. A proper solution would take into account what your environment is (operating system, software, servers, configuration), what your workflow is (what steps are you taking), how you expect it to work (what steps are failing), etc.

Every feature requires maintenance. Projects that get too big are harder to maintain. I personally support the removal of features based on this alone. Sure, it might require a little additional tooling for the end user. However, it is assumed this is common enough that most users will be able to do it. I am not suggesting that you do not have a complex setup. This is why I do not think this is the proper channel to discuss it. This is my final post on this subject on this channel.

@cboynton-cweil I started to test a tool that might solves my problem. If not, I will post a StackOverflow.com link.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dewski picture dewski  路  8Comments

atomAltera picture atomAltera  路  7Comments

richardaday picture richardaday  路  25Comments

modsognir picture modsognir  路  6Comments

mattwildig picture mattwildig  路  9Comments