开发者

What happens with Rails indentation in outputted HTML?

I'm writing code for a Rails view in TextMate (using the 2-space indentation standard). Whenever I view the output of my webpages (View Source), the HTML brackets always seem weirdly indented. For example, my application.html.erb looks like this:

<!DOCTYPE html>
<html>
<head>
  <title>Rainleader</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :all %>
  <%= csrf_meta_tag %>
</head>
<body>
    <div id="outer">
        <div class="contentwidth main">
            <%= render 'layouts/header' %>
        </div>

        <%= yield %>

</body>
&l开发者_如何学JAVAt;/html>

And the partial it's rendering (_header.html.erb) looks like this:

<div class="logo">
    <h1><a href="index.html">minimal.</a></h1>
</div><!-- end logo -->

But, an excerpt of the outputted HTML has misplaced (mis-indented) brackets (see my notes in the code below):

<body>
    <div id="outer">

        <div class="contentwidth main">
                        <div class="logo"> <<<Why is this so far to the right?
    <h1><a href="index.html">minimal.</a></h1>   <<<Why is this so far to the left?
</div><!-- end logo -->

What's going on here? If my call to the _header.html.erb partial in application.html.erb is indented four spaces, do I need to indent the code in the partial by at least that same amount to have it nest properly?


The first line of the partial that is rendered is indented as <%= render 'layouts/header' %> in application.html.erb. But all other lines of code are not indented further, just left-aligned as they are in your partial. It bugged me too, which is part of why I started using haml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