scinote-web/app/serializers/step_text_serializer.rb

35 lines
784 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class StepTextSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
2022-05-10 19:28:09 +08:00
include ApplicationHelper
include ActionView::Helpers::TextHelper
2022-05-10 19:28:09 +08:00
attributes :id, :text, :urls, :text_view, :updated_at
def updated_at
object.updated_at.to_i
end
def text_view
@user = scope[:user]
custom_auto_link(object.tinymce_render('text'),
simple_format: false,
tags: %w(img),
team: object.step.protocol.team)
end
def text
sanitize_input(object.tinymce_render('text'))
end
def urls
2022-05-04 16:25:53 +08:00
return if object.destroyed?
{
2022-05-10 19:28:09 +08:00
delete_url: step_text_path(object.step, object),
update_url: step_text_path(object.step, object)
}
end
end