diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db0987cf..4e68b7f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,9 +38,9 @@ jobs: matrix: stable: [true] crystal: - - 1.0.0 - - 1.1.1 - 1.2.2 + - 1.3.2 + - 1.4.0 include: - crystal: nightly stable: false diff --git a/shard.lock b/shard.lock index be4333c1..cdce1160 100644 --- a/shard.lock +++ b/shard.lock @@ -14,11 +14,11 @@ shards: exception_page: git: https://github.com/crystal-loot/exception_page.git - version: 0.2.0 + version: 0.2.2 kemal: git: https://github.com/kemalcr/kemal.git - version: 1.1.0 + version: 1.1.2 kilt: git: https://github.com/jeromegn/kilt.git diff --git a/shard.yml b/shard.yml index bf382ec3..9c9b0d37 100644 --- a/shard.yml +++ b/shard.yml @@ -18,7 +18,10 @@ dependencies: version: ~> 0.18.0 kemal: github: kemalcr/kemal - version: ~> 1.1.0 + 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/helpers/static_file_handler.cr b/src/ext/kemal_static_file_handler.cr similarity index 100% rename from src/invidious/helpers/static_file_handler.cr rename to src/ext/kemal_static_file_handler.cr diff --git a/src/invidious.cr b/src/invidious.cr index 9f3d5d10..dd240852 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -16,7 +16,13 @@ require "digest/md5" require "file_utils" + +# Require kemal, kilt, then our own overrides require "kemal" +require "kilt" +require "./ext/kemal_content_for.cr" +require "./ext/kemal_static_file_handler.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 diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 5f8bde13..ce7af783 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -52,11 +52,11 @@ <% if !env.get("preferences").as(Preferences).thin_mode %>