如何格式化玉表?

时间:2013-05-14 12:26:44

标签: node.js pug

我正在尝试重构我的应用程序以使用jade而不是ejs但是在设置登录表单时遇到了一些问题。

这是我在ejs中的原始形式:

<% if (message) { %>
<p><%= message %></p>
<% } %>

<form class="form-horizontal" action='/login' method="POST" id="loginForm">
  <fieldset>
    <div id="legend">
      <legend class="">Login</legend>
    </div>
    <div class="control-group">
      <!-- Username -->
      <label class="control-label"  for="username">Username</label>
      <div class="controls">
        <input type="text" id="username" name="username" placeholder="" class="input-xlarge">
      </div>
    </div>

    <div class="control-group">
      <!-- Password-->
      <label class="control-label" for="password">Password</label>
      <div class="controls">
        <input type="password" id="password" name="password" placeholder="" class="input-xlarge">
      </div>
    </div>

    <div class="control-group">
      <!-- session-->
      <label class="control-label" for="rememberme">Remember Me</label>
      <div class="controls">
        <input type="checkbox" name="rememberme"/>
      </div>
    </div>


    <div class="control-group">
      <!-- Button -->
      <div class="controls">
        <button class="btn btn-success">Login</button>
      </div>
    </div>
  </fieldset>
</form>

这是我在玉器中的新形式:

extends layout

block content
    if message
        p= message
    form(class='form-horizontal',action='/login',method='POST',id='loginForm')
        fieldset
            div#legand
                legend Login
            div.control-group
                label(for='username',class='control-label') Username
                div.controls
                    input(type='text',id='username',name='username',placeholder='Username',class='input-xlarge')
            div.control-group
                label(for='password',class='control-label') Password
                div.controls
                    input(type='text',id='password',name='password',placeholder='Password',class='input-xlarge')
            div.control-group
                label(for='rememberme',class='control-label') Remember Me
                div.controls
                    input(type='checkbox',name='rememberme')
            div.control-group
                div.controls
                    input(type='submit',class='btn btn-success') Login

Codekit抛出错误:

/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/runtime.js:173
  throw err;
        ^
Error: /Users/sm/Documents/Projects/Web_Applications/App/app/views/login.jade:27
    25| 
    26| 
  > 27|   

Invalid indentation, you can use tabs or spaces but not both
    at Object.Lexer.indent (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:672:15)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:770:15)
    at Object.Lexer.blank (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:179:19)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:744:15)
    at Object.Lexer.blank (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:179:19)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:744:15)
    at Object.Lexer.lookahead (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:106:46)
    at Object.Parser.lookahead (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:115:23)
    at Object.Parser.peek (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:92:17)
    at Object.Parser.tag (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:666:30)

如何通过此缩进错误并使此表单生效?我只使用标签而没有空格,所以我不明白问题是什么。

2 个答案:

答案 0 :(得分:2)

这可能是由Jade模板中的空白行中的空格引起的(您没有发布,但根据错误消息存在)。

答案 1 :(得分:1)

我认为您的问题可能就是您指定按钮的方式。而不是:

            div.control-group
                div.controls
                    input(type='submit',class='btn btn-success') Login

尝试:

            div.control-group
                div.controls
                    button(type='submit',class='btn btn-success') Login