Skip to content

Commit

Permalink
rendering refactoring, no asset pipeline by default, autoregister web…
Browse files Browse the repository at this point in the history
…components, webchannels enhancements, cleanup, docs updates
  • Loading branch information
Adrian Salceanu committed Jul 17, 2019
1 parent 544dd7e commit 2f90c13
Show file tree
Hide file tree
Showing 66 changed files with 241 additions and 15,089 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2017 Adrian Salceanu
Copyright (c) 2016-2019 Adrian Salceanu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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.9.6"
version = "0.9.7"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ In a Julia session switch to `pkg>` mode to add `Genie`:

```julia
julia>] # switch to pkg> mode
pkg> add https://github.com/genieframework/Genie.jl
```

Alternatively, you can achieve the above using the `Pkg` API:

```julia
julia> using Pkg
julia> pkg"add https://github.com/genieframework/Genie.jl"
pkg> add Genie
```

When finished, make sure that you're back to the Julian prompt (`julia>`)
Expand All @@ -43,7 +36,7 @@ julia> using Genie

## Using Genie

Genie can be used for a variety of tasks, from quickly whipping up a web server to full MVC web apps.
Genie can be used for a variety of tasks, from quickly whipping up a web server to full MVC web apps.
Use the following resources to dive into each use case.

[Using Genie in an interactive environment (Jupyter/IJulia, REPL, etc)](docs/content/Interactive_environment.md)
Expand Down
14 changes: 7 additions & 7 deletions docs/content/Simple_API_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Genie makes it very easy to quickly set up a REST API backend. All it takes is a
```julia
using Genie
import Genie.Router: route
import Genie.Renderer: json!
import Genie.Renderer: json

Genie.config.run_as_server = true

route("/") do
(:message => "Hi there!") |> json!
(:message => "Hi there!") |> json
end

Genie.startup()
```

The key bit here is `Genie.config.run_as_server = true`. This will start the server synchronously so the `startup()` function won't return.
The key bit here is `Genie.config.run_as_server = true`. This will start the server synchronously so the `startup()` function won't return.
This endpoint can be run directly from the command line - if say, you save the code in a `rest.jl` file:

```shell
Expand All @@ -33,19 +33,19 @@ using HTTP

route("/echo", method = POST) do
message = jsonpayload()
(:echo => (message["message"] * " ") ^ message["repeat"]) |> json!
(:echo => (message["message"] * " ") ^ message["repeat"]) |> json
end

route("/send") do
response = HTTP.request("POST", "http://localhost:8000/echo", [("Content-Type", "application/json")], """{"message":"hello", "repeat":3}""")

response.body |> String |> json!
response.body |> String |> json
end

Genie.startup(async = false)
```

Here we define two routes, `/send` and `/echo`. The `send` route makes a `HTTP` request over `POST` to `/echo`, sending a JSON payload with two values, `message` and `repeat`.
Here we define two routes, `/send` and `/echo`. The `send` route makes a `HTTP` request over `POST` to `/echo`, sending a JSON payload with two values, `message` and `repeat`.
In the `/echo` route, we grab the JSON payload using the `Requests.jsonpayload()` function, extract the values from the JSON object, and output the `message` value repeated for a number of times equal to the `repeat` value.

