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

     1  # document
     2  
     3  package document provides helpers to generate an html document
     4  
     5  ## Variables
     6  
     7  ```golang
     8  var BasicLayout = &Document{
     9      Lang:     "en",
    10      Title:    "lazyview",
    11      Viewport: "width=device-width",
    12      Styles:   []string{SimpleCSS(), PageStyle()},
    13      Head: []interface{}{
    14          Script(Async(), Src("https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js"), Crossorigin(("anonymous"))),
    15          Script(Type("module"),
    16              nodes.Raw(`import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';`),
    17          ),
    18      },
    19      LayoutBody: LayoutBody,
    20  }
    21  ```
    22  
    23  ```golang
    24  var DefaultLayout = &Document{}
    25  ```
    26  
    27  ## Functions
    28  
    29  ### func [AddComponent](/document.go#L28)
    30  
    31  `func AddComponent(c Component)`
    32  
    33  ### func [Layout](/document.go#L24)
    34  
    35  `func Layout(content ...interface{}) io.WriterTo`
    36  
    37  ```golang
    38  nodes.Beautify = true
    39  defer (func() {
    40      nodes.Beautify = false
    41  })()
    42  
    43  template := &Document{}
    44  
    45  template.With("hola mundo").WriteTo(os.Stdout)
    46  ```
    47  
    48   Output:
    49  
    50  ```
    51  <html>
    52  <head>
    53  </head>
    54  <body>
    55  hola mundo</body>
    56  </html>
    57  ```
    58  
    59  ### Complete
    60  
    61  ```golang
    62  nodes.Beautify = true
    63  defer (func() {
    64      nodes.Beautify = false
    65  })()
    66  
    67  template := &Document{
    68      Lang:     "en",
    69      Title:    "lazyview",
    70      Viewport: "width=device-width",
    71      Styles:   []string{"body{margin:0;padding:0;box-sizing: border-box;}"},
    72      Head: []interface{}{
    73          Script(Async(), Src("https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js"), Crossorigin(("anonymous"))),
    74          Script(Type("module"),
    75              nodes.Raw(`import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';`),
    76          ),
    77      },
    78      Scripts: []string{
    79          `document.write("hello");`,
    80      },
    81      LayoutBody: func(l *Document, content ...interface{}) io.WriterTo {
    82          return Body(Main(content...))
    83      },
    84  }
    85  
    86  template.With("hello").WriteTo(os.Stdout)
    87  ```
    88  
    89   Output:
    90  
    91  ```
    92  <html lang="en">
    93  <head>
    94  <title>lazyview</title>
    95  <meta name="viewport" content="width=device-width"/>
    96  <style>body{margin:0;padding:0;box-sizing: border-box;}</style>
    97  <script>document.write("hello");</script>
    98  <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js" crossorigin="anonymous"/>
    99  <script type="module">import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';</script>
   100  </head>
   101  <body>
   102  <main>hello</main>
   103  </body>
   104  </html>
   105  ```
   106  
   107  ### func [LayoutBody](/document.go#L95)
   108  
   109  `func LayoutBody(l *Document, content ...interface{}) io.WriterTo`
   110  
   111  ### func [PageStyle](/document.go#L110)
   112  
   113  `func PageStyle() string`
   114  
   115  ### func [SimpleCSS](/document.go#L177)
   116  
   117  `func SimpleCSS() string`
   118  
   119  ## Types
   120  
   121  ### type [Component](/component.go#L3)
   122  
   123  `type Component struct { ... }`
   124  
   125  ```golang
   126  nodes.Beautify = true
   127  defer (func() {
   128      nodes.Beautify = false
   129  })()
   130  
   131  template := &Document{}
   132  template.AddComponent(Component{
   133      Scripts: []string{`document.Write("hello world");`},
   134      Styles:  []string{`body{background: red;}`},
   135      Head: []interface{}{
   136          Script(Type("module"), Src("https://google.com/s.rs")),
   137      },
   138  })
   139  
   140  template.With("hola mundo").WriteTo(os.Stdout)
   141  ```
   142  
   143   Output:
   144  
   145  ```
   146  <html>
   147  <head>
   148  <style>body{background: red;}</style>
   149  <script>document.Write("hello world");</script>
   150  <script type="module" src="https://google.com/s.rs"/>
   151  </head>
   152  <body>
   153  hola mundo</body>
   154  </html>
   155  ```
   156  
   157  ### type [Document](/document.go#L11)
   158  
   159  `type Document struct { ... }`
   160  
   161  #### func (*Document) [AddComponent](/document.go#L32)
   162  
   163  `func (l *Document) AddComponent(c Component)`
   164  
   165  #### func (*Document) [With](/document.go#L36)
   166  
   167  `func (l *Document) With(content ...interface{ ... }) io.WriterTo`
   168  
   169  ## Sub Packages
   170  
   171  * [lazylayout](./lazylayout)
   172  
   173  ---
   174  Readme created from Go doc with [goreadme](https://github.com/posener/goreadme)