github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/render/js.go (about)

     1  package render
     2  
     3  // JavaScript renders the named files using the 'application/javascript'
     4  // content type and the github.com/gobuffalo/plush
     5  // package for templating. If more than 1 file is provided
     6  // the second file will be considered a "layout" file
     7  // and the first file will be the "content" file which will
     8  // be placed into the "layout" using "<%= yield %>".
     9  func JavaScript(names ...string) Renderer {
    10  	e := New(Options{})
    11  	return e.JavaScript(names...)
    12  }
    13  
    14  // JavaScript renders the named files using the 'application/javascript'
    15  // content type and the github.com/gobuffalo/plush
    16  // package for templating. If more than 1 file is provided
    17  // the second file will be considered a "layout" file
    18  // and the first file will be the "content" file which will
    19  // be placed into the "layout" using "<%= yield %>". If no
    20  // second file is provided and an `JavaScriptLayout` is specified
    21  // in the options, then that layout file will be used
    22  // automatically.
    23  func (e *Engine) JavaScript(names ...string) Renderer {
    24  	if e.JavaScriptLayout != "" && len(names) == 1 {
    25  		names = append(names, e.JavaScriptLayout)
    26  	}
    27  	hr := &templateRenderer{
    28  		Engine:      e,
    29  		contentType: "application/javascript",
    30  		names:       names,
    31  	}
    32  	return hr
    33  }