dna-engine

An uncomplicated user interface library for cloning semantic templates (written in TypeScript)

Fork me on GitHub

Hello World Bookstore Example

The code below is a bare bones, standalone web page with the all CSS and JavaScript (including loading jQuery and dna-engine) to demonstrate dna-engine in action.

Each call to dna.clone() creates a new element from the book template and appends the element to the books element.

Bookstore Code

bookstore.html

            <!doctype html>
            <!-- - - - - - -->
            <!-- Bookstore -->
            <!-- - - - - - -->
            <html>
            <head>
               <meta charset=utf-8>
               <title>Bookstore</title>
               <link rel=stylesheet href=https://cdn.jsdelivr.net/npm/dna-engine@2.2/dist/dna-engine.css>
               <style>
                  body     { font-family: system-ui, sans-serif; margin: 30px; }
                  .books   { width: 250px; }
                  .book    { background-color: gold; padding: 10px; margin-bottom: 15px; }
                  .book h2 { font-size: 1.1rem; margin: 0px; }
               </style>
               <script defer src=https://cdn.jsdelivr.net/npm/jquery@3.6/dist/jquery.min.js></script>
               <script defer src=https://cdn.jsdelivr.net/npm/dna-engine@2.2/dist/dna-engine.min.js></script>
               <script data-on-load=startup>
                  const books = [
                     { title: 'The DOM',      author: 'Jan' },
                     { title: 'Howdy HTML5',  author: 'Ed' },
                     { title: 'Styling CSS3', author: 'Abby' }
                     ];
                  const startup = () => dna.clone('book', books);
               </script>
            </head>
            <body>

            <main>
               <h1>Bookstore</h1>
               <section class=books>
                  <div id=book class=dna-template>
                     <h2>~~title~~</h2>
                     Author: <cite>~~author~~</cite>
                  </div>
               </section>
            </main>

            </body>
            </html>
         

Bookstore Web Page

screenshot

Bookstore on jsFiddle

Experiment with the code at:

Questions and comments

Tweet your question or comment with or submit an issue on GitHub.