001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.html5;
018
019import org.apache.juneau.marshall.*;
020
021/**
022 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/scripting-1.html#the-template-element">&lt;template&gt;</a>
023 * element.
024 *
025 * <p>
026 * The template element represents a template for a fragment of HTML that can be cloned and
027 * inserted into the document by script. It is used to define reusable HTML content that
028 * can be instantiated multiple times using JavaScript. The template element is not rendered
029 * in the document until its content is cloned and inserted into the DOM. It is commonly
030 * used for creating dynamic content, such as repeating elements in lists or generating
031 * content based on data.
032 *
033 * <h5 class='section'>Examples:</h5>
034 * <p class='bcode w800'>
035 *    <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*;
036 *
037 *    <jc>// Simple template</jc>
038 *    Template <jv>simple</jv> = <jsm>template</jsm>(
039 *       <jsm>p</jsm>(<js>"This is a template paragraph."</js>)
040 *    );
041 *
042 *    <jc>// Template with styling</jc>
043 *    Template <jv>styled</jv> = <jsm>template</jsm>(
044 *       <jsm>div</jsm>(
045 *          <jsm>h3</jsm>(<js>"Item Title"</js>),
046 *          <jsm>p</jsm>(<js>"Item description"</js>)
047 *       ).class_(<js>"item"</js>)
048 *    ).class_(<js>"item-template"</js>);
049 *
050 *    <jc>// Template with complex content</jc>
051 *    Template <jv>complex</jv> = <jsm>template</jsm>(
052 *       <jsm>article</jsm>(
053 *          <jsm>header</jsm>(
054 *             <jsm>h2</jsm>(<js>"Article Title"</js>),
055 *             <jsm>p</jsm>(<js>"Article subtitle"</js>)
056 *          ),
057 *          <jsm>p</jsm>(<js>"Article content goes here."</js>),
058 *          <jsm>footer</jsm>(<js>"Article footer"</js>)
059 *             )
060 *       );
061 *
062 *    // Template with ID
063 *    Template withId = template()
064 *       .id("user-card-template")
065 *       .children(
066 *          div().class_("user-card")
067 *             .children(
068 *                img().src("/avatar.jpg").alt("User Avatar"),
069 *                h3().children("User Name"),
070 *                p().children("User Bio")
071 *             )
072 *       );
073 *
074 *    // Template with styling
075 *    Template styled2 = template()
076 *       .style("display: none;")
077 *       .children(
078 *          div().class_("modal")
079 *             .children(
080 *                h2().children("Modal Title"),
081 *                p().children("Modal content")
082 *             )
083 *       );
084 *
085 *    // Template with multiple elements
086 *    Template multiple = template()
087 *       .children(
088 *          div().class_("product-card")
089 *             .children(
090 *                img().src("/product.jpg").alt("Product Image"),
091 *                h3().children("Product Name"),
092 *                p().children("Product Description"),
093 *                span().class_("price").children("$99.99"),
094 *                button().children("Add to Cart")
095 *             )
096 *       );
097 *
098 *    // Template with form
099 *    Template withForm = template()
100 *       .children(
101 *          form().class_("comment-form")
102 *             .children(
103 *                textarea().placeholder("Enter your comment"),
104 *                button().type("submit").children("Submit Comment")
105 *             )
106 *       );
107 * </p>
108 *
109 * <p>
110 * The following convenience methods are provided for constructing instances of this bean:
111 * <ul class='javatree'>
112 *    <li class='jc'>{@link HtmlBuilder}
113 *    <ul class='javatree'>
114 *       <li class='jm'>{@link HtmlBuilder#template() template()}
115 *       <li class='jm'>{@link HtmlBuilder#template(String, Object...) template(String, Object...)}
116 *    </ul>
117 * </ul>
118 * </p>
119 *
120 * <h5 class='section'>See Also:</h5><ul>
121 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
122 * </ul>
123 */
124@Marshalled(typeName = "template")
125public class Template extends HtmlElementMixed<Template> {
126
127   /**
128    * Creates an empty {@link Template} element.
129    */
130   public Template() {}
131
132   /**
133    * Creates a {@link Template} element with the specified {@link Template#id(String)} attribute and child nodes.
134    *
135    * @param id The {@link Template#id(String)} attribute. Can be <jk>null</jk> to unset the attribute.
136    * @param children The child nodes. Must not be <jk>null</jk>.
137    */
138   public Template(String id, Object...children) {
139      id(id).children(children);
140   }
141}