Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm respond to README #3678

Merged
merged 10 commits into from
Jul 26, 2024
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 %>
Loading