对于需要实现共享的html 内容,tailor 提供了基础模版的概念,我们需要操作的就是添加slots ,以及使用slots
做为占位符

环境准备

使用现有的仓库代码 https://github.com/rongfengliang/tailor-skipper-docker-compose.
代码使用docker-compose 运行

测试

  • 模版布局
  • 代码说明
    base-template基于 slot 的占位符
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="dns-prefetch" href="https://example.com" />
<script type="slot" name="head"></script>
</head>
<body>
<slot name="body-start"></slot>
<div>Hello</div>
</body>
</html>
````
index.html tailor 需要一个index page
```code
<!-- Tailor needs an index.html -->
<meta slot="head" charset="utf-8">
<script slot="body-start" src="http://blah"></script>
<title slot="head">dalongrong demo</title>
<p>fragment a</p>
<fragment src="http://skipper:9090/fragment-a" primary ></fragment>
<p>fragment b</p>
<fragment src="http://skipper:9090/fragment-b" async primary ></fragment>
  • tailor server 代码说明
    主要是进行模版的配置,因为使用了base template 所以需要添加处理函数
'use strict';
const http = require('http');
const Tailor = require('node-tailor');
const fetchTemplate = require('node-tailor/lib/fetch-template'); const path = require("path")
const baseTemplateFn = () => 'base-template';
const tailor = new Tailor({
// 模版函数的定义,如果使用了base template 需要多个参数
// templatesPath: './templates',
fetchTemplate: fetchTemplate(
path.join(__dirname, 'templates'),
baseTemplateFn
)
}); // Root Server
http
.createServer((req, res) => {
tailor.requestHandler(req, res);
})
.listen(8080, function() {
console.log('Tailor server listening on port 8080');
});

fetchTemplate 函数签名说明

启动&&测试

  • 启动
docker-compose up -d
  • 测试

说明

官方文档对于基本模版的使用,说明的不是很清晰,结合示例以及源码,我们可以了解具体的实现

参考资料

https://github.com/rongfengliang/tailor-skipper-docker-compose
https://github.com/zalando/tailor/blob/master/docs/Base-Templates.md

 
 
 
 

tailor 基础模版的使用的更多相关文章

  1. hadoop概述测试题和基础模版代码

    hadoop概述测试题和基础模版代码 1.Hadoop的创始人是DougCutting?() A.正确 B.错误答对了!正确答案:A解析:参考课程里的文档,这个就不解释了2.下列有关Hadoop的说法 ...

  2. CodeSmith的基础模版类(CodeSmith help中的内容)

    基础模版类类型描述: Batch      OutputFileCodeTemplate  模版通过继承此类能够在生成过程中把他们的输出保存到文件中 ScriptError    在脚本执行中出现一个 ...

  3. tailor multi fragment && cutom-amd script demo 说明

    tailor 官方demo 中提供了一个multi fragment 的demo,这个比较简单,就是使用不同的 后端server 做为fragment ,然后使用 html tag 进行加载就可以了. ...

  4. [Hadoop in Action] 第4章 编写MapReduce基础程序

    基于hadoop的专利数据处理示例 MapReduce程序框架 用于计数统计的MapReduce基础程序 支持用脚本语言编写MapReduce程序的hadoop流式API 用于提升性能的Combine ...

  5. 掌握Thinkphp3.2.0----模版基础

    我们将要学习一下 ThinkPHP 模版,ThinkPHP 内置了一个基于 XML 的性能卓越的模版引擎 ThinkTemplate,使用了动态编译和缓存技术,支持自定义标签库, 其实我还体会不到其中 ...

  6. zabbix 布署实践【7 H3C网络设备监控模版制作思路】

    我们知道,zabbix安装后自带Template OS Linux 模版已满足了绝大部分Linux服务器的基础环境监控,只是我们在其模版上稍微修改,可配合将SWAP监控取消,另存为一个叫OS Linu ...

  7. python2.0_s12_day19_前端模版使用

    Django中引用bootstrap实现在前端可以创建客户信息,可以修改客户信息我们需要设计一个前端用户交互系统.我们在设计之前,讨论一些需求:前端实现:1. 不同角色的用户,看到的东西是不一样的 销 ...

  8. webpy 模版语言

    webpy框架拥有自己的模版语言Templetor Templetor具有Python的语言风格 可以直接嵌入Python代码 $code: videoIn = post.filename and p ...

  9. 在linux上如何通过composer安装yii

      Composer可以理解成一个依赖管理工具 它能解决以下问题 a) 你有一个项目依赖于若干个库. b) 其中一些库依赖于其他库. c) 你声明你所依赖的东西. d) Composer 会找出哪个版 ...

随机推荐

  1. 3.2 C++继承方式

    参考: http://www.weixueyuan.net/view/6359.html  总结: 子类继承父类,继承方式将限制父类的成员属性在子类中的访问权限,子类访问父类的成员,也需要遵循其成员的 ...

  2. 50个常用的Linux命令

    1.tar tar -xvf archive_name.tar  解压文件 tar -cvf archive_name.tar file 把文件file压缩成archive_name.tar tar ...

  3. loadrunner http协议性能测试脚本编写

    性能测试其实测的就是接口的性能,不管是用工具录制还是自己写,都是围绕接口的,录制也是把接口录制下来而已,但是录制下来的脚本比较乱,会把很多相关的请求都录下来. 在这里我们手动写HTTP协议的get.p ...

  4. SQL-10 获取所有非manager的员工emp_no

    题目描述 获取所有非manager的员工emp_noCREATE TABLE `dept_manager` (`dept_no` char(4) NOT NULL,`emp_no` int(11) N ...

  5. redis_key键

    exists k1,判断k1是否存在,‘1’就是存在,‘0’ 就是不存在 move k3 2   --->这里就是说把k3移动到2号库. ‘1’为成功,‘0’为失败 ttl k2  --查看k2 ...

  6. pytest的HTML

    安装html: 1.github上源码地址[https://github.com/pytest-dev/pytest-html] 2.pip安装  pip install pytest-html 3. ...

  7. 编程实现Linux系统的od功能

    选做题目以及分析 题目:编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能 分析:我觉得这道题目中的参数应当是-tx1而不是-tx,使用了-tx后结 ...

  8. L293 给地球降温

    Countries look at ways to tinker with Earth’s thermostat The idea of cooling the climate with strato ...

  9. uniGUI HyperServer

    uniGUI HyperServer 是一种新的服务器体系架构, 旨在高度提高 uniGUI 应用程序的可用性.稳定性和特定的可伸缩性. 这一目标是通过应用业界已知和广泛使用的技术 (如负载平衡和过程 ...

  10. ibatis集成封装之路(to mysql)

    hello <tx:annotation-driven transaction-manager=" "/> 插入记录ID的坑 https://renjieguixion ...