If you run the code, the output should be
Expand All @@ -56,5 +56,5 @@ If you run the code, the output should be
}
```

If the payload contains invalid JSON, the `jsonpayload` will be set to `nothing`. You can still access the raw payload by using the `Requests.rawpayload()` function.
If the payload contains invalid JSON, the `jsonpayload` will be set to `nothing`. You can still access the raw payload by using the `Requests.rawpayload()` function.
You can also use `rawpayload` if for example the type of request/payload is not JSON.
9 changes: 8 additions & 1 deletion docs/content/Working_with_Genie_apps/Frontend_assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ As summary:

## Requirements

You will need NodeJS as well as Yarn to be installed on system. If using Linux, MacOS your package manager should easily allow this. Windows please download relevant installer from NodeJS project webpage.
** In order for the Genie app to install the asset pipeline the app needs to be created using the `fullstack = true` option, as in: **

```julia
julia> Genie.newapp("MyApp", fullstack = true)
```


You will need NodeJS as well as Yarn to be installed on system. If using Linux, macOS your package manager should easily allow this. Windows please download relevant installer from NodeJS project webpage.

## Installing dependencies

Expand Down
22 changes: 11 additions & 11 deletions docs/content/Working_with_Genie_apps/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ end

That should be clear enough. Our controller is just a plain Julia module where we define a `Book` type and set up an array of book objects.
We then define a function, `billgatesbooks`, which returns a HTML string, with a heading an an unordered list of all the books.
The plan is to map this function to a route and expose it on the internet.
The plan is to map this function to a route and expose it on the internet.

#### Checkpoint

Expand Down Expand Up @@ -362,7 +362,7 @@ It's a simple change in the `BookiesController`: we have to explicitly tell Geni
```julia
# BooksController.jl
function billgatesbooks()
html!(:books, "billgatesbooks.jl.md", books = BillGatesBooks)
html(:books, "billgatesbooks.jl.md", books = BillGatesBooks)
end
```

Expand Down Expand Up @@ -447,7 +447,7 @@ Update the `billgatesbooks` function to look like this:
```julia
# BooksController.jl
function billgatesbooks()
html!(:books, :billgatesbooks, :admin, books = BillGatesBooks)
html(:books, :billgatesbooks, :admin, books = BillGatesBooks)
end
```

Expand Down Expand Up @@ -492,7 +492,7 @@ const BillGatesBooks = Book[
]

function billgatesbooks()
html!(:books, Symbol("billgatesbooks.jl.html"), books = BillGatesBooks)
html(:books, Symbol("billgatesbooks.jl.html"), books = BillGatesBooks)
end


Expand All @@ -515,7 +515,7 @@ Keep in mind that you're free to organize the code as you see fit – not necess
If you go to `http://localhost:8000/api/v1/bgbooks` it should already work.

Not a bad start, but we can do better. First, the MIME type of the response is not right. By default Genie will return `text/html`.
We need `application/json`. That's easy to fix though, we can just use Genie's `respond` method. The `API` submodule should look like this:
We need `application/json`. That's easy to fix though, we can just use Genie's `json` method. The `API` submodule should look like this:

```julia
module API
Expand All @@ -525,7 +525,7 @@ using Genie.Renderer
using JSON

function billgatesbooks()
respond(JSON.json(BooksController.BillGatesBooks), "application/json")
json(JSON.json(BooksController.BillGatesBooks))
end

end
Expand Down Expand Up @@ -557,11 +557,11 @@ Final step, instructing `BooksController` to render the view:

```julia
function billgatesbooks()
json!(:books, :billgatesbooks, books = BooksController.BillGatesBooks)
json(:books, :billgatesbooks, books = BooksController.BillGatesBooks)
end
```

This should hold no surprises – the `json!` function is similar to the `html!` one we've seen before.
This should hold no surprises – the `json` function is similar to the `html` one we've seen before.

That's all – everything should work!

Expand Down Expand Up @@ -890,7 +890,7 @@ module BooksController
using Genie.Renderer, SearchLight, Books

function billgatesbooks()
html!(:books, :billgatesbooks, books = SearchLight.all(Book))
html(:books, :billgatesbooks, books = SearchLight.all(Book))
end

module API
Expand All @@ -901,7 +901,7 @@ using SearchLight, Books
using JSON

function billgatesbooks()
json!(:books, :billgatesbooks, books = SearchLight.all(Book))
json(:books, :billgatesbooks, books = SearchLight.all(Book))
end

end
Expand Down Expand Up @@ -960,7 +960,7 @@ Now, to add the methods in `BooksController`. Add these definition under the `bi
```julia
# BooksController.jl
function new()
html!(:books, :new)
html(:books, :new)
end

function create()
Expand Down
20 changes: 0 additions & 20 deletions files/new_app/LICENSE.md

This file was deleted.

Loading

2 comments on commit 2f90c13

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

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.9.7 -m "<description of version>" 2f90c135d1fa679a7f1f6a39dc9ff9a0d6f36feb
git push origin v0.9.7

Also, note the warning: Version 0.9.7 skips over 0.9.6
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.