学习 Jade_html/css_WEB-ITnose
优秀的模板引擎 Jade ,超强可读性,提升开发效率。
为什么需要 Jade ?
减少写代码,提高可读性,提高生活质量。。。
这一层一层的。。。
看 jade 的这个拼接。
Jade 优点:
- 超强的可读性
- 灵活的缩进
- 块扩展
- 代码默认经过编码处理以增强安全性
- 编译及运行时的上下文错误报告
- 命令行的编译支持
- HTML5 模式
- 可选的内存缓存
- 利用过滤器解析树的处理
后面说的什么鬼其实我也不懂,但是最大优点: 超强的可读性 , 提升开发效率 。
需要 Node.js 环境, 没有装的可以参考 Mac 上配置 Node.js 环境
安装 Jade
# 通过 npm 安装 jade$ npm install jade -g
开始使用
创建 index.jade 文件
index.jade
doctype htmlhtml head title hanks.xyz body p welcome to hanks.xyz
就是这么简单,下面开始将 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>%
可以看到渲染出来的 index.html 文件是经过压缩过的。我们可以加速 -P 参数格式化渲染的 index.html
$ jade -P index.jade
html:
<!DOCTYPE html><html> <head> <title>hanks.xyz</title> </head> <body> <p>welcome to hanks.xyz</p> </body></html>
还可以加上 -w 参数监听 jade 文件的变化,自动渲染刷新 html 文件
$ jade -P -w index.jade
基本语法
标签
默认,每行开始的 第一个单词 代表一个标签,可以是自定义的标签
jade:
p welcome to hanks.xyzh1 h1 标题h2 h2 标题
html:
<p>welcome to hanks.xyz</p><h1 id="h-标题">h1 标题</h1><h2 id="h-标题">h2 标题</h2>
使用 缩进 代表标签嵌套关系
jade:
div.title h1 title2 p somethingdiv div div.info(name="hanks")
html:
<div class="title"> <h1 id="title">title2</h1> <p> something</p></div><div> <div> <div name="hanks" class="info"></div> </div></div>
class 和 id
jade:
h1.titleh2#title#t_id#t_id.title
html:
<h1 class="title"></h1><h2 id="title"></h2><div id="t_id"></div><div id="t_id" class="title"></div>
### 属性
jade:
a(herf="http://hanks.xyz") hanks.xyzinput#username(name="username",type="text",vaule="jade")
html:
<a herf="http://hanks.xyz">hanks.xyz</a><input id="username" name="username" type="text" vaule="jade">
Plain Text
jade:
p. 1.aa 2.vv 3.cc
html:
<p> 1.aa 2.vv 3.cc</p>
注意 p 标签后面紧跟着一个 .
jade:
p. 1.aa<strong>AA</strong> 2.vv 3.ccp | 1.aa strong AA | 2.vv | 3.cc
html:
<p> 1.aa<strong>AA</strong> 2.vv 3.cc</p><p>1.aa<strong>AA</strong>2.vv 3.cc</p>
注释
jade:
div // h1 单行注释,输出到源文件 //- h3 非缓冲注释 // 这是一个 多行注释
html:
<div> <!-- h1 单行注释,输出到源文件--> <!-- 这是一个 多行注释 --></div>
jade 使用双斜线 // 进行单行注释;
如果不想让注释的内容显示到生成的 html 代码中,可以在双斜线 // 后跟一个单横线 - ;
双斜线 // 后面的注释内容换行并缩进可进行块级注释
参考文章:
Jade中文教程
慕课网视频-带你学习Jade模板引擎
文章来自:http://hanks.xyz

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





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

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

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

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

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.

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

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

This article explains the HTML5 <time> 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
