mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 22:26:21 +00:00
55 lines
1.1 KiB
Ruby
55 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Forma de ingreso a Sutty
|
|
class ApplicationController < ActionController::Base
|
|
include ExceptionHandler
|
|
|
|
protect_from_forgery with: :exception
|
|
before_action :set_locale
|
|
|
|
# No tenemos índice de sutty, vamos directamente a ver el listado de
|
|
# sitios
|
|
def index
|
|
redirect_to sites_path
|
|
end
|
|
|
|
def markdown; end
|
|
|
|
private
|
|
|
|
# Encontrar un sitio por su nombre
|
|
def find_site
|
|
id = params[:site_id] || params[:id]
|
|
|
|
unless (site = current_usuarie.sites.find_by_name(id))
|
|
raise SiteNotFound
|
|
end
|
|
|
|
site
|
|
end
|
|
|
|
def find_post(site)
|
|
id = params[:post_id] || params[:id]
|
|
lang = find_lang(site)
|
|
posts = site.posts_for(lang)
|
|
|
|
posts.find do |p|
|
|
p.id == id
|
|
end
|
|
end
|
|
|
|
def find_lang(site)
|
|
params.fetch(:lang, site.default_lang)
|
|
end
|
|
|
|
def find_template(site)
|
|
id = params[:template_id] || params[:template] || params.dig(:post, :layout)
|
|
site.templates.find do |t|
|
|
t.id == id
|
|
end
|
|
end
|
|
|
|
def set_locale
|
|
I18n.locale = session[:lang] if session[:lang].present?
|
|
end
|
|
end
|