<section class="dso-legal-document">
    <h1 class="dso-is-document">Naam van het document</h1>
    <h2 class="dso-is-chapter">Hoofdstuk</h2>
    <article>
        <h1 class="dso-is-article">Artikel</h1>
        <p>Lid</p>
        <p>Ander lid</p>
        <ul>
            <li>item 1</li>
            <li>item 2</li>
        </ul>

    </article>

</section>
{{#dsoLegalDocument legalDocument }}{{/dsoLegalDocument}}
legalDocument:
  - type: documentHeader
    content: Naam van het document
  - type: chapterHeader
    content: Hoofdstuk
  - type: article
    content:
      - type: articleHeader
        content: Artikel
      - type: body
        content: |
          <p>Lid</p>
          <p>Ander lid</p>
          <ul>
            <li>item 1</li>
            <li>item 2</li>
          </ul>
  • Content:
    // Notes:
    // ------
    // * Each change to this file needs a restart of the fractal instance
    // * Exported methods are merged as helpers in fractal.js
    
    module.exports = {
      dsoLegalDocument(legalDocument, options) {
        return `
          <section class="dso-legal-document">
            ${legalDocument.map((d, i, array) => {
              if (isHeader(d.type)) {
                const headerElement = getHeader(d, array);
                const headerClass = getHeadingClass(d.type);
    
                return `<${headerElement} class="${headerClass}">${d.content}</${headerElement}>`;
              }
              else if (isArticle(d.type)) {
                return `
                  <article>
                    ${d.content.map((c, i, array) => {
                      if (isArticleHeader(c.type)) {
                        const articleHeaderElement = getArticleHeader(c, array);
                        const articleHeaderClass = getArticleHeadingClass(c.type);
    
                        return `<${articleHeaderElement} class="${articleHeaderClass}">${c.content}</${articleHeaderElement}>`;
                      }
                      else if (isArticleBody(c.type)) {
                        return c.content;
                      }
                    }).join('')}
                  </article>
                `;
              }
            }).join('')}
          </section>
        `;
      }
    };
    
    function isHeader(type) {
      return type === 'documentHeader' || type === 'chapterHeader' || type === 'titleHeader' || type === 'departmentHeader';
    }
    
    function getHeader(h, array) {
      if (!array.includes(h)) {
        throw new Error('Header does not exist in array');
      }
    
      const headers = array.filter(i => isHeader(i.type));
    
      return `h${headers.indexOf(h) + 1}`;
    }
    
    function getHeadingClass(type) {
      switch (type) {
        case 'documentHeader':
          return 'dso-is-document';
        case 'chapterHeader':
          return 'dso-is-chapter';
        case 'titleHeader':
          return 'dso-is-title';
        case 'departmentHeader':
          return 'dso-is-department';
      }
    }
    
    function isArticle(type) {
      return type === 'article';
    }
    
    function isArticleHeader(type) {
      return type === 'paragraphHeader' || type === 'subparagraphHeader' || type === 'subsubparagraphHeader' || type === 'articleHeader';
    }
    
    function isArticleBody(type) {
      return type === 'body';
    }
    
    function getArticleHeader(h, array) {
      if (!array.includes(h)) {
        throw new Error('Header does not exist in array');
      }
    
      const articleHeaders = array.filter(i => isArticleHeader(i.type));
    
      return `h${articleHeaders.indexOf(h) + 1}`;
    }
    
    function getArticleHeadingClass(type) {
      switch (type) {
        case 'paragraphHeader':
          return 'dso-is-paragraph';
        case 'subparagraphHeader':
          return 'dso-is-subparagraph';
        case 'subsubparagraphHeader':
          return 'dso-is-subsubparagraph';
        case 'articleHeader':
          return 'dso-is-article';
      }
    }
    
  • URL: /components/raw/legal-document/legal-document.js
  • Filesystem Path: components/02-content/legal-document/legal-document.js
  • Size: 2.8 KB

There are no notes for this item.