2016-07-11 2 views
2

Я недавно установил Jade (Pug) на Mac OS X Yosemite.Jade (Pug) Html render output

Я установил Node.js последнюю версию, а затем используется терминал команды: $ sudo npm install pug-cli -g

Все было прекрасно, пока я не должен был оказанным файл. Я создал 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. 

, а затем использовал терминал, чтобы сделать его, чтобы проверить его. Я использовал: $ pug -P test.pug и оказано test.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> 
    <div 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> 
    </div> 
    </body> 
</html> 

Ну теперь, когда я хочу, чтобы сделать его авто и использовали -Смотрите особенность: $ pug -w test.pug он выводит, как это:

<!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><div 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></div></body></html> 

Я не могу найти исправление для этого. Для всех остальных, которые я просматриваю на YouTube или других учебных пособиях, вывод выглядит с правильной структурой HTML, но моя визуализируется как мини-версия.

Что я могу сделать, чтобы исправить это и сделать его автоматически рендерингом с правильным выходом в HTML?

ответ

5

Опция, которую вы устанавливаете в первом варианте (-P), позволяет префиксацию вывода. Если вы хотите на втором варианте, просто добавьте флаг: pug -P -w test.pug

Из документов:

-h, --help    output usage information 
-V, --version   output the version number 
-O, --obj <path|str> JavaScript options object or JSON file containing it 
-o, --out <dir>  output the compiled html to <dir> 
-p, --path <path>  filename used to resolve includes 
-P, --pretty   compile pretty html output 
-c, --client   compile function for client-side runtime.js 
-n, --name <str>  the name of the compiled template (requires --client) 
-D, --no-debug   compile without debugging (smaller functions) 
-w, --watch   watch files for changes and automatically re-render 
-E, --extension <ext> specify the output file extension 
--name-after-file  name the template after the last section of the file path 
         (requires --client and overriden by --name) 
--doctype <str>  specify the doctype on the command line (useful if it 
         is not specified by the template) 
+0

Спасибо. Оно работает. Я не знал, что могу использовать 2 варианта одновременно. Мне удалось использовать его с хрюканьем, но он также работает с вашим методом. – boggyn

0

Проверить http://jade-lang.com/api/.

В каждом методе API есть pretty (--pretty в CLI), который, если включен, делает вывод Jade доступным для чтения (довольно) HTML.

Смежные вопросы