partials.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. overview: |
  2. Partial tags are used to expand an external template into the current
  3. template.
  4. The tag's content MUST be a non-whitespace character sequence NOT containing
  5. the current closing delimiter.
  6. This tag's content names the partial to inject. Set Delimiter tags MUST NOT
  7. affect the parsing of a partial. The partial MUST be rendered against the
  8. context stack local to the tag. If the named partial cannot be found, the
  9. empty string SHOULD be used instead, as in interpolations.
  10. Partial tags SHOULD be treated as standalone when appropriate. If this tag
  11. is used standalone, any whitespace preceding the tag should treated as
  12. indentation, and prepended to each line of the partial before rendering.
  13. tests:
  14. - name: Basic Behavior
  15. desc: The greater-than operator should expand to the named partial.
  16. data: { }
  17. template: '"{{>text}}"'
  18. partials: { text: 'from partial' }
  19. expected: '"from partial"'
  20. - name: Failed Lookup
  21. desc: The empty string should be used when the named partial is not found.
  22. data: { }
  23. template: '"{{>text}}"'
  24. partials: { }
  25. expected: '""'
  26. - name: Context
  27. desc: The greater-than operator should operate within the current context.
  28. data: { text: 'content' }
  29. template: '"{{>partial}}"'
  30. partials: { partial: '*{{text}}*' }
  31. expected: '"*content*"'
  32. - name: Recursion
  33. desc: The greater-than operator should properly recurse.
  34. data: { content: "X", nodes: [ { content: "Y", nodes: [] } ] }
  35. template: '{{>node}}'
  36. partials: { node: '{{content}}<{{#nodes}}{{>node}}{{/nodes}}>' }
  37. expected: 'X<Y<>>'
  38. # Whitespace Sensitivity
  39. - name: Surrounding Whitespace
  40. desc: The greater-than operator should not alter surrounding whitespace.
  41. data: { }
  42. template: '| {{>partial}} |'
  43. partials: { partial: "\t|\t" }
  44. expected: "| \t|\t |"
  45. - name: Inline Indentation
  46. desc: Whitespace should be left untouched.
  47. data: { data: '|' }
  48. template: " {{data}} {{> partial}}\n"
  49. partials: { partial: ">\n>" }
  50. expected: " | >\n>\n"
  51. - name: Standalone Line Endings
  52. desc: '"\r\n" should be considered a newline for standalone tags.'
  53. data: { }
  54. template: "|\r\n{{>partial}}\r\n|"
  55. partials: { partial: ">" }
  56. expected: "|\r\n>|"
  57. - name: Standalone Without Previous Line
  58. desc: Standalone tags should not require a newline to precede them.
  59. data: { }
  60. template: " {{>partial}}\n>"
  61. partials: { partial: ">\n>"}
  62. expected: " >\n >>"
  63. - name: Standalone Without Newline
  64. desc: Standalone tags should not require a newline to follow them.
  65. data: { }
  66. template: ">\n {{>partial}}"
  67. partials: { partial: ">\n>" }
  68. expected: ">\n >\n >"
  69. - name: Standalone Indentation
  70. desc: Each line of the partial should be indented before rendering.
  71. data: { content: "<\n->" }
  72. template: |
  73. \
  74. {{>partial}}
  75. /
  76. partials:
  77. partial: |
  78. |
  79. {{{content}}}
  80. |
  81. expected: |
  82. \
  83. |
  84. <
  85. ->
  86. |
  87. /
  88. # Whitespace Insensitivity
  89. - name: Padding Whitespace
  90. desc: Superfluous in-tag whitespace should be ignored.
  91. data: { boolean: true }
  92. template: "|{{> partial }}|"
  93. partials: { partial: "[]" }
  94. expected: '|[]|'