Skip to content

Commit

Permalink
Use the latest version of the datablock module
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Oct 20, 2023
1 parent 9439ecc commit e566790
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion engine/funcmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (ac *Config) Lua2funcMap(w http.ResponseWriter, req *http.Request, filename
if luablock.HasData() {
// There was Lua code available. Now make the functions and
// variables available for the template.
funcs, err = ac.LuaFunctionMap(w, req, luablock.MustData(), luafilename)
funcs, err = ac.LuaFunctionMap(w, req, luablock.Bytes(), luafilename)
if err != nil {
funcMapChan <- funcs
errChan <- err
Expand Down
26 changes: 13 additions & 13 deletions engine/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (ac *Config) PongoHandler(w http.ResponseWriter, req *http.Request, filenam
luablock = datablock.EmptyDataBlock
}
// Use the Lua filename as the title
ac.PrettyError(w, req, luafilename, luablock.MustData(), err.Error(), "lua")
ac.PrettyError(w, req, luafilename, luablock.Bytes(), err.Error(), "lua")
} else {
log.Error(err)
}
Expand All @@ -89,7 +89,7 @@ func (ac *Config) PongoHandler(w http.ResponseWriter, req *http.Request, filenam

// Render the Pongo2 page, using functions from luaDataFilename, if available
ac.pongomutex.Lock()
ac.PongoPage(w, req, filename, pongoblock.MustData(), funcs)
ac.PongoPage(w, req, filename, pongoblock.Bytes(), funcs)
ac.pongomutex.Unlock()

return
Expand All @@ -103,7 +103,7 @@ func (ac *Config) PongoHandler(w http.ResponseWriter, req *http.Request, filenam
// Use the Pongo2 template without any Lua functions
ac.pongomutex.Lock()
funcs := make(template.FuncMap)
ac.PongoPage(w, req, filename, pongoblock.MustData(), funcs)
ac.PongoPage(w, req, filename, pongoblock.Bytes(), funcs)
ac.pongomutex.Unlock()
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
// If the auto-refresh feature has been enabled
if ac.autoRefresh {
// Get the bytes from the datablock
htmldata := htmlblock.MustData()
htmldata := htmlblock.Bytes()
// Insert JavaScript for refreshing the page, into the HTML
htmldata = ac.InsertAutoRefresh(req, htmldata)
// Write the data to the client
Expand All @@ -169,7 +169,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
w.Header().Add("Content-Type", "text/html;charset=utf-8")
if markdownblock, err := ac.ReadAndLogErrors(w, filename, ext); err == nil { // if no error
// Render the markdown page
ac.MarkdownPage(w, req, markdownblock.MustData(), filename)
ac.MarkdownPage(w, req, markdownblock.Bytes(), filename)
}
return

Expand Down Expand Up @@ -208,11 +208,11 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
if luablock.HasData() {
// There was Lua code available. Now make the functions and
// variables available for the template.
funcs, err = ac.LuaFunctionMap(w, req, luablock.MustData(), luafilename)
funcs, err = ac.LuaFunctionMap(w, req, luablock.Bytes(), luafilename)
if err != nil {
if ac.debugMode {
// Use the Lua filename as the title
ac.PrettyError(w, req, luafilename, luablock.MustData(), err.Error(), "lua")
ac.PrettyError(w, req, luafilename, luablock.Bytes(), err.Error(), "lua")
} else {
log.Error(err)
}
Expand All @@ -233,7 +233,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
}

// Render the Amber page, using functions from luaDataFilename, if available
ac.AmberPage(w, req, filename, amberblock.MustData(), funcs)
ac.AmberPage(w, req, filename, amberblock.Bytes(), funcs)

return

Expand Down Expand Up @@ -289,7 +289,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
fileblock = datablock.NewDataBlock([]byte(err.Error()), true)
}
// If there were errors, display an error page
ac.PrettyError(w, req, filename, fileblock.MustData(), errortext, "lua")
ac.PrettyError(w, req, filename, fileblock.Bytes(), errortext, "lua")
} else {
// If things went well, check if there is a status code we should write first
// (especially for the case of a redirect)
Expand Down Expand Up @@ -320,23 +320,23 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
if gcssblock, err := ac.ReadAndLogErrors(w, filename, ext); err == nil { // if no error
w.Header().Add("Content-Type", "text/css;charset=utf-8")
// Render the GCSS page as CSS
ac.GCSSPage(w, req, filename, gcssblock.MustData())
ac.GCSSPage(w, req, filename, gcssblock.Bytes())
}
return

case ".scss":
if scssblock, err := ac.ReadAndLogErrors(w, filename, ext); err == nil { // if no error
// Render the SASS page (with .scss extension) as CSS
w.Header().Add("Content-Type", "text/css;charset=utf-8")
ac.SCSSPage(w, req, filename, scssblock.MustData())
ac.SCSSPage(w, req, filename, scssblock.Bytes())
}
return

case ".happ", ".hyper", ".hyper.jsx", ".hyper.js": // hyperApp JSX -> JS, wrapped in HTML
if jsxblock, err := ac.ReadAndLogErrors(w, filename, ext); err == nil { // if no error
// Render the JSX page as HTML with embedded JavaScript
w.Header().Add("Content-Type", "text/html;charset=utf-8")
ac.HyperAppPage(w, req, filename, jsxblock.MustData())
ac.HyperAppPage(w, req, filename, jsxblock.Bytes())
} else {
log.Error("Error when serving " + filename + ":" + err.Error())
}
Expand All @@ -347,7 +347,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _
if jsxblock, err := ac.ReadAndLogErrors(w, filename, ext); err == nil { // if no error
// Render the JSX page as JavaScript
w.Header().Add("Content-Type", "text/javascript;charset=utf-8")
ac.JSXPage(w, req, filename, jsxblock.MustData())
ac.JSXPage(w, req, filename, jsxblock.Bytes())
}
return

Expand Down
10 changes: 5 additions & 5 deletions engine/rendering.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (ac *Config) MarkdownPage(w http.ResponseWriter, req *http.Request, data []
fmt.Fprintf(w, "Unable to read %s: %s", filename, err)
return
}
gcssdata := gcssblock.MustData()
gcssdata := gcssblock.Bytes()

// Try compiling the GCSS file first
errChan := make(chan error)
Expand Down Expand Up @@ -399,7 +399,7 @@ func (ac *Config) MarkdownPage(w http.ResponseWriter, req *http.Request, data []
fmt.Fprintf(w, "Unable to read %s: %s", filename, err)
return
}
cssdata := cssblock.MustData()
cssdata := cssblock.Bytes()
head.WriteString("<style>" + string(cssdata) + "</style>")
} else {
head.WriteString(`<link href="`)
Expand Down Expand Up @@ -480,7 +480,7 @@ func (ac *Config) PongoPage(w http.ResponseWriter, req *http.Request, filename s
fmt.Fprintf(w, "Unable to read %s: %s", filename, err)
return
}
gcssdata := gcssblock.MustData()
gcssdata := gcssblock.Bytes()

// Try compiling the GCSS file before the Pongo2 file
errChan := make(chan error)
Expand Down Expand Up @@ -658,7 +658,7 @@ func (ac *Config) AmberPage(w http.ResponseWriter, req *http.Request, filename s
fmt.Fprintf(w, "Unable to read %s: %s", filename, err)
return
}
gcssdata := gcssblock.MustData()
gcssdata := gcssblock.Bytes()

// Try compiling the GCSS file before the Amber file
errChan := make(chan error)
Expand Down Expand Up @@ -816,7 +816,7 @@ func (ac *Config) HyperAppPage(w http.ResponseWriter, req *http.Request, filenam
fmt.Fprintf(w, "Unable to read %s: %s", filename, err)
return
}
gcssdata := gcssblock.MustData()
gcssdata := gcssblock.Bytes()

// Try compiling the GCSS file first
errChan := make(chan error)
Expand Down
2 changes: 1 addition & 1 deletion engine/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (ac *Config) ServeStaticFile(filename, colonPort string) error {
extensions := parser.CommonExtensions | parser.AutoHeadingIDs
mdParser := parser.NewWithExtensions(extensions)
// Convert from Markdown to HTML
htmlbody := markdown.ToHTML(markdownData.MustData(), mdParser, nil)
htmlbody := markdown.ToHTML(markdownData.Bytes(), mdParser, nil)
localImages = utils.ExtractLocalImagePaths(string(htmlbody))
}

Expand Down

0 comments on commit e566790

Please sign in to comment.