loading
open in
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Handlebars = require('handlebars');

var source = `

{{test node}}

`;

Handlebars.registerHelper('test', function(data) {

  var str ;
  var array = ["layer one","layer two","layer three"] ;
  for (var i = 0; i < data.length; i++ ) {
    
    str += `
    <div class="${array[i%array.length]}">
      <h2>${data[i]["term"]}</h2>
      <p>${data[i]["meaning"]}</p>
    </div>
    `;

  };

  return new Handlebars.SafeString (str);
});

var template = Handlebars.compile(source);

var data = {
  
  node: [
    
{ term: "evasiveness", meaning: "ごまかし" } ,
{ term: "no way ", meaning: "とんでもない!" } ,
{ term: "at least", meaning: "少なくとも" } ,
{ term: "fuss", meaning: "散らかった" } ,
{ term: "nuisance", meaning: "迷惑" } ,
{ term: "no longer ", meaning: "もはや" } ,
{ term: "calm down", meaning: "落ち着く" } ,
{ term: "stuffy", meaning: "ぬるい" } ,
{ term: "circumstances", meaning: "状況" } ,
{ term: "duties", meaning: "職務" } ,
{ term: "certain", meaning: "確信して" } ,
{ term: "good grief.", meaning: "なんて悲しいんだ。" } ,
{ term: "a whole lot", meaning: "たくさん" } ,
{ term: "twisted ", meaning: "ねじれた" } ,
{ term: "slut", meaning: "ビッチ女" } ,
{ term: "no surprise", meaning: "驚かない" } ,
{ term: "It has to be", meaning: "それはそうなるべき" } ,
{ term: "head back", meaning: "引き返す" } ,
{ term: "in just a bit", meaning: "ほんの少し" } ,
{ term: "clingy", meaning: "ぎこちない" } ,
{ term: "ever since ", meaning: "それ以来" } ,
{ term: "cling", meaning: "しがみつく" } ,
{ term: "reckless", meaning: "無謀" } ,
{ term: "urged", meaning: "促された" } ,
{ term: "intruding", meaning: "侵入する" } ,
{ term: "drooling", meaning: "落ちる" } ,
{ term: "insult", meaning: "侮辱" } ,
{ term: "cruel", meaning: "残酷な" } ,
{ term: "disturb", meaning: "妨害する" } ,
{ term: "I'm certain", meaning: "確信しています" } ,
    
  ] ,

};

var result = template(data);

console.log(result) ;

const fs = require('fs');
fs.writeFile("./tmp.txt", result , function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("OK: Text was saved to ./tmp.txt.");
}); 
node v10.15.2 linux/amd64