From 3dc66fc05eaddfb80ef8e56fbc5e2d8dda90f8ee Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Thu, 28 May 2026 16:49:40 -0300 Subject: [PATCH 1/2] IIRR-34: Render puzzles's code with code-style --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/helpers/application_helper.rb | 3 +++ app/views/puzzles/_puzzles_table.html.erb | 4 ++-- app/views/puzzles/update.turbo_stream.erb | 4 ++-- db/seeds.rb | 29 +++++++++++++---------- test/fixtures/puzzles.yml | 4 ++-- test/helpers/markdown_helper_test.rb | 27 +++++++++++++++++++++ 8 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 test/helpers/markdown_helper_test.rb diff --git a/Gemfile b/Gemfile index 3acef3a..156ae5c 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,8 @@ gem "stimulus-rails" # Build JSON APIs with ease [https://github.com/rails/jbuilder] gem "jbuilder" +gem "redcarpet" + # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] # gem "bcrypt", "~> 3.1.7" diff --git a/Gemfile.lock b/Gemfile.lock index 66d6c35..62b9f0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -381,6 +381,7 @@ GEM rdoc (6.14.1) erb psych (>= 4.0.0) + redcarpet (3.6.1) redis-client (0.24.0) connection_pool regexp_parser (2.10.0) @@ -590,6 +591,7 @@ DEPENDENCIES propshaft puma (>= 5.0) rails (~> 8.0.2) + redcarpet rubocop-rails-omakase selenium-webdriver sentry-rails diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..ce36e2a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def markdown(text) + RedcarpetCompat.new(text, :fenced_code).to_html.html_safe + end end diff --git a/app/views/puzzles/_puzzles_table.html.erb b/app/views/puzzles/_puzzles_table.html.erb index a880c95..eeca005 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -15,9 +15,9 @@ <% puzzles.each do |puzzle| %> - <%= simple_format(puzzle.question) %> + <%= markdown(puzzle.question) %> <%= puzzle.answer %> - <%= puzzle.explanation %> + <%= markdown(puzzle.explanation) %> <% if puzzle.link.present? %> <%= link_to 'View', puzzle.link, target: '_blank' %> diff --git a/app/views/puzzles/update.turbo_stream.erb b/app/views/puzzles/update.turbo_stream.erb index 8f26218..e9dd213 100644 --- a/app/views/puzzles/update.turbo_stream.erb +++ b/app/views/puzzles/update.turbo_stream.erb @@ -1,9 +1,9 @@