Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* add elements viewer #47

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ test:
go test ./... -v

# Update required tools and libraries
update: download-rapidoc download-style
update: download-rapidoc download-elements download-style
go get -u
go mod tidy

# Install additionally required tools
tools:
Expand All @@ -37,7 +38,12 @@ tools:

# Download rapidoc, an OpenAPI documentation viewer
download-rapidoc:
curl -o templates/web/css/rapidoc-min.js -L https://unpkg.com/rapidoc/dist/rapidoc-min.js
curl -o templates/web/js/rapidoc-min.js -L https://unpkg.com/rapidoc/dist/rapidoc-min.js

# Download elements, an OpenAPI documentation viewer (https://stoplight.io/open-source/elements)
download-elements:
curl -o templates/web/js/elements.min.js -L https://unpkg.com/@stoplight/elements/web-components.min.js
curl -o templates/web/css/elements.min.css -L https://unpkg.com/@stoplight/elements/styles.min.css

# Download frontend libraries
# woff Dateien müssen aus dem ZIP manuell nach fonts/ kopiert werden!
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Generation flags:
For typical tasks you can use the [just](https://just.systems/man/en/) recipes:

build # Build the local dredger binary
download-elements # Download elements, an OpenAPI documentation viewer
download-rapidoc # Download rapidoc, an OpenAPI documentation viewer
download-style # Download frontend libraries
generate # Generate the source code in the target directory ./src from the OpenAPI file provided in the environment variable OPEN_API_PATH
Expand Down
2 changes: 1 addition & 1 deletion core/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.5
0.3.6
8 changes: 5 additions & 3 deletions generator/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func generateFrontend(spec *openapi3.T, conf GeneratorConfig) {
fs.CopyWebFile("web/js", javascriptPath, "htmx-sse.js", true)
fs.CopyWebFile("web/js", javascriptPath, "htmx.min.js", true)
fs.CopyWebFile("web/js", javascriptPath, "hyperscript.js", true)
fs.CopyWebFile("web/js", javascriptPath, "rapidoc-min.js", true)
fs.CopyWebFile("web/js", javascriptPath, "sse.js", true)
fs.CopyWebFile("web/js", javascriptPath, "rapidoc-min.js", true)
fs.CopyWebFile("web/js", javascriptPath, "elements.min.js", true)

// files in stylesheet directory
fs.CopyWebFile("web/css", stylesheetPath, "bootstrap-icons.min.css", true)
Expand All @@ -63,7 +64,7 @@ func generateFrontend(spec *openapi3.T, conf GeneratorConfig) {
fs.CopyWebFile("web/css", stylesheetPath, "bootstrap.min.css", true)
fs.CopyWebFile("web/css", stylesheetPath, "pico.min.css", true)
fs.CopyWebFile("web/css", stylesheetPath, "pico.colors.min.css", true)
fs.CopyWebFile("web/css", stylesheetPath, "simple.min.css", true)
fs.CopyWebFile("web/css", stylesheetPath, "elements.min.css", true)

// files in images directory
fs.CopyWebFile("web/images", imagesPath, "favicon.ico", false)
Expand Down Expand Up @@ -224,7 +225,8 @@ func generateOpenAPIDoc(conf GeneratorConfig) {
}

// create static html files
createFileFromTemplate(filepath.Join(path, "index.html"), "templates/openapidoc/index.html.tmpl", template)
createFileFromTemplate(filepath.Join(path, "rapidoc.html"), "templates/rapidoc/index.html.tmpl", template)
createFileFromTemplate(filepath.Join(path, "elements.html"), "templates/elements/index.html.tmpl", template)

// copy OpenAPI Specification in this directory
fs.CopyFile(conf.OpenAPIPath, path, template.OpenAPIFile)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ require (
github.com/spf13/cast v1.7.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/text v0.19.0 // indirect
)

require (
Expand All @@ -53,6 +53,6 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/otiai10/copy v1.14.0
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -343,13 +343,13 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
2 changes: 2 additions & 0 deletions templates/core/config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Config struct {
Languages []string `default:"en,de"`
UseSse bool `default:"false" split_words:"true"`
ProgressDuration int `default:"100" split_words:"true"`
RapidocDoc bool `default:"false" split_words:"true"`
ElementsDoc bool `default:"false" split_words:"true"`
ConfigExt
}

Expand Down
20 changes: 20 additions & 0 deletions templates/elements/index.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{.ModuleName}} Frontend</title>

<script src="js/elements.min.js"></script>
<link rel="stylesheet" href="css/elements.min.css">
</head>
<body>

<elements-api
apiDescriptionUrl="{{.OpenAPIFile}}"
layout="responsive"
router="hash"
/>

</body>
</html>
7 changes: 6 additions & 1 deletion templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ func main() {
{{- if .AddFrontend }}

// serve doc
e.FileFS("/doc", "web/doc/index.html", embeddedFS)
if core.AppConfig.ElementsDoc {
e.FileFS("/doc", "web/doc/elements.html", embeddedFS)
} else if core.AppConfig.RapidocDoc {
e.FileFS("/doc", "web/doc/rapidoc.html", embeddedFS)
}
e.FileFS("/{{.OpenAPIName}}.yaml", "web/doc/{{.OpenAPIName}}.yaml", embeddedFS)

// serve default stylesheets and javascript files
e.StaticFS("/css/", echo.MustSubFS(web.Css, "css"))
e.StaticFS("/js/", echo.MustSubFS(web.Js, "js"))
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions templates/web/css/elements.min.css

Large diffs are not rendered by default.

3,899 changes: 0 additions & 3,899 deletions templates/web/css/rapidoc-min.js

This file was deleted.

2 changes: 2 additions & 0 deletions templates/web/js/elements.min.js

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions templates/web/js/htmx-sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

(function() {

if (htmx.version && !htmx.version.startsWith("1.")) {
console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version +
". It is recommended that you move to the version of this extension found on https://htmx.org/extensions")
}

/** @type {import("../htmx").HtmxInternalApi} */
var api;

htmx.defineExtension("sse", {

/**
* Init saves the provided reference to the internal HTMX API.
*
* @param {import("../htmx").HtmxInternalApi} api
*
* @param {import("../htmx").HtmxInternalApi} api
* @returns void
*/
init: function(apiRef) {
Expand All @@ -30,9 +35,9 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

/**
* onEvent handles all events passed to this extension.
*
* @param {string} name
* @param {Event} evt
*
* @param {string} name
* @param {Event} evt
* @returns void
*/
onEvent: function(name, evt) {
Expand Down Expand Up @@ -64,8 +69,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
/**
* createEventSource is the default method for creating new EventSource objects.
* it is hoisted into htmx.config.createEventSource to be overridden by the user, if needed.
*
* @param {string} url
*
* @param {string} url
* @returns EventSource
*/
function createEventSource(url) {
Expand Down Expand Up @@ -105,7 +110,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
}

/**
* registerSSE looks for attributes that can contain sse events, right
* registerSSE looks for attributes that can contain sse events, right
* now hx-trigger and sse-swap and adds listeners based on these attributes too
* the closest event source
*
Expand Down Expand Up @@ -183,7 +188,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
if (sseEventName.slice(0, 4) != "sse:") {
return;
}

// remove the sse: prefix from here on out
sseEventName = sseEventName.substr(4);

Expand Down Expand Up @@ -269,8 +274,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
/**
* maybeCloseSSESource confirms that the parent element still exists.
* If not, then any associated SSE source is closed and the function returns true.
*
* @param {HTMLElement} elt
*
* @param {HTMLElement} elt
* @returns boolean
*/
function maybeCloseSSESource(elt) {
Expand All @@ -287,9 +292,9 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

/**
* queryAttributeOnThisOrChildren returns all nodes that contain the requested attributeName, INCLUDING THE PROVIDED ROOT ELEMENT.
*
* @param {HTMLElement} elt
* @param {string} attributeName
*
* @param {HTMLElement} elt
* @param {string} attributeName
*/
function queryAttributeOnThisOrChildren(elt, attributeName) {

Expand All @@ -310,7 +315,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

/**
* @param {HTMLElement} elt
* @param {string} content
* @param {string} content
*/
function swap(elt, content) {

Expand Down Expand Up @@ -340,10 +345,10 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
}

/**
* doSettle mirrors much of the functionality in htmx that
* doSettle mirrors much of the functionality in htmx that
* settles elements after their content has been swapped.
* TODO: this should be published by htmx, and not duplicated here
* @param {import("../htmx").HtmxSettleInfo} settleInfo
* @param {import("../htmx").HtmxSettleInfo} settleInfo
* @returns () => void
*/
function doSettle(settleInfo) {
Expand Down
2 changes: 1 addition & 1 deletion templates/web/js/htmx.min.js

Large diffs are not rendered by default.

766 changes: 390 additions & 376 deletions templates/web/js/rapidoc-min.js

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions templates/web/js/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

(function() {

if (htmx.version && !htmx.version.startsWith("1.")) {
console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version +
". It is recommended that you move to the version of this extension found on https://htmx.org/extensions")
}

/** @type {import("../htmx").HtmxInternalApi} */
var api;

htmx.defineExtension("sse", {

/**
* Init saves the provided reference to the internal HTMX API.
*
* @param {import("../htmx").HtmxInternalApi} api
*
* @param {import("../htmx").HtmxInternalApi} api
* @returns void
*/
init: function(apiRef) {
Expand All @@ -30,9 +35,9 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

/**
* onEvent handles all events passed to this extension.
*
* @param {string} name
* @param {Event} evt
*
* @param {string} name
* @param {Event} evt
* @returns void
*/
onEvent: function(name, evt) {
Expand Down Expand Up @@ -64,8 +69,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
/**
* createEventSource is the default method for creating new EventSource objects.
* it is hoisted into htmx.config.createEventSource to be overridden by the user, if needed.
*
* @param {string} url
*
* @param {string} url
* @returns EventSource
*/
function createEventSource(url) {
Expand Down Expand Up @@ -105,7 +110,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
}

/**
* registerSSE looks for attributes that can contain sse events, right
* registerSSE looks for attributes that can contain sse events, right
* now hx-trigger and sse-swap and adds listeners based on these attributes too
* the closest event source
*
Expand Down Expand Up @@ -183,7 +188,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
if (sseEventName.slice(0, 4) != "sse:") {
return;
}

// remove the sse: prefix from here on out
sseEventName = sseEventName.substr(4);

Expand Down Expand Up @@ -269,8 +274,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
/**
* maybeCloseSSESource confirms that the parent element still exists.
* If not, then any associated SSE source is closed and the function returns true.
*
* @param {HTMLElement} elt
*
* @param {HTMLElement} elt
* @returns boolean
*/
function maybeCloseSSESource(elt) {
Expand All @@ -287,9 +292,9 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

/**
* queryAttributeOnThisOrChildren returns all nodes that contain the requested attributeName, INCLUDING THE PROVIDED ROOT ELEMENT.
*
* @param {HTMLElement} elt
* @param {string} attributeName
*
* @param {HTMLElement} elt
* @param {string} attributeName
*/
function queryAttributeOnThisOrChildren(elt, attributeName) {

Expand All @@ -310,7 +315,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

/**
* @param {HTMLElement} elt
* @param {string} content
* @param {string} content
*/
function swap(elt, content) {

Expand Down Expand Up @@ -340,10 +345,10 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
}

/**
* doSettle mirrors much of the functionality in htmx that
* doSettle mirrors much of the functionality in htmx that
* settles elements after their content has been swapped.
* TODO: this should be published by htmx, and not duplicated here
* @param {import("../htmx").HtmxSettleInfo} settleInfo
* @param {import("../htmx").HtmxSettleInfo} settleInfo
* @returns () => void
*/
function doSettle(settleInfo) {
Expand Down