You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
2.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # Konstrui [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucode/konstrui)](https://goreportcard.com/report/github.com/arnaucode/konstrui)
  2. web templating engine for static websites, written in Go lang
  3. ![konstrui](https://raw.githubusercontent.com/arnaucode/konstrui/master/media/konstrui.png "konstrui")
  4. ## Example
  5. #### See the full example on https://github.com/arnaucode/konstrui/tree/master/example
  6. - Simple project structure example:
  7. ```
  8. webInput/
  9. konstruiConfig.json
  10. index.html
  11. templates/
  12. userTemplate.html
  13. userTemplate.json
  14. ```
  15. - Set the html file:
  16. ```html
  17. <!DOCTYPE html>
  18. <html>
  19. <body>
  20. <h1>My First Heading</h1>
  21. <p>My first paragraph.</p>
  22. <konstrui-template html="templates/userTemplate.html" data="templates/userTemplate.json"></konstrui-template>
  23. </body>
  24. </html>
  25. ```
  26. - Set the template file:
  27. ```html
  28. <div class="class1" id="user[[i]]">
  29. <div id="username[[i]]" class="class2">{{username}}</div>
  30. <div id="description[[i]]" class="class2">{{description}}</div>
  31. <div class="class2">{{phone}}</div>
  32. </div>
  33. ```
  34. - Set the template data file:
  35. ```json
  36. [{
  37. "username": "Michaela Doe",
  38. "description": "Hi, I'm here to code",
  39. "phone": "456456456"
  40. },
  41. {
  42. "username": "John Doe",
  43. "description": "Hi, I'm here",
  44. "phone": "123456789"
  45. },
  46. {
  47. "username": "Myself",
  48. "description": "How are you",
  49. "phone": "no phone"
  50. }
  51. ]
  52. ```
  53. - Set the configuration file konstruiConfig.json in the webInput directory:
  54. ```json
  55. {
  56. "title": "Web example",
  57. "author": "arnaucode",
  58. "github": "github.com/arnaucode",
  59. "website": "arnaucode.com",
  60. "files": [
  61. "index.html",
  62. "projects.html",
  63. "app.css"
  64. ]
  65. }
  66. ```
  67. - Execute konstrui
  68. ```
  69. ./konstrui
  70. ```
  71. - Output:
  72. ```html
  73. <!DOCTYPE html>
  74. <html>
  75. <body>
  76. <h1>Heading</h1>
  77. <p>Paragraph.</p>
  78. <div class="class1" id="user0">
  79. <div id="username0" class="class2">Michaela Doe</div>
  80. <div id="description0" class="class2">Hi, I'm here to code</div>
  81. <div class="class2">456456456</div>
  82. </div>
  83. <div class="class1" id="user1">
  84. <div id="username1" class="class2">John Doe</div>
  85. <div id="description1" class="class2">Hi, I'm here</div>
  86. <div class="class2">123456789</div>
  87. </div>
  88. <div class="class1" id="user2">
  89. <div id="username2" class="class2">Myself</div>
  90. <div id="description2" class="class2">How are you</div>
  91. <div class="class2">no phone</div>
  92. </div>
  93. </body>
  94. </html>
  95. ```
  96. ## Features
  97. Import templates
  98. ```html
  99. <konstrui-template html="template.html" data="template.json"></konstrui-template>
  100. ```
  101. Load values:
  102. ```html
  103. {{username}}
  104. ```
  105. Number of iterations:
  106. ```html
  107. User [[i]]
  108. ```
  109. Subobjects:
  110. ```html
  111. <p konstrui-repeat="users">
  112. {{user.username}}
  113. </p>
  114. ```