Skip to content

Commit

Permalink
bugfix/package-extensions-loading (#139)
Browse files Browse the repository at this point in the history
* Fixed the Requires.jl code so that package extensions are loaded properly
  • Loading branch information
ndortega authored Jan 13, 2024
1 parent 53a7aa9 commit ede83e9
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 83 deletions.
16 changes: 16 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand All @@ -21,9 +22,24 @@ Dates = "^1"
HTTP = "^1"
JSON3 = "^1.9"
MIMEs = "^0.1.4"
Mustache = "^1"
OteraEngine = "^0"
Pkg = "^1"
Reexport = "^1"
RelocatableFolders = "^1"
Requires = "^1"
Sockets = "^1"
Statistics = "^1"
StructTypes = "^1"
Suppressor = "^0"
julia = "^1.6"

[extras]
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
OteraEngine = "b2d7f28f-acd6-4007-8b26-bc27716e5513"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Mustache", "OteraEngine", "Pkg", "StructTypes", "Test"]
4 changes: 2 additions & 2 deletions data/dashboard/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/css/main.1e415bb7.css",
"main.js": "/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/js/main.bd661328.js",
"main.js": "/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/js/main.cbb8a478.js",
"static/media/signInImage.png": "/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/media/signInImage.eeb0c777f5867442d1a2.png",
"static/media/BgSignUp.png": "/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/media/BgSignUp.2dea4acf779bbfe49e5c.png",
"static/media/roboto-all-500-normal.woff": "/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/media/roboto-all-500-normal.0ab669b7a0d19b178f57.woff",
Expand Down Expand Up @@ -33,6 +33,6 @@
},
"entrypoints": [
"static/css/main.1e415bb7.css",
"static/js/main.bd661328.js"
"static/js/main.cbb8a478.js"
]
}
2 changes: 1 addition & 1 deletion data/dashboard/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en" dir="ltr"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/manifest.json"/><link rel="shortcut icon" href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/favicon.ico"/><link rel="apple-touch-icon" sizes="76x76" href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/apple-icon.png"/><title>Oxygen Metrics</title><script defer="defer" src="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/js/main.bd661328.js"></script><link href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/css/main.1e415bb7.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en" dir="ltr"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/manifest.json"/><link rel="shortcut icon" href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/favicon.ico"/><link rel="apple-touch-icon" sizes="76x76" href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/apple-icon.png"/><title>Oxygen Metrics</title><script defer="defer" src="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/js/main.cbb8a478.js"></script><link href="/df9a0d86-3283-4920-82dc-4555fc0d1d8b/static/css/main.1e415bb7.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/Oxygen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ include("util.jl" ); using .Util
include("bodyparsers.jl"); using .BodyParsers
include("core.jl"); using .Core

# Load any optional extensions
include("extensions/load.jl");

export @get, @post, @put, @patch, @delete, @route, @cron,
@staticfiles, @dynamicfiles, staticfiles, dynamicfiles,
get, post, put, patch, delete, route,
Expand All @@ -15,8 +18,4 @@ export @get, @post, @put, @patch, @delete, @route, @cron,
configdocs, mergeschema, setschema, getschema, router,
enabledocs, disabledocs, isdocsenabled, starttasks, stoptasks,
resetstate, startcronjobs, stopcronjobs, clearcronjobs

# Load any optional extensions
include("extensions/load.jl");

end
2 changes: 2 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ function resetstate()
resetstatevariables()
# reset cron module state
resetcronstate()
# clear metrics
clear_history()
end


Expand Down
14 changes: 3 additions & 11 deletions src/extensions/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ using Requires

function __init__()


################################################################
# Templating Extensions #
# Templating Extensions #
################################################################
@require Mustache="ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" include("templating/mustache.jl")
@require OteraEngine="b2d7f28f-acd6-4007-8b26-bc27716e5513" include("templating/oteraengine.jl")

@require Mustache="ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" begin
include("templating/mustache.jl"); using .MustacheTemplating
export mustache
end

@require OteraEngine="b2d7f28f-acd6-4007-8b26-bc27716e5513" begin
include("templating/oteraengine.jl"); using .OteraEngineTemplating
export otera
end
end
22 changes: 18 additions & 4 deletions src/extensions/templating/mustache.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
module MustacheTemplating
using HTTP
using MIMEs
using Mustache
include("util.jl"); using .TemplatingUtil
using .Mustache

export mustache

"""
response(content::String, status=200, headers=[]) :: HTTP.Response
Convert a template string `content` into a valid HTTP Response object.
The content type header is automatically generated based on the content's mimetype
- `content`: The string content to be included in the HTTP response body.
- `status`: The HTTP status code (default is 200).
- `headers`: Additional HTTP headers to include (default is an empty array).
Returns an `HTTP.Response` object with the specified content, status, and headers.
"""
function response(content::String, status=200, headers=[]; detect=true) :: HTTP.Response
response_headers = detect ? ["Content-Type" => HTTP.sniff(content)] : []
return HTTP.Response(status, [response_headers; headers;], content)
end

"""
mustache(template::String; kwargs...)
Expand Down Expand Up @@ -75,4 +89,4 @@ function mustache(file::IO; mime_type=nothing, kwargs...)
end
end

end

22 changes: 18 additions & 4 deletions src/extensions/templating/oteraengine.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
module OteraEngineTemplating
using HTTP
using MIMEs
using OteraEngine
include("util.jl"); using .TemplatingUtil
using .OteraEngine

export otera

"""
response(content::String, status=200, headers=[]) :: HTTP.Response
Convert a template string `content` into a valid HTTP Response object.
The content type header is automatically generated based on the content's mimetype
- `content`: The string content to be included in the HTTP response body.
- `status`: The HTTP status code (default is 200).
- `headers`: Additional HTTP headers to include (default is an empty array).
Returns an `HTTP.Response` object with the specified content, status, and headers.
"""
function response(content::String, status=200, headers=[]; detect=true) :: HTTP.Response
response_headers = detect ? ["Content-Type" => HTTP.sniff(content)] : []
return HTTP.Response(status, [response_headers; headers;], content)
end

"""
otera(template::String; kwargs...)
Expand Down Expand Up @@ -69,4 +84,3 @@ function otera(file::IO; mime_type=nothing, kwargs...)
end
end

end
23 changes: 0 additions & 23 deletions src/extensions/templating/util.jl

This file was deleted.

3 changes: 2 additions & 1 deletion src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using RelocatableFolders
include("util.jl"); using .Util
include("bodyparsers.jl"); using .BodyParsers

export MetricsMiddleware, get_history, push_history, HTTPTransaction,
export MetricsMiddleware, get_history, clear_history, push_history,
HTTPTransaction,
server_metrics,
all_endpoint_metrics,
capture_metrics, bin_and_count_transactions,
Expand Down
29 changes: 0 additions & 29 deletions test/Project.toml

This file was deleted.

3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using StructTypes
using Sockets
using Dates

ENV["OXYGEN_TESTING_MODE"] = "true"

include("../src/Oxygen.jl")
using .Oxygen

Expand Down Expand Up @@ -637,7 +639,6 @@ r = internalrequest(HTTP.Request("GET", "/math/square/3"))

r = internalrequest(HTTP.Request("GET", "/getroutervalue"))
@test r.status == 200
println(text(r))
@test parse(Int64, text(r)) > 0

r = internalrequest(HTTP.Request("GET", "/emptyrouter"))
Expand Down
1 change: 0 additions & 1 deletion test/templatingtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using .Oxygen
# ensure the init is called so we can load the extensions
Oxygen.__init__()


function clean_output(result::String)
# Replace carriage returns followed by line feeds (\r\n) with a single newline (\n)
tmp = replace(result, "\r\n" => "\n")
Expand Down

0 comments on commit ede83e9

Please sign in to comment.