diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2022-04-10 22:53:03 +0200 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2022-04-16 22:48:24 +0200 |
| commit | 1f66d7ef7471acb07642bb3b8132d824877176fb (patch) | |
| tree | 8915fc538ef1cef808e96b468e15b90e99a2cf23 | |
| parent | 84b6429ca65ae407e4257fc771f4b760af72d310 (diff) | |
| download | invidious-1f66d7ef7471acb07642bb3b8132d824877176fb.tar.gz invidious-1f66d7ef7471acb07642bb3b8132d824877176fb.tar.bz2 invidious-1f66d7ef7471acb07642bb3b8132d824877176fb.zip | |
Keep using kilt for rendering
Directly using Crystal's ECR seems to be causing issues, so
don't use kemal's 'render' macro and patch 'content_for' to
have the same behavior as before Kemal v1.1.1
| -rw-r--r-- | shard.lock | 4 | ||||
| -rw-r--r-- | shard.yml | 3 | ||||
| -rw-r--r-- | src/ext/kemal_content_for.cr | 16 | ||||
| -rw-r--r-- | src/invidious.cr | 5 | ||||
| -rw-r--r-- | src/invidious/helpers/macros.cr | 12 |
5 files changed, 37 insertions, 3 deletions
@@ -20,6 +20,10 @@ shards: git: https://github.com/kemalcr/kemal.git version: 1.1.2 + kilt: + git: https://github.com/jeromegn/kilt.git + version: 0.6.1 + lsquic: git: https://github.com/iv-org/lsquic.cr.git version: 2.18.1-2 @@ -19,6 +19,9 @@ dependencies: kemal: github: kemalcr/kemal version: ~> 1.1.2 + kilt: + github: jeromegn/kilt + version: ~> 0.6.1 protodec: github: iv-org/protodec version: ~> 0.1.4 diff --git a/src/ext/kemal_content_for.cr b/src/ext/kemal_content_for.cr new file mode 100644 index 00000000..a4f3fd96 --- /dev/null +++ b/src/ext/kemal_content_for.cr @@ -0,0 +1,16 @@ +# Overrides for Kemal's `content_for` macro in order to keep using +# kilt as it was before Kemal v1.1.1 (Kemal PR #618). + +require "kemal" +require "kilt" + +macro content_for(key, file = __FILE__) + %proc = ->() { + __kilt_io__ = IO::Memory.new + {{ yield }} + __kilt_io__.to_s + } + + CONTENT_FOR_BLOCKS[{{key}}] = Tuple.new {{file}}, %proc + nil +end diff --git a/src/invidious.cr b/src/invidious.cr index 9f3d5d10..631a6e78 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -16,7 +16,12 @@ require "digest/md5" require "file_utils" + +# Require kemal, kilt, then our own overrides require "kemal" +require "kilt" +require "./ext/kemal_content_for.cr" + require "athena-negotiation" require "openssl/hmac" require "option_parser" diff --git a/src/invidious/helpers/macros.cr b/src/invidious/helpers/macros.cr index 75df1612..43e7171b 100644 --- a/src/invidious/helpers/macros.cr +++ b/src/invidious/helpers/macros.cr @@ -48,13 +48,19 @@ module JSON::Serializable end end -macro templated(filename, template = "template", navbar_search = true) +macro templated(_filename, template = "template", navbar_search = true) navbar_search = {{navbar_search}} - render "src/invidious/views/#{{{filename}}}.ecr", "src/invidious/views/#{{{template}}}.ecr" + + {{ filename = "src/invidious/views/" + _filename + ".ecr" }} + {{ layout = "src/invidious/views/" + template + ".ecr" }} + + __content_filename__ = {{filename}} + content = Kilt.render({{filename}}) + Kilt.render({{layout}}) end macro rendered(filename) - render "src/invidious/views/#{{{filename}}}.ecr" + Kilt.render("src/invidious/views/#{{{filename}}}.ecr") end # Similar to Kemals halt method but works in a |
