Skip to content

Commit

Permalink
v0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Salceanu committed Aug 22, 2019
1 parent 4d3bd62 commit 4b653b8
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 94 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# Changelog

## v0.14 - 2019-08-21
## v0.15.0 - 2019-08-22

* fixed error in `Genie.newapp()` with `dbsupport = true`
* internal API cleanup and optimisations
* fixed issue with `newresource` SearchLight integration
* SearchLight initializer code is now uncommented
* dependencies update
* `Router.tolink` and its alias `Router.linkto` throw exceptions if the route is not defined **breaking**
* `Router.tolink!!` and its alias `Router.linkto!!` have been removed **breaking**
* new method `Requests.read(HttpFile, Type{String})` which returns the content of an uploaded file as a string.

## v0.14.0 - 2019-08-21

* consolidation of the Generator API
* Genie depencencies update
* Genie dependencies update
* support for Julia v1.2
* removal of the `REPL` module
* CORS handling improvement (thanks @milesfrain)
Expand Down
4 changes: 2 additions & 2 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ version = "0.5.1"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"]
git-tree-sha1 = "03ddc88af7f2d963fac5aa9f3ac8e11914d68a78"
git-tree-sha1 = "c4a527dba1d26add0e85946e1a53f42a1b343acc"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.8.4"
version = "0.8.5"

[[HttpCommon]]
deps = ["Dates", "Nullables", "Test", "URIParser"]
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.14.0"
version = "0.15.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/Working_With_Genie_Apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ Next, we add `SearchLight`:
Genie is designed to seamlessly integrate with SearchLight and provides access to various database oriented generators. First we need to tell Genie/SearchLight how to connect to the database. Let's use them to set up our database support. Run this in the Genie/Julia REPL:

```julia
julia> Genie.REPL.copy_db_support()
julia> Genie.Generator.dbsupport()
```

The command will add a `db/` folder within the root of the app. What we're looking for is the `db/connection.yml` file. Let's edit it. Make the file to look like this:
Expand Down Expand Up @@ -501,7 +501,7 @@ Database migrations provide a way to reliably, consistently and repeatedly apply
SearchLight needs its own DB table to keep track of the state of the migrations so let's set it up:

```julia
julia> SearchLight.db_init()
julia> SearchLight.init()
[info]: SQL QUERY: CREATE TABLE `schema_migrations` (
`version` varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (`version`)
Expand Down
15 changes: 5 additions & 10 deletions files/new_app/config/initializers/searchlight.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Uncomment the code to enable SearchLight support

#=
using SearchLight, SearchLight.QueryBuilder

SearchLight.Configuration.load()
if SearchLight.config.db_config_settings["adapter"] !== nothing
SearchLight.Database.setup_adapter()
SearchLight.Database.connect()
try
SearchLight.Configuration.load() |> SearchLight.Database.connect!
SearchLight.load_resources()
end
=#
catch ex
@error "Failed loading SearchLight database configuration. Please make sure you have a valid connection.yml file."
end
104 changes: 77 additions & 27 deletions src/App.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ const ASSET_FINGERPRINT = ""


"""
bootstrap(context::Module = @__MODULE__) :: Nothing
bootstrap(context::Union{Module,Nothing} = nothing) :: Nothing
Kickstarts the loading of a Genie app by loading the environment settings.
"""
function bootstrap(context::Module = @__MODULE__) :: Nothing
function bootstrap(context::Union{Module,Nothing} = nothing) :: Nothing
context = Genie.default_context(context)

if haskey(ENV, "GENIE_ENV") && isfile(joinpath(Genie.ENV_PATH, ENV["GENIE_ENV"] * ".jl"))
isfile(joinpath(Genie.ENV_PATH, Genie.GLOBAL_ENV_FILE_NAME)) && Base.include(context, joinpath(Genie.ENV_PATH, Genie.GLOBAL_ENV_FILE_NAME))
isfile(joinpath(Genie.ENV_PATH, ENV["GENIE_ENV"] * ".jl")) && Base.include(context, joinpath(Genie.ENV_PATH, ENV["GENIE_ENV"] * ".jl"))
Expand All @@ -44,13 +46,20 @@ using .Loggers, .Configuration


"""
newmodel(model_name::String; context = @__MODULE__) :: Nothing
newmodel(model_name::String; context::Union{Module,Nothing} = nothing) :: Nothing
Creates a new SearchLight `model` file.
"""
function newmodel(model_name::String; context::Module = @__MODULE__) :: Nothing
Core.eval(context, :(SearchLight.Generator.newmodel($model_name)))
load_resources()
function newmodel(model_name::String; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

try
Core.eval(context, :(SearchLight.Generator.newmodel($model_name)))

load_resources()
catch ex
@error ex
end

nothing
end
Expand All @@ -70,18 +79,20 @@ end


"""
newresource(resource_name::String; pluralize::Bool = true, context::Module = @__MODULE__) :: Nothing
newresource(resource_name::String; 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::Module = @__MODULE__) :: Nothing
function newresource(resource_name::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)

try
Core.eval(context, :(SearchLight.Generator.newresource(uppercasefirst($resource_name))))
catch ex
log(ex, :error)
@error ex
log("Skipping SearchLight", :warn)
end

Expand All @@ -92,24 +103,36 @@ end


"""
newmigration(migration_name::String, context::Module = @__MODULE__) :: Nothing
newmigration(migration_name::String, context::Union{Module,Nothing} = nothing) :: Nothing
Creates a new SearchLight migration file.
"""
function newmigration(migration_name::String; context::Module = @__MODULE__) :: Nothing
Core.eval(context, :(SearchLight.Generator.new_migration(Dict{String,Any}("migration:new" => $migration_name))))
function newmigration(migration_name::String; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

try
Core.eval(context, :(SearchLight.Generator.new_migration(Dict{String,Any}("migration:new" => $migration_name))))
catch ex
@error ex
end

nothing
end


"""
newtablemigration(migration_name::String) :: Nothing
newtablemigration(migration_name::String, context::Union{Module,Nothing} = nothing) :: Nothing
Creates a new migration prefilled with code for creating a new table.
"""
function newtablemigration(migration_name::String; context::Module = @__MODULE__) :: Nothing
Core.eval(context, :(SearchLight.Generator.new_table_migration(Dict{String,Any}("migration:new" => $migration_name))))
function newtablemigration(migration_name::String; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

try
Core.eval(context, :(SearchLight.Generator.new_table_migration(Dict{String,Any}("migration:new" => $migration_name))))
catch ex
@error ex
end

nothing
end
Expand Down Expand Up @@ -197,12 +220,14 @@ end


"""
load_configurations(root_dir::String = CONFIG_PATH, context::Module = @__MODULE__) :: Nothing
load_configurations(root_dir::String = CONFIG_PATH; context::Union{Module,Nothing} = nothing) :: Nothing
Loads (includes) the framework's configuration files into the app's module `context`.
The files are set up with `Revise` to be automatically reloaded.
"""
function load_configurations(root_dir::String = Genie.CONFIG_PATH; context::Module = @__MODULE__) :: Nothing
function load_configurations(root_dir::String = Genie.CONFIG_PATH; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

secrets_path = joinpath(root_dir, Genie.SECRETS_FILE_NAME)
isfile(secrets_path) && Revise.track(context, secrets_path, define = true)

Expand All @@ -211,12 +236,14 @@ end


"""
load_initializers(root_dir::String = CONFIG_PATH, context::Module = @__MODULE__) :: Nothing
load_initializers(root_dir::String = CONFIG_PATH; context::Union{Module,Nothing} = nothing) :: Nothing
Loads (includes) the framework's initializers.
The files are set up with `Revise` to be automatically reloaded.
"""
function load_initializers(root_dir::String = Genie.CONFIG_PATH; context::Module = @__MODULE__) :: Nothing
function load_initializers(root_dir::String = Genie.CONFIG_PATH; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

dir = joinpath(root_dir, Genie.INITIALIZERS_FOLDER)

isdir(dir) || return nothing
Expand All @@ -232,11 +259,13 @@ end


"""
load_plugins(root_dir::String = PLUGINS_PATH; context::Module = @__MODULE__) :: Nothing
load_plugins(root_dir::String = PLUGINS_PATH; context::Union{Module,Nothing} = nothing) :: Nothing
Loads (includes) the framework's plugins initializers.
"""
function load_plugins(root_dir::String = Genie.PLUGINS_PATH; context::Module = @__MODULE__) :: Nothing
function load_plugins(root_dir::String = Genie.PLUGINS_PATH; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

isdir(root_dir) || return nothing

for i in readdir(root_dir)
Expand All @@ -249,25 +278,29 @@ end


"""
load_routes_definitions(routes_file::String = Genie.ROUTES_FILE_NAME, context::Module = @__MODULE__) :: Nothing
load_routes_definitions(routes_file::String = Genie.ROUTES_FILE_NAME; context::Union{Module,Nothing} = nothing) :: Nothing
Loads the routes file.
"""
function load_routes_definitions(routes_file::String = Genie.ROUTES_FILE_NAME; context::Module = @__MODULE__) :: Nothing
function load_routes_definitions(routes_file::String = Genie.ROUTES_FILE_NAME; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

isfile(routes_file) && Revise.track(context, routes_file, define = true)

nothing
end


"""
secret_token(; context::Module = @__MODULE__) :: String
secret_token(; context::Union{Module,Nothing} = nothing) :: String
Wrapper around /config/secrets.jl SECRET_TOKEN `const`.
Sets up the secret token used in the app for encryption and salting.
If there isn't a valid secrets file, a temporary secret token is generated for the current session only.
"""
function secret_token(; context::Module = @__MODULE__) :: String
function secret_token(; context::Union{Module,Nothing} = nothing) :: String
context = default_context(context)

if isdefined(context, :SECRET_TOKEN)
context.SECRET_TOKEN
else
Expand All @@ -284,11 +317,28 @@ end


"""
load(; context::Module = @__MODULE__) :: Nothing
default_context(context::Union{Module,Nothing})
Sets the module in which the code is loaded (the app's module)
"""
function default_context(context::Union{Module,Nothing})
try
context === nothing ? Main.UserApp : context
catch ex
@error ex
@__MODULE__
end
end


"""
load(; context::Union{Module,Nothing} = nothing) :: Nothing
Main entry point to loading a Genie app.
"""
function load(; context::Module = @__MODULE__) :: Nothing
function load(; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

App.bootstrap(context)

load_configurations(context = context)
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Core genie configuration / settings functionality.
"""
module Configuration

const GENIE_VERSION = v"0.14.0"
const GENIE_VERSION = v"0.15.0"

using YAML
using Genie
Expand Down
4 changes: 3 additions & 1 deletion src/Generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ Writes files used for interacting with the SearchLight ORM.
"""
function db_support(app_path::String = ".") :: Nothing
cp(joinpath(@__DIR__, "..", Genie.NEW_APP_PATH, Genie.DB_PATH), joinpath(app_path, Genie.DB_PATH))
cp(joinpath(@__DIR__, "..", Genie.NEW_APP_PATH, Genie.INITIALIZERS_PATH, Genie.SEARCHLIGHT_INITIALIZER_FILE_NAME), joinpath(app_path, Genie.INITIALIZERS_PATH, Genie.SEARCHLIGHT_INITIALIZER_FILE_NAME))

initializer_path = joinpath(app_path, Genie.INITIALIZERS_PATH, Genie.SEARCHLIGHT_INITIALIZER_FILE_NAME)
isfile(initializer_path) || cp(joinpath(@__DIR__, "..", Genie.NEW_APP_PATH, Genie.INITIALIZERS_PATH, Genie.SEARCHLIGHT_INITIALIZER_FILE_NAME), initializer_path)

nothing
end
Expand Down
4 changes: 2 additions & 2 deletions src/Genie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Genie

push!(LOAD_PATH, @__DIR__)

include(joinpath(@__DIR__, "Configuration.jl"))
include(joinpath(@__DIR__, "constants.jl"))
include("Configuration.jl")
include("constants.jl")

config = Configuration.Settings(app_env = Configuration.DEV)

Expand Down
13 changes: 12 additions & 1 deletion src/Requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Requests
using Genie, Genie.Router, Genie.Input
using HTTP

export jsonpayload, rawpayload, filespayload, postpayload, getpayload, getrequest, infilespayload, download, filename, payload
export jsonpayload, rawpayload, filespayload, postpayload, getpayload, getrequest
export infilespayload, download, filename, payload, read


"""
Expand Down Expand Up @@ -70,6 +71,16 @@ Saves uploaded `HttpFile` `file` to local storage under the `name` filename.
end


"""
read(file::HttpFile)
Returns the content of `file` as string.
"""
@inline function Base.read(file::HttpFile, ::Type{String}) :: String
file.data |> String
end


"""
filename(file::HttpFile) :: String
Expand Down
Loading

2 comments on commit 4b653b8

@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/2878

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.15.0 -m "<description of version>" 4b653b8bf2102d1d048e996b00392cbdea6939cd
git push origin v0.15.0

Please sign in to comment.