From d1f991d8e73fa13a0f8bd62dfbd2900d84929cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Cez=C3=A1rio=20Barreto?= Date: Sat, 29 Nov 2025 21:28:31 +0000 Subject: [PATCH] render_any will ignore render extension in file request path --- app.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app.rb b/app.rb index 7a0adf9..750d2c2 100644 --- a/app.rb +++ b/app.rb @@ -8,6 +8,10 @@ class TonTonWeb::App < Sinatra::Base # Renders a view by the filename without the extension (without a predefined render) # TODO: pass this to tonton-web code def render_any template_name, base_dir, options = {} + for extension in ['.markdown', '.erb'] + template_name.delete_suffix!(extension) + end + views_root = settings.views || "./views" # Search for any file with the given name and any extension @@ -29,15 +33,7 @@ class TonTonWeb::App < Sinatra::Base file_path = "#{base_dir}/#{template_name}" - extension = File.extname(filename).delete('.') - - engine = case extension - when 'md', 'markdown' then :markdown - when 'erb' then :erb - else - # Fallback: try to use the extension name as the method - extension.to_sym - end + engine = File.extname(filename).delete('.').to_sym # Dynamically call the correct Sinatra method (e.g., erb :hello, markdown :hello) # We use 'send' to call the method by its name symbol