Skip to content

Commit 2db332e

Browse files
✅ Added EJS Codelab templates (#941)
1 parent 206674a commit 2db332e

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<html>
2+
<head>
3+
<meta
4+
name="viewport"
5+
content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"
6+
/>
7+
<meta name="theme-color" content="#4F7DC9" />
8+
<meta charset="UTF-8" />
9+
<title><%= node.getDocument().getTitle()%></title>
10+
<link
11+
rel="stylesheet"
12+
href="//fonts.googleapis.com/css?family=Source+Code+Pro:400|Roboto:400,300,400italic,500,700|Roboto+Mono"
13+
/>
14+
<link
15+
rel="stylesheet"
16+
href="//fonts.googleapis.com/icon?family=Material+Icons"
17+
/>
18+
<link
19+
rel="stylesheet"
20+
href="https://storage.googleapis.com/codelab-elements/codelab-elements.css"
21+
/>
22+
<style>
23+
.success {
24+
color: #1e8e3e;
25+
}
26+
.error {
27+
color: red;
28+
}
29+
</style>
30+
</head>
31+
<body>
32+
<google-codelab
33+
codelab-gaid=""
34+
id="<%= node.getDocument().hasAttribute('id') ? node.getDocument().getAttribute('id'):Math.floor(Math.random() * 1000000)%>"
35+
environment="web"
36+
feedback-link="<%=node.getDocument().getAttribute('feedback-link')%>"
37+
title="<%=node.getDocument().getTitle() %>"
38+
>
39+
<%- node.getContent() %>
40+
</google-codelab>
41+
<script src="https://storage.googleapis.com/codelab-elements/native-shim.js"></script>
42+
<script src="https://storage.googleapis.com/codelab-elements/custom-elements.min.js"></script>
43+
<script src="https://storage.googleapis.com/codelab-elements/prettify.js"></script>
44+
<script src="https://storage.googleapis.com/codelab-elements/codelab-elements.js"></script>
45+
</body>
46+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports.attributeIfSet = (attName, attValue) => {
2+
if (attName && attValue !== undefined && attValue.trim().length > 0) {
3+
return attName.trim() + '="' + attValue.trim() + '"'
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<google-codelab-step label="Overview">
2+
<%- node.getContent() %>
3+
</google-codelab-step>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<% if (node.getLevel() === 1) { %>
2+
<google-codelab-step
3+
label="<%= node.getTitle() %>"
4+
<%- helpers.attributeIfSet('duration', node.getAttribute('duration')) %>
5+
>
6+
<%- node.getContent() %>
7+
</google-codelab-step>
8+
<% } else { %>
9+
<section>
10+
<h<%= node.getLevel() %>><%- node.getTitle() %></h<%= node.getLevel() %>>
11+
<%- node.getContent() %>
12+
</section>
13+
<% } %>

packages/core/spec/node/asciidoctor.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,31 @@ In other words, it’s about discovering writing zen.`
25292529
const result = asciidoctor.convert('content', options)
25302530
expect(result).to.contain('<p class="paragraph-ejs">content</p>')
25312531
}).timeout(5000)
2532+
describe('Using EJS Codelab templates', () => {
2533+
it('should render a Codelab HTML instance', () => {
2534+
const options = { safe: 'safe', standalone: 'true', backend: 'html5', template_dir: 'spec/fixtures/templates/ejs-codelabs' }
2535+
const content = `
2536+
= Codelab Test
2537+
:id: my-id
2538+
:feedback-link: http://my-feedback.org
2539+
2540+
This is a preamble
2541+
2542+
[duration=5]
2543+
== Step 1
2544+
`
2545+
const result = asciidoctor.convert(content, options)
2546+
expect(result).to.contain('<google-codelab')
2547+
expect(result).to.contain('title="Codelab Test"')
2548+
// Feedback and ID set
2549+
expect(result).to.contain('id="my-id"')
2550+
expect(result).to.contain('feedback-link="http://my-feedback.org"')
2551+
// Preamble becomes overview
2552+
expect(result).to.contain('label="Overview"')
2553+
expect(result).to.contain('label="Step 1"')
2554+
expect(result).to.contain('duration="5"')
2555+
}).timeout(5000)
2556+
})
25322557
it('should use a Handlebars template', () => {
25332558
const options = { safe: 'safe', backend: 'html5', template_dir: 'spec/fixtures/templates/handlebars' }
25342559
const result = asciidoctor.convert('content', options)

0 commit comments

Comments
 (0)