Skip to content

Commit

Permalink
pm respond to README (#3678)
Browse files Browse the repository at this point in the history
Allow project manager to respond to README.{txt,md} files in the project and display them in a collapsible menu.
  • Loading branch information
ashton22305 authored Jul 26, 2024
1 parent 1f75395 commit 943e81a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/dashboard/app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions apps/dashboard/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@
<%= render(partial: 'job_details', collection: @project.jobs, as: :job) %>
</div>
</div>
<% unless @project.readme_path.nil? %>
<div class="card">
<div class="card-header">
<button class="btn btn-default fa fa-chevron-right" type="button" data-bs-toggle="collapse" data-bs-target="#readme" aria-expanded="true" aria-controls="readme"></button>
<%= File.basename(@project.readme_path) %>
</div>
<div class="card-body collapse show" id="readme">
<%= render_readme(@project.readme_path) %>
</div>
</div>
<% end %>

0 comments on commit 943e81a

Please sign in to comment.