Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. ## 1. Install Dust.js dependency
  2.  
  3. Web 3.0 supports multiple template engines. As a consequence, Dust.js is now decoupled from core and needs to be included as a dependency on projects that want to use it.
  4.  
  5. ```
  6. npm install @dadi/web-dustjs --save
  7. ```
  8.  
  9. ## 2. Change bootstrap script
  10.  
  11. The bootstrap script (which you may be calling `index.js`, `main.js` or `server.js`) now needs to inform Web of the engines it has available and which npm modules implement them.
  12.  
  13. ```js
  14. require('@dadi/web')({
  15. engines: [
  16. require('@dadi/web-dustjs')
  17. ]
  18. })
  19. ```
  20.  
  21. ## 3. Update config
  22.  
  23. The `dust` config block has been moved inside a generic `engines` block.
  24.  
  25. *Before:*
  26.  
  27. ```
  28. "dust": {
  29. "cache": true,
  30. "debug": true,
  31. "debugLevel": "DEBUG",
  32. "whitespace": true,
  33. "paths": {
  34. "helpers": "workspace/utils/helpers"
  35. }
  36. }
  37. ```
  38.  
  39. *After:*
  40.  
  41. ```
  42. "engines": {
  43. "dust": {
  44. "cache": true,
  45. "debug": true,
  46. "debugLevel": "DEBUG",
  47. "whitespace": true,
  48. "paths": {
  49. "helpers": "workspace/utils/helpers"
  50. }
  51. }
  52. }
  53. ```
  54.  
  55. ## 4. Move partials directory
  56.  
  57. Before Web 3.0, Dust templates were separated between the `pages` and `partials` directories, with the former being used for templates that generate a page (i.e. have a route) and the latter being used for partials/includes.
  58.  
  59. In Web 3.0, all templates live under the same directory (`pages`). The distinction between a page and a partial is made purely by whether or not the template has an accompanying JSON schema file.
  60.  
  61. Also, pages and partials can now be located in sub-directories, nested as deeply as possible.
  62.  
  63. To migrate an existing project, all you need to do is move the `partials` directory inside `pages` and everything will work as expected.
  64.  
  65. *Before:*
  66.  
  67. ```
  68. workspace
  69. |_ pages
  70. |_ partials
  71. ```
  72.  
  73. *After:*
  74. ```
  75. workspace
  76. |_ pages
  77.  |_ partials
  78. ```
  79.  
  80. ```
  81. mv workspace/partials workspace/pages
  82. ```
  83.  
  84. ## 5. Update Dust helpers
  85.  
  86. If your project is using custom helpers, you might need to change the way they access the Dust engine. You should now access the module directly, rather than reference the one from Web.
  87.  
  88. ```js
  89. // Before
  90. var dust = require('@dadi/web').Dust
  91. require('@dadi/dustjs-helpers')(dust.getEngine())
  92.  
  93. // After
  94. var dust = require('dustjs-linkedin')
  95. require('@dadi/dustjs-helpers')(dust)
  96. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement