Skip to content

Commit

Permalink
v0.25.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Feb 3, 2020
1 parent 6f7c316 commit 2e70bc0
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 97 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.25.2 - 2020-02-03

* bug fixes
* performance improvements
* deps update

## v0.22.9 - 2020-01-06

* refactoring of the Rendering engine (**breaking**)
Expand Down
12 changes: 6 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ URIParser = "0.4"
julia = "1.2"

[extras]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestSetExtensions = "98d24dd4-01ad-11ea-1b02-c9a08f80db04"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

[targets]
test = ["SafeTestsets", "Test", "TestSetExtensions", "Pkg", "Random", "Revise", "Logging","LoggingExtras", "Sockets", "Dates"]
test = ["SafeTestsets", "Test", "TestSetExtensions", "Pkg", "Random", "Revise", "Logging", "LoggingExtras", "Sockets", "Dates"]
6 changes: 3 additions & 3 deletions files/new_app/config/initializers/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ function initialize_logging()
isdir(Genie.config.path_log) || mkpath(Genie.config.path_log)
LoggingExtras.DemuxLogger(
LoggingExtras.FileLogger(joinpath(Genie.config.path_log, "$(Genie.config.app_env)-$(Dates.today()).log"), always_flush = true, append = true),
LoggingExtras.ConsoleLogger(stdout, Genie.config.log_level),
Logging.ConsoleLogger(stdout, Genie.config.log_level),
include_current_global = false
)
else
LoggingExtras.ConsoleLogger(stdout, Genie.config.log_level)
Logging.ConsoleLogger(stdout, Genie.config.log_level)
end

timestamp_logger(logger) = LoggingExtras.TransformerLogger(logger) do log
Expand All @@ -25,4 +25,4 @@ function initialize_logging()
nothing
end

@async initialize_logging()
initialize_logging()
3 changes: 1 addition & 2 deletions files/new_app/config/initializers/searchlight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ using SearchLight, SearchLight.QueryBuilder

function initialize_searchlight()
try
SearchLight.Configuration.load() |> SearchLight.Database.connect!
SearchLight.load_resources()
SearchLight.Configuration.load() |> SearchLight.connect!
catch ex
@error ex
end
Expand Down
2 changes: 1 addition & 1 deletion files/new_app/db/connection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ test:
username:
password:
port:
config:
config:
5 changes: 2 additions & 3 deletions src/AppServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function startup(port::Int = Genie.config.server_port, host::String = Genie.conf
verbose::Bool = false, ratelimit::Union{Rational{Int},Nothing} = nothing,
server::Union{Sockets.TCPServer,Nothing} = nothing) :: ServersCollection

update_config(port, host, ws_port, async)
update_config(port, host, ws_port)

if Genie.config.websockets_server
SERVERS.websockets = @async HTTP.listen(host, ws_port) do req
Expand Down Expand Up @@ -76,11 +76,10 @@ function startup(port::Int = Genie.config.server_port, host::String = Genie.conf
end


function update_config(port::Int, host::String, ws_port::Int, async::Bool) :: Nothing
function update_config(port::Int, host::String, ws_port::Int) :: Nothing
Genie.config.server_port = port
Genie.config.server_host = host
Genie.config.websockets_port = ws_port
Genie.config.run_as_server = ! async

nothing
end
Expand Down
36 changes: 11 additions & 25 deletions src/Generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ Generates various Genie files.
module Generator

import Revise, SHA, Dates, Pkg, Logging
import Genie, Genie.FileTemplates, Genie.Inflector, Genie.Configuration, Genie.Util, Genie.Exceptions
import Genie


const JULIA_PATH = joinpath(Sys.BINDIR, "julia")


"""
newcontroller(cmd_args::Dict{String,Any}) :: Nothing
newcontroller(resource_name::String) :: Nothing
Generates a new Genie controller file and persists it to the resources folder.
"""
function newcontroller(cmd_args::Dict{String,Any}; path::String = ".", pluralize::Bool = true) :: Nothing
resource_name = cmd_args["controller:new"]
Genie.Inflector.is_singular(resource_name) && pluralize && (resource_name = Inflector.to_plural(resource_name))
function newcontroller(resource_name::String; path::String = ".", pluralize::Bool = true, mvc_support::Bool = true) :: Nothing
Genie.Inflector.is_singular(resource_name) && pluralize && (resource_name = Genie.Inflector.to_plural(resource_name))
resource_name = uppercasefirst(resource_name)

resource_path = setup_resource_path(resource_name, path = path)
resource_path = mvc_support ? setup_resource_path(resource_name, path = path) : (ispath(path) ? path : mkpath(path))
cfn = controller_file_name(resource_name)
write_resource_file(resource_path, cfn, resource_name, :controller, pluralize = pluralize) &&
@info "New controller created at $(abspath(joinpath(resource_path, cfn)))"
Expand All @@ -30,16 +29,13 @@ end


"""
newresource(cmd_args::Dict{String,Any}, config::Settings) :: Nothing
newresource(resource_name::String, config::Settings) :: Nothing
Generates all the files associated with a new resource and persists them to the resources folder.
"""
function newresource(cmd_args::Dict{String,Any}; path::String = ".", pluralize::Bool = true) :: Nothing
resource_name = uppercasefirst(cmd_args["resource:new"])

if Genie.Inflector.is_singular(resource_name) && pluralize
resource_name = Genie.Inflector.to_plural(resource_name)
end
function newresource(resource_name::String; path::String = ".", pluralize::Bool = true) :: Nothing
Genie.Inflector.is_singular(resource_name) && pluralize &&
(resource_name = Genie.Inflector.to_plural(resource_name))

resource_path = setup_resource_path(resource_name, path = path)
for (resource_file, resource_type) in [(controller_file_name(resource_name), :controller)]
Expand All @@ -54,16 +50,6 @@ function newresource(cmd_args::Dict{String,Any}; path::String = ".", pluralize::
end


"""
newresource(resource_name::Union{String,Symbol}) :: Nothing
Generates all the files associated with a new resource and persists them to the resources folder.
"""
function newresource(resource_name::Union{String,Symbol}; path::String = ".", pluralize::Bool = true) :: Nothing
newresource(Dict{String,Any}("resource:new" => string(resource_name)), path = path, pluralize = pluralize)
end


"""
setup_resource_path(resource_name::String) :: String
Expand All @@ -89,7 +75,7 @@ end
Generates all resouce files and persists them to disk.
"""
function write_resource_file(resource_path::String, file_name::String, resource_name::String, resource_type::Symbol; pluralize::Bool = true) :: Bool
resource_name = (pluralize ? (Inflector.to_plural(resource_name)) : resource_name) |> Inflector.from_underscores
resource_name = (pluralize ? (Genie.Inflector.to_plural(resource_name)) : resource_name) |> Genie.Inflector.from_underscores

try
if resource_type == :controller
Expand All @@ -106,7 +92,7 @@ function write_resource_file(resource_path::String, file_name::String, resource_
if resource_type == :test
resource_does_not_exist(resource_path, file_name) || return true
open(joinpath(resource_path, file_name), "w") do f
name = pluralize ? (Inflector.tosingular(resource_name)) : resource_name
name = pluralize ? (Genie.Inflector.tosingular(resource_name)) : resource_name
write(f, Genie.FileTemplates.newtest(resource_name, name))
end
end
Expand Down
11 changes: 11 additions & 0 deletions src/Renderer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ function WebRenderable(wr::WebRenderable, content_type::Symbol, status::Int, hea
end


function WebRenderable(f::Function, args...)
fr::String = try
f()::String
catch
Base.invokelatest(f)::String
end

WebRenderable(fr, args...)
end


function render end


Expand Down
17 changes: 15 additions & 2 deletions src/Router.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,17 @@ function match_routes(req::HTTP.Request, res::HTTP.Response, params::Params) ::

return try
run_hook(controller, BEFORE_HOOK)
result = (Genie.Configuration.isdev() ? Base.invokelatest(r.action) : (r.action)()) |> to_response
# result = (Genie.Configuration.isdev() ? Base.invokelatest(r.action) : (r.action)()) |> to_response
result = try
(r.action)() |> to_response
catch
Base.invokelatest(r.action) |> to_response
end

run_hook(controller, AFTER_HOOK)

result

catch ex
if isa(ex, Genie.Exceptions.ExceptionalResponse)
return ex.response
Expand Down Expand Up @@ -520,7 +527,13 @@ function match_channels(req, msg::String, ws_client, params::Params) :: String

return try
run_hook(controller, BEFORE_HOOK)
result = (Genie.Configuration.isdev() ? Base.invokelatest(c.action) : (c.action)()) |> string

result = try
(c.action)() |> string
catch
Base.invokelatest(c.action) |> string
end

run_hook(controller, AFTER_HOOK)

result
Expand Down
23 changes: 9 additions & 14 deletions src/Toolbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,34 @@ end


"""
new(cmd_args::Dict{String,Any}, config::Settings) :: Nothing
new(task_name::String, config::Settings = App.config) :: Nothing
new(task_name::String) :: Nothing
Generates a new Genie task file.
"""
function new(cmd_args::Dict{String,Any}, config::Genie.Configuration.Settings = Genie.config) :: Nothing
tfn = taskfilename(cmd_args, config)
function new(task_name::String) :: Nothing
task_name = validtaskname(task_name)
tfn = taskfilename(task_name)

isfile(tfn) && throw(Genie.Exceptions.FileExistsException(tfn))
isdir(Genie.config.path_tasks) || mkpath(Genie.config.path_tasks)

f = open(tfn, "w")
write(f, Genie.FileTemplates.newtask(taskmodulename(cmd_args["task:new"])))
close(f)
open(tfn, "w") do io
write(io, Genie.FileTemplates.newtask(taskmodulename(task_name)))
end

@info "New task created at $tfn"

nothing
end
function new(task_name::String, config::Genie.Configuration.Settings = Genie.config) :: Nothing
new(Dict{String,Any}("task:new" => validtaskname(task_name)), config)

nothing
end


"""
task_file_name(cmd_args::Dict{String,Any}, config::Settings) :: String
Computes the name of a Genie task based on the command line input.
"""
function taskfilename(cmd_args::Dict{String,Any}, config::Genie.Configuration.Settings = Genie.config) :: String
joinpath(Genie.config.path_tasks, cmd_args["task:new"] * ".jl")
function taskfilename(task_name::String) :: String
joinpath(Genie.config.path_tasks, "$task_name.jl")
end


Expand Down
19 changes: 10 additions & 9 deletions src/genie_module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ import REPL, REPL.Terminals


"""
newcontroller(controller_name::String) :: Nothing
newcontroller(controller_name::Union{String,Symbol}) :: Nothing
Creates a new `controller` file. If `pluralize` is `false`, the name of the controller is not automatically pluralized.
"""
function newcontroller(controller_name::String; pluralize::Bool = true) :: Nothing
Generator.newcontroller(Dict{String,Any}("controller:new" => controller_name), pluralize = pluralize)
function newcontroller(controller_name::Union{String,Symbol}; path::String = ".", pluralize::Bool = true, mvc_support::Bool = false) :: Nothing
Generator.newcontroller(string(controller_name), path = path, pluralize = pluralize, mvc_support = mvc_support)
load_resources()

nothing
end


"""
newresource(resource_name::String; pluralize::Bool = true, context::Union{Module,Nothing} = nothing) :: Nothing
newresource(resource_name::Union{String,Symbol}; pluralize::Bool = true, context::Union{Module,Nothing} = nothing) :: Nothing
Creates all the files associated with a new resource.
If `pluralize` is `false`, the name of the resource is not automatically pluralized.
"""
function newresource(resource_name::String; pluralize::Bool = true, context::Union{Module,Nothing} = nothing) :: Nothing
function newresource(resource_name::Union{String,Symbol}; path::String = ".", pluralize::Bool = true, context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

Generator.newresource(Dict{String,Any}("resource:new" => resource_name), pluralize = pluralize)
Generator.newresource(string(resource_name), path = path, pluralize = pluralize)

try
pluralize || error("SearchLight resources need to be pluralized")
Expand All @@ -47,13 +47,14 @@ end


"""
newtask(task_name::String) :: Nothing
newtask(task_name::Union{String,Symbol}) :: Nothing
Creates a new Genie `Task` file.
"""
function newtask(task_name::String) :: Nothing
function newtask(task_name::Union{String,Symbol}) :: Nothing
task_name = string(task_name)
endswith(task_name, "Task") || (task_name = task_name * "Task")
Toolbox.new(Dict{String,Any}("task:new" => task_name), Genie.config)
Toolbox.new(task_name)

nothing
end
Expand Down
Loading

2 comments on commit 2e70bc0

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/8823

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.25.2 -m "<description of version>" 2e70bc0a59fd189d702a108b6e6ad92ef0816ebf
git push origin v0.25.2

Please sign in to comment.