Skip to content
Snippets Groups Projects
Commit 4fd6e8a4 authored by pabois's avatar pabois
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents e451f46d a01e7327
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@
clear: both
.form-group
margin-top: 10px
::-webkit-calendar-picker-indicator
filter: invert(1)
.controller-users .sfpwh-password-toggle
top: 35px
......@@ -39,12 +39,10 @@ class Communication::Website::Menu < ApplicationRecord
end
def github_path_generated
"_data/menus.yml"
"_data/menus/#{identifier}.yml"
end
def to_jekyll
website.menus.map { |menu|
[menu.identifier, menu.items.root.ordered.map(&:to_jekyll_hash)]
}.to_h.to_yaml
items.root.ordered.map(&:to_jekyll_hash).to_yaml
end
end
......@@ -7,6 +7,9 @@ module Communication::Website::WithBatchPublication
publish_categories!
publish_pages!
publish_posts!
publish_menus!
publish_school! if about.is_a?(Education::School)
publish_journal! if about.is_a?(Research::Journal)
end
handle_asynchronously :force_publish!, queue: 'default'
......@@ -26,9 +29,26 @@ module Communication::Website::WithBatchPublication
publish_objects_with_blobs(Communication::Website::Post, posts)
end
def publish_menus!
publish_objects(Communication::Website::Menu, menus)
end
def publish_school!
github.publish(path: about.github_path, commit: "[School] Save #{about.to_s}", data: about.to_jekyll)
publish_shared_objects(Education::Program, about.programs)
publish_shared_objects(Education::Teacher, about.teachers)
end
def publish_journal!
github.publish(path: about.github_path, commit: "[Journal] Save #{about.to_s}", data: about.to_jekyll)
publish_shared_objects(Research::Article, about.articles)
publish_shared_objects(Research::Volume, about.volumes)
end
protected
def publish_objects(model, objects)
return if objects.empty?
begin
had_callback = model.__callbacks[:save].find { |c| c.matches?(:after, :publish_to_github) }
model.skip_callback(:save, :after, :publish_to_github) if had_callback
......@@ -59,6 +79,28 @@ module Communication::Website::WithBatchPublication
end
}
end
def publish_shared_objects(model, objects)
return if objects.empty?
begin
had_callback = model.__callbacks[:save].find { |c| c.matches?(:after, :publish_to_every_websites) }
model.skip_callback(:save, :after, :publish_to_every_websites) if had_callback
return unless github.valid?
clean_model_name = model.name.demodulize
objects.each do |object|
if object.respond_to?(:github_path)
github_path = object.github_path
else
root_folder = "_#{clean_model_name.pluralize.underscore}"
github_path = "#{root_folder}/#{object.id}.md"
end
github.add_to_batch(path: github_path, data: object.to_jekyll)
end
github.commit_batch "[#{clean_model_name}] Batch update from import"
ensure
model.set_callback(:save, :after, :publish_to_every_websites) if had_callback
end
end
end
end
......@@ -33,6 +33,7 @@ class Education::School < ApplicationRecord
join_table: 'education_programs_schools',
foreign_key: 'education_school_id',
association_foreign_key: 'education_program_id'
has_many :teachers, -> { distinct }, through: :programs
validates :name, :address, :city, :zipcode, :country, presence: true
......
......@@ -28,8 +28,19 @@ class Research::Journal < ApplicationRecord
scope :ordered, -> { order(:title) }
def to_s
"#{title}"
end
def github_path
"_data/journal.yml"
end
def to_jekyll
{
title: title,
description: description,
issn: issn
}.deep_stringify_keys.to_yaml.lines[1..-1].join
end
end
......@@ -6,6 +6,12 @@ continuing: <%= @program.continuing %>
level: <%= @program.level %>
ects: <%= @program.ects %>
position: <%= @program.position %>
<% if @program.teachers.any? %>
teachers:
<% @program.teachers.each do |teacher| %>
- "<%= teacher.id %>"
<% end %>
<% end %>
accessibility: >
<%= prepare_for_github @program.accessibility, @program.university %>
contacts: >
......
......@@ -4,6 +4,12 @@ identifier: "<%= @teacher.id %>"
first_name: "<%= @teacher.first_name %>"
last_name: "<%= @teacher.last_name %>"
slug: "<%= @teacher.slug %>"
<% if @teacher.programs.any? %>
programs:
<% @teacher.programs.each do |program| %>
- "<%= program.id %>"
<% end %>
<% end %>
biography: >
<%= prepare_for_github @teacher.biography, @teacher.university %>
---
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