github.com/golazy/golazy@v0.0.7-0.20221012133820-968fe65a0b65/lazyview/nodes/README.md (about)

     1  # nodes
     2  
     3  Package nodes provides data structures to represents Html ElementNodes,
     4  TextNodes and Attributes.
     5  
     6  You are free to use this package, but is probably more comfortable to use the
     7  html package, that already have html elements and common attributes.
     8  
     9  ## Variables
    10  
    11  ```golang
    12  var Beautify = true
    13  ```
    14  
    15  ## Types
    16  
    17  ### type [Attr](/attr.go#L10)
    18  
    19  `type Attr struct { ... }`
    20  
    21  Attr holds information about an attribute for an Element Node
    22  
    23  #### func [NewAttr](/attr.go#L17)
    24  
    25  `func NewAttr(key string, value ...string) Attr`
    26  
    27  NewAttr creates a new attribute.
    28  If several arguments are given, they are join by a space
    29  
    30  #### func (Attr) [String](/attr.go#L66)
    31  
    32  `func (a Attr) String() string`
    33  
    34  #### func (Attr) [WriteTo](/attr.go#L26)
    35  
    36  `func (a Attr) WriteTo(w io.Writer) (n int64, err error)`
    37  
    38  WriteTo writes the current string to the writer w
    39  
    40  ### type [ContentNode](/content_node.go#L5)
    41  
    42  `type ContentNode []io.WriterTo`
    43  
    44  #### func (ContentNode) [WriteTo](/content_node.go#L7)
    45  
    46  `func (c ContentNode) WriteTo(w io.Writer) (n64 int64, err error)`
    47  
    48  ### type [Element](/element.go#L13)
    49  
    50  `type Element struct { ... }`
    51  
    52  #### func [NewElement](/element.go#L289)
    53  
    54  `func NewElement(tagname string, options ...interface{ ... }) Element`
    55  
    56  NewElement creates a new element with the provided tagname and the provided options
    57  The options can be:
    58  
    59  * An Attr that will be render
    60  * A string or Text
    61  * Another Element
    62  * Any WriterTo interface
    63  Attributes are output in order
    64  The rest is output in the same order as received
    65  
    66  ```golang
    67  Beautify = false
    68  content := NewElement("html", NewAttr("lang", "en"),
    69      NewElement("head",
    70          NewElement("title", "Mi pagina")),
    71      NewElement("body",
    72          NewElement("h1", "This is my page")),
    73  )
    74  
    75  content.WriteTo(os.Stdout)
    76  ```
    77  
    78   Output:
    79  
    80  ```
    81  <!DOCTYPE html><html lang=en><head><title>Mi pagina</title><body><h1>This is my page</h1>
    82  ```
    83  
    84  #### func (Element) [String](/element.go#L274)
    85  
    86  `func (r Element) String() string`
    87  
    88  #### func (Element) [WriteTo](/element.go#L226)
    89  
    90  `func (r Element) WriteTo(w io.Writer) (n64 int64, err error)`
    91  
    92  WriteTo writes the current string to the writer w
    93  
    94  ### type [Raw](/text.go#L10)
    95  
    96  `type Raw string`
    97  
    98  #### func (Raw) [WriteTo](/text.go#L13)
    99  
   100  `func (t Raw) WriteTo(w io.Writer) (int64, error)`
   101  
   102  WriteTo writes the current string to the writer w without any escape
   103  
   104  ### type [Text](/text.go#L9)
   105  
   106  `type Text string`
   107  
   108  Text represents a TextNode
   109  
   110  #### func (Text) [WriteTo](/text.go#L19)
   111  
   112  `func (t Text) WriteTo(w io.Writer) (int64, error)`
   113  
   114  WriteTo writes the current string to the writer w while escapeing html with [https://godocs.io/html#EscapeString](https://godocs.io/html#EscapeString)
   115  
   116  ---
   117  Readme created from Go doc with [goreadme](https://github.com/posener/goreadme)