Table of Contents
为什么需要 Jade ?
安装 Jade
开始使用
基本语法
标签
h2 标题
title2
class 和 id
Plain Text
注释
Home Web Front-end HTML Tutorial 学习 Jade_html/css_WEB-ITnose

学习 Jade_html/css_WEB-ITnose

Jun 21, 2016 am 08:52 AM

优秀的模板引擎 Jade ,超强可读性,提升开发效率。

为什么需要 Jade ?

减少写代码,提高可读性,提高生活质量。。。

这一层一层的。。。

看 jade 的这个拼接。

Jade 优点:

  • 超强的可读性
  • 灵活的缩进
  • 块扩展
  • 代码默认经过编码处理以增强安全性
  • 编译及运行时的上下文错误报告
  • 命令行的编译支持
  • HTML5 模式
  • 可选的内存缓存
  • 利用过滤器解析树的处理

后面说的什么鬼其实我也不懂,但是最大优点: 超强的可读性提升开发效率

需要 Node.js 环境, 没有装的可以参考 Mac 上配置 Node.js 环境

安装 Jade

# 通过 npm 安装 jade$ npm install jade -g
Copy after login

开始使用

创建 index.jade 文件

index.jade

doctype htmlhtml  head    title hanks.xyz  body    p welcome to hanks.xyz
Copy after login

就是这么简单,下面开始将 jade 文件渲染为 html 文件

$ jade index.jade  rendered index.html$ cat index.html<!DOCTYPE html><html><head><title>hanks.xyz</title></head><body><p>welcome to hanks.xyz</p></body></html>%
Copy after login

可以看到渲染出来的 index.html 文件是经过压缩过的。我们可以加速 -P 参数格式化渲染的 index.html

$ jade -P index.jade
Copy after login

html:

<!DOCTYPE html><html>  <head>    <title>hanks.xyz</title>  </head>  <body>    <p>welcome to hanks.xyz</p>  </body></html>
Copy after login

还可以加上 -w 参数监听 jade 文件的变化,自动渲染刷新 html 文件

$ jade -P -w index.jade
Copy after login

基本语法

标签

默认,每行开始的 第一个单词 代表一个标签,可以是自定义的标签

jade:

p welcome to hanks.xyzh1 h1 标题h2 h2 标题
Copy after login

html:

<p>welcome to hanks.xyz</p><h1 id="h-标题">h1 标题</h1><h2 id="h-标题">h2 标题</h2>
Copy after login

使用 缩进 代表标签嵌套关系

jade:

div.title  h1 title2  p  somethingdiv  div    div.info(name="hanks")
Copy after login

html:

<div class="title">  <h1 id="title">title2</h1>  <p> something</p></div><div>  <div>    <div name="hanks" class="info"></div>  </div></div>
Copy after login

class 和 id

jade:

h1.titleh2#title#t_id#t_id.title
Copy after login

html:

<h1 class="title"></h1><h2 id="title"></h2><div id="t_id"></div><div id="t_id" class="title"></div>
Copy after login

### 属性

jade:

a(herf="http://hanks.xyz") hanks.xyzinput#username(name="username",type="text",vaule="jade")
Copy after login

html:

<a herf="http://hanks.xyz">hanks.xyz</a><input id="username" name="username" type="text" vaule="jade">
Copy after login

Plain Text

jade:

p.  1.aa  2.vv  3.cc
Copy after login

html:

<p>  1.aa  2.vv  3.cc</p>
Copy after login

注意 p 标签后面紧跟着一个 .

jade:

p.  1.aa<strong>AA</strong>  2.vv  3.ccp  | 1.aa strong AA | 2.vv | 3.cc
Copy after login

html:

<p>  1.aa<strong>AA</strong>  2.vv  3.cc</p><p>1.aa<strong>AA</strong>2.vv  3.cc</p>
Copy after login

注释

jade:

div  // h1 单行注释,输出到源文件  //- h3 非缓冲注释  //    这是一个    多行注释
Copy after login

html:

<div>  <!-- h1 单行注释,输出到源文件-->  <!-- 这是一个 多行注释 --></div>
Copy after login

jade 使用双斜线 // 进行单行注释;

如果不想让注释的内容显示到生成的 html 代码中,可以在双斜线 // 后跟一个单横线 - ;

双斜线 // 后面的注释内容换行并缩进可进行块级注释

参考文章:

Jade中文教程

慕课网视频-带你学习Jade模板引擎

文章来自:http://hanks.xyz

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

See all articles