Skip to content
Snippets Groups Projects
Unverified Commit 1b5417f9 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

publish media blobs

parent c31e0b52
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@
class Communication::Website::Page < ApplicationRecord
include WithGithub
include Communication::Website::WithMedia
include WithSlug
include WithTree
......
......@@ -31,6 +31,7 @@
#
class Communication::Website::Post < ApplicationRecord
include WithGithub
include Communication::Website::WithMedia
include WithSlug
has_rich_text :text
......
module Communication::Website::WithMedia
extend ActiveSupport::Concern
protected
def active_storage_blobs
blob_ids = [featured_image&.blob_id, text.embeds.blobs.pluck(:id)].flatten.compact
university.active_storage_blobs.where(id: blob_ids)
end
def publish_to_github
super
active_storage_blobs.each do |blob|
blob.analyze unless blob.analyzed?
github.publish(path: "_media/#{blob.id}.md",
commit: "[Medium] Save ##{ blob.id }",
data: blob_to_jekyll(blob))
end
end
def blob_to_jekyll(blob)
ApplicationController.render(
template: 'active_storage/blobs/jekyll',
layout: false,
assigns: { blob: blob }
)
end
end
......@@ -25,9 +25,15 @@ class University < ApplicationRecord
has_one_attached_deletable :logo
# Can't use dependent: :destroy because of attachments
# We use after_destroy to let the attachment go first
has_many :active_storage_blobs, class_name: 'ActiveStorage::Blob'
validates_presence_of :name
validates :sms_sender_name, presence: true, length: { maximum: 11 }
after_destroy :destroy_remaining_blobs
scope :ordered, -> { order(:name) }
def to_s
......@@ -43,4 +49,10 @@ class University < ApplicationRecord
full: "#{name} <#{address}>"
}
end
private
def destroy_remaining_blobs
active_storage_blobs.delete_all
end
end
<%
width, height = @blob.metadata.values_at('width', 'height')
ratio = width.present? && height.present? ? (width.to_f / height.to_f) : nil
%>
---
name: <%= @blob.filename.to_s %>
size: <%= @blob.byte_size %>
<% if width.present? %>width: <%= width %><% end %>
<% if height.present? %>height: <%= height %><% end %>
<% if ratio.present? %>ratio: <%= ratio %><% end %>
<%# TODO: Replace with the media endpoint when it's ready %>
url: <%= @blob.url %>
---
init.js 0 → 100644
/*global window, document, $ */
window.b2bylon.training.paths = {
invoke: function () {
'use strict';
return {
init: this.init.bind(this)
};
},
init: function () {
'use strict';
this.$kindSelect = $('select#features_training_path_kind');
if (!this.$kindSelect.length) {
return;
}
this.$folderKindForms = $('.kind-folder');
this.$activityKindForms = $('.kind-activity');
this.$activityField = $('input#features_training_path_activity_uid');
this.$kindSelect.on('change', this.kindChanged.bind(this));
this.kindChanged();
},
kindChanged: function () {
'use strict';
if (this.$kindSelect.val() === 'activity') {
this.$folderKindForms.hide();
$('.form-group.required select, .form-group.required input', this.$folderKindForms).removeAttr('required');
this.$activityKindForms.show();
$('.form-group.required select, .form-group.required input', this.$activityKindForms).attr('required', 'required');
} else {
this.$folderKindForms.show();
$('.form-group.required select, .form-group.required input', this.$folderKindForms).attr('required', 'required');
this.$activityKindForms.hide();
$('.form-group.required select, .form-group.required input', this.$activityKindForms).removeAttr('required', 'required');
}
}
}.invoke();
document.addEventListener('DOMContentLoaded', function () {
'use strict';
window.b2bylon.training.paths.init();
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment