1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/services/project_to_markdown.rb

89 lines
2.4 KiB
Ruby
Raw Normal View History

2023-06-29 16:37:16 +02:00
class ProjectToMarkdown
attr_reader :project
def initialize(project)
@project = project
end
def call
md = []
md << "# #{project.name}"
md << "![#{I18n.t('app.shared.project.illustration')}](#{full_url(project.project_image.attachment.url)})" if project.project_image
md << ReverseMarkdown.convert(project.description.to_s)
2023-06-30 11:15:37 +02:00
project_steps = project.project_steps
2023-06-29 16:37:16 +02:00
if project_steps.present?
md << "## #{I18n.t('app.shared.project.steps')}"
project_steps.each do |project_step|
md << "### #{I18n.t('app.shared.project.step_N').gsub('{INDEX}', project_step.step_nb.to_s)} : #{project_step.title}"
md << ReverseMarkdown.convert(project_step.description.to_s)
project_step.project_step_images.each_with_index do |image, i|
md << "![#{I18n.t('app.shared.project.step_image')} #{i+1}](#{full_url(image.attachment.url)})"
2023-06-29 16:37:16 +02:00
end
end
end
2023-06-30 11:15:37 +02:00
md << "## #{I18n.t('app.shared.project.author')}"
md << project.author&.user&.profile&.full_name
2023-06-29 16:37:16 +02:00
if project.themes.present?
md << "## #{I18n.t('app.shared.project.themes')}"
md << project.themes.map(&:name).join(', ')
end
if project.project_caos.present?
md << "## #{I18n.t('app.shared.project.CAD_files')}"
project.project_caos.each do |cao|
md << "![#{cao.attachment_identifier}](#{full_url(cao.attachment_url)})"
end
end
2023-06-30 11:15:37 +02:00
if project.status
md << "## #{I18n.t('app.shared.project.status')}"
md << project.status.name
end
2023-06-29 16:37:16 +02:00
if project.machines.present?
md << "## #{I18n.t('app.shared.project.employed_machines')}"
md << project.machines.map(&:name).join(', ')
end
if project.components.present?
md << "## #{I18n.t('app.shared.project.employed_materials')}"
md << project.components.map(&:name).join(', ')
end
2023-06-30 11:15:37 +02:00
if project.users.present?
2023-06-29 16:37:16 +02:00
md << "## #{I18n.t('app.shared.project.collaborators')}"
2023-06-30 11:15:37 +02:00
md << project.users.map { |u| u.profile.full_name }.join(', ')
2023-06-29 16:37:16 +02:00
end
if project.licence.present?
md << "## #{I18n.t('app.shared.project.licence')}"
md << project.licence.name
end
if project.tags.present?
md << "## #{I18n.t('app.shared.project.tags')}"
md << project.tags
end
md = md.reject { |line| line.blank? }
md.join("\n\n")
end
private
def full_url(path)
"#{Rails.application.routes.url_helpers.root_url[...-1]}#{path}"
end
end