Skip to content

Commit dde0799

Browse files
committed
add embedded js templating
1 parent 8f526a1 commit dde0799

File tree

9 files changed

+75
-25
lines changed

9 files changed

+75
-25
lines changed

.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
preview.png
2+
.gitignore
3+
.*.swp
4+
._*
5+
.DS_Store
6+
.git
7+
.hg
8+
.npmrc
9+
.lock-wscript
10+
.svn
11+
.wafpickle-*
12+
config.gypi
13+
CVS
14+
npm-debug.log

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11

22
<div align="center">
33
<h1> Terminull </h1>
4-
<p>Terminull is a gitbook plugin allows you to create a modern terminal for your gitbook pages in order to documente your commands and it gives you a fast way to copy the command .</p>
4+
<p>Terminull is a <a href="https://www.npmjs.com/package/gitbook">gitbook</a> plugin allows you to create a modern terminal for your gitbook pages in order to documente your commands and it gives you a fast way to copy the command .</p>
55
<br>
66
<br>
7-
<a href="https://www.npmjs.com/package/gitbook-plugin-terminull"><img src="https://badge.fury.io/js/1.0.3.svg" alt="npm version" height="18"></a>
7+
<a href="https://www.npmjs.com/package/gitbook-plugin-terminull"><img src="https://img.shields.io/npm/v/gitbook-plugin-terminull/latest?color=green" alt="npm version"></a>
88
<br>
99
<br>
10-
<img src="./resources/terminull.png">
10+
<img src="https://raw.githubusercontent.com/ridaeh/gitbook-plugin-terminull/master/preview.png">
1111
</div>
1212

13-
1413
## How to use it?
1514
To use Terminull plugin in your Gitbook project, add the terminull plugin to the `book.json` file of your project, then install plugins using `gitbook install`.
1615

@@ -30,10 +29,13 @@ First, you need to create a terminal. Each terminal should have a directory wher
3029
~/gitbook-plugin-terminull
3130
{% command %}
3231
echo "Hello terminull"
32+
{% comment %}
33+
This will print 'Hello terminull' in the screen
3334
{% output %}
3435
Hello terminull
3536
{% endterm %}
3637
```
38+
3739
## You like my work :exclamation:
3840
In case you were wondering how you can thanks me for my work, coffee :coffee: is the way to my heart.
3941

@@ -42,4 +44,10 @@ In case you were wondering how you can thanks me for my work, coffee :coffee: is
4244

4345

4446
## Contributing
45-
Bug reports and pull requests are welcome.
47+
Bug reports and pull requests are welcome.
48+
49+
1. Fork it!
50+
2. Create your feature branch: git checkout -b my-new-feature
51+
3. Commit your changes: git commit -am 'Add some feature'
52+
4. Push to the branch: git push origin my-new-feature
53+
5. Submit a pull request :smile:

assets/terminull.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
.terminullComment {
2828
color: seagreen;
29-
font-weight: bold;
3029
font-style: italic;
3130
}
3231

@@ -63,3 +62,6 @@
6362
.terminullOutput {
6463
display: block;
6564
}
65+
66+
.terminullCopyBtn { transition: all .2s ease-in-out; }
67+
.terminullCopyBtn:hover { transform: scale(1.1); }

assets/terminull.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
function copyCommandTerminull(command) {
2-
console.log('clicked',command)
32
var dummy = document.createElement("textarea");
43
document.body.appendChild(dummy);
54
dummy.value=command;

index.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
var ejs = require('ejs');
2+
const path = require('path');
3+
14
function processBlock(rootBlock) {
2-
var term = {};
3-
var blocks = [rootBlock].concat(rootBlock.blocks);
4-
blocks.forEach(_blk => {
5+
var terminulls = [];
6+
var term = {}
7+
rootBlock.blocks.forEach(_blk => {
8+
if(term[_blk.name]){
9+
terminulls.push(term)
10+
term = {}
11+
}
512
term[_blk.name] = _blk.body.trim();
613
});
7-
return '<div class="terminull">' +
8-
'<div class="terminullMenu">' +
9-
'<div class="terminullButtons terminullClose"></div>' +
10-
'<div class="terminullButtons terminullMinimize"></div>' +
11-
'<div class="terminullButtons terminullZoom"></div>' +
12-
'</div>' +
13-
'<div class="terminullScreen">' +
14-
'<span class="terminullDirectory">~/' + term.directory + '</span>$ ' +
15-
'<span class="terminullCommand">' + term.command + '</span>' +
16-
'<span class="terminullOutput">' + term.output + '</span>' +
17-
'</div>'+
18-
'</div>';
14+
terminulls.push(term)
15+
return new Promise(function(resolve, reject){
16+
ejs.renderFile(path.join(__dirname, './src/terminull.html.ejs'),{terminulls:terminulls},function(err, str){
17+
if(err) {
18+
throw err
19+
}
20+
resolve(str)
21+
})
22+
})
1923
}
2024

2125
module.exports = {
@@ -26,7 +30,7 @@ module.exports = {
2630
},
2731
blocks: {
2832
term: {
29-
blocks: ['directory', 'command', 'output'],
33+
blocks: ['directory', 'command','comment', 'output'],
3034
process: processBlock
3135
}
3236
}

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
},
1010
"keywords": [
1111
"terminal",
12-
"gitbook"
12+
"gitbook",
13+
"gitbook-plugin",
14+
"plugin"
1315
],
1416
"author": "Ridae HAMDANI",
1517
"license": "ISC",
1618
"bugs": {
1719
"url": "https://github.com/ridaeh/gitbook-plugin-terminull/issues"
1820
},
19-
"homepage": "https://github.com/ridaeh/gitbook-plugin-terminull#readme",
21+
"homepage": "https://github.com/ridaeh/gitbook-plugin-terminull",
2022
"engines": {
2123
"gitbook": ">2.5.0"
24+
},
25+
"dependencies": {
26+
"ejs": "^3.0.1"
2227
}
2328
}

preview.png

19.6 KB
Loading

resources/terminull.png

-11.4 KB
Binary file not shown.

src/terminull.html.ejs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="terminull">
2+
<div class="terminullMenu">
3+
<div class="terminullButtons terminullClose"></div>
4+
<div class="terminullButtons terminullMinimize"></div>
5+
<div class="terminullButtons terminullZoom"></div>
6+
</div>
7+
<div class="terminullScreen">
8+
<% terminulls.forEach(function(terminull){ %>
9+
<span class="terminullDirectory">~/<%= terminull.directory %></span>$
10+
<span class="terminullCommand"><%= terminull.command%></span>
11+
<% if (terminull.comment) { %>
12+
<span class="terminullComment"># <%= terminull.comment%></span>
13+
<% } %>
14+
<i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`<%= terminull.command%>`)"></i>
15+
<span class="terminullOutput"><%= terminull.output%></span>
16+
<% }); %>
17+
</div>
18+
</div>

0 commit comments

Comments
 (0)