对于需要实现共享的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. 戴尔poweredge r730服务器配置以及系统安装

    第一次给服务器安装的是ubantu系统: 首先我们开机进入小型BIOS设置一下RAID,或者进入服务器管理系统,在系统的BIOS中进行RAID设置: 开机后当看到出现< Ctrl > &l ...

  2. Android : iperf-2.0.4 网络测试工具

    一.源码下载及交叉编译: 下载:https://pan.baidu.com/s/1i6NYDF3   //包含linux和windows上的可执行文件 1. 解压后获得perf-2.0.4源码.2. ...

  3. Docker常用命令学习

    sudo service docker startsudo docker run hello-worlddocker stats --helpdocker run -d -P training/web ...

  4. Github拉取远端的时候提示“ssh: connect to host github.com port 22: Connection timed out”错误

    在使用Github的时候,如果使用到拉取远端分支的时候或者测试ssh -T git@github.com的时候可能会出现连接失败的问题,错误描述为“ssh: connect to host githu ...

  5. CRM工具简介

    pacemaker是高可用集群中的CRM(Cluster Resource Manager)资源管理层,他是一个服务,可以作为一个单独的服务启动,不过在如果使用corosync1.4中,我们可以设置c ...

  6. Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException

    Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException时,请Catch HibernateOptimisticLockingFailur ...

  7. 【Python】基础练习题-1

    #练习1:从键盘输入两个数,并比较其大小,直到输入e/E退出程序 while 1: input_number=raw_inut("please input two numbers,enter ...

  8. 安装Cygwin,,以及遇到的问题

    实验需要用到Cygwin,于是去下了一个,安装过程比较顺利,参考:http://blog.csdn.net/chunleixiahe/article/details/55666792 但是发现  ma ...

  9. 使用Git去管理修改

    Git跟踪的是修改而不是文件本身. 看下面一个例子 首先我们修改我们Git管理的git.txt文件 如下: 然后添加: 然后我们再去修改git.txt这个文件 然后直接提交到分支里如图: 也就是说我们 ...

  10. 服务器安装wordpress,搭建自己的博客平台

    自己构造网站的话,建立一个简单的网页还可以(比如,yongjieshi.com),对于建立复杂的博客就需要借助第三方的工具,常见的有wordpress,在阿里云上安装wordpress,我主要参考了这 ...