2022-11-22 17:43:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Provides methods to sync projects on OpenLab
|
|
|
|
class OpenLabService
|
|
|
|
class << self
|
|
|
|
def to_hash(project)
|
|
|
|
{
|
|
|
|
id: project.id,
|
|
|
|
slug: project.slug,
|
|
|
|
name: project.name,
|
|
|
|
description: project.description,
|
|
|
|
tags: project.tags,
|
|
|
|
machines: project.machines.map(&:name),
|
|
|
|
components: project.components.map(&:name),
|
|
|
|
themes: project.themes.map(&:name),
|
|
|
|
author: project.author&.user&.profile&.full_name,
|
|
|
|
collaborators: project.users.map { |u| u&.profile&.full_name },
|
|
|
|
steps_body: steps_body(project),
|
|
|
|
image_path: project.project_image&.attachment&.medium&.url,
|
|
|
|
project_path: "/#!/projects/#{project.slug}",
|
2023-09-27 15:36:19 +02:00
|
|
|
updated_at: project.updated_at.to_fs(:iso8601),
|
|
|
|
created_at: project.created_at.to_fs(:iso8601),
|
|
|
|
published_at: project.published_at.to_fs(:iso8601)
|
2022-11-22 17:43:19 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def steps_body(project)
|
|
|
|
concatenated_steps = project.project_steps.map { |s| "#{s.title} #{s.description}" }
|
|
|
|
.join(' ').gsub('</p>', ' </p>')
|
|
|
|
.gsub("\r\n", ' ').gsub("\n\r", ' ')
|
|
|
|
.gsub("\n", ' ').gsub("\r", ' ').gsub("\t", ' ')
|
|
|
|
|
2023-09-27 15:36:19 +02:00
|
|
|
ActionController::Base.helpers.strip_tags(concatenated_steps).strip
|
2022-11-22 17:43:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|