search

Home  >  Q&A  >  body text

node.js - 菜鸟关于JADE的问题

请问一下jade模版怎么运行?在编译器里写好之后怎么运行测试?第一次用nodeJS,第一次用jade,不太理解

PHPzPHPz2864 days ago586

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:59:29

    When you say good writing, it should be "editor", right? ^^, anyone who can write good code in the "compiler" must be very cool!

    And it seems that it is not called jade now, but is called: pug.

    Open a command line and install the pug command tool first:

    npm install pug-cli -g

    If it is an operating system other than windows, add sudo

    in front of it

    Then write a template for pug:

    test.pug

    doctype html
    html(lang="en")
      head
        title= pageTitle
        script(type='text/javascript').
          if (foo) bar(1 + 5)
      body
        h1 Pug - node template engine
        #container.col
          if youAreUsingPug
            p You are amazing
          else
            p Get on it!
          p.
            Pug is a terse and simple templating language with a
            strong focus on performance and powerful features.

    Then in the command line, use the pug command to escape it into the real html:

    pug -P test.pug

    Then it automatically generated something like this html:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title></title>
        <script type="text/javascript">if (foo) bar(1 + 5)</script>
      </head>
      <body>
        <h1>Pug - node template engine</h1>
        <p class="col" id="container">
          <p>Get on it!</p>
          <p>
            Pug is a terse and simple templating language with a
            strong focus on performance and powerful features.
          </p>
        </p>
      </body>
    </html>

    htmlYou don’t need me to teach you how to use it?

    Of course, what I am introducing is an introduction for beginners. High-level usage is integrated into other project construction tools. Take your time, you won’t become fat if you eat it all in one go

    reply
    0
  • Cancelreply