From 943e81a1fa3c42f1446e4c60bcc62cf908ca947f Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 26 Jul 2024 10:04:35 -0400 Subject: [PATCH] pm respond to README (#3678) Allow project manager to respond to README.{txt,md} files in the project and display them in a collapsible menu. --- apps/dashboard/app/helpers/projects_helper.rb | 17 +++++++++++++++++ apps/dashboard/app/models/project.rb | 5 +++++ apps/dashboard/app/views/projects/show.html.erb | 11 +++++++++++ 3 files changed, 33 insertions(+) create mode 100644 apps/dashboard/app/helpers/projects_helper.rb diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb new file mode 100644 index 0000000000..c725ac7b8b --- /dev/null +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# Helpers for the projects page +module ProjectsHelper + def render_readme(readme_location) + file_content = File.read(readme_location) + + if File.extname(readme_location) == '.md' + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML) + markdown_html = markdown.render(file_content).html_safe + sanitize(markdown_html) + elsif File.extname(readme_location) == '.txt' + # simple_format sanitizes its output + simple_format(file_content) + end + end +end \ No newline at end of file diff --git a/apps/dashboard/app/models/project.rb b/apps/dashboard/app/models/project.rb index 0cf98fde7a..7cf2553486 100644 --- a/apps/dashboard/app/models/project.rb +++ b/apps/dashboard/app/models/project.rb @@ -203,6 +203,11 @@ def jobs end.flatten end + def readme_path + file = Dir.glob("#{directory}/README.{md,txt}").first.to_s + File.readable?(file) ? file : nil + end + private def update_attrs(attributes) diff --git a/apps/dashboard/app/views/projects/show.html.erb b/apps/dashboard/app/views/projects/show.html.erb index d849b26b04..9ea4765224 100644 --- a/apps/dashboard/app/views/projects/show.html.erb +++ b/apps/dashboard/app/views/projects/show.html.erb @@ -60,3 +60,14 @@ <%= render(partial: 'job_details', collection: @project.jobs, as: :job) %> +<% unless @project.readme_path.nil? %> +
+
+ + <%= File.basename(@project.readme_path) %> +
+
+ <%= render_readme(@project.readme_path) %> +
+
+<% end %> \ No newline at end of file