Sha256: 49a2da1a7c30c728bd5226c4c26751f33a6541ce1753c84d2c777eb5f020d804

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

class Occams::Cms::AssetsController < Occams::Cms::BaseController
  skip_before_action :verify_authenticity_token, raise: false

  before_action :load_cms_layout,
                :use_null_session

  after_action :set_cache_control_header

  def render_css
    render body: @cms_layout.css, content_type: "text/css"
  end

  def render_js
    render body: @cms_layout.js, content_type: "application/javascript"
  end

protected

  def load_cms_layout
    @cms_layout = @cms_site.layouts.find_by_identifier!(params[:identifier])
  rescue ActiveRecord::RecordNotFound
    render body: nil, status: 404
  end

  # null_session avoids cookies and flash updates
  def use_null_session
    ActionController::RequestForgeryProtection::ProtectionMethods::NullSession.new(self)
      .handle_unverified_request
  end

  def set_cache_control_header
    if params[:cache_buster].present?
      response.headers["Cache-Control"] = "public, max-age=#{1.year.to_i}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
occams-1.0.1 app/controllers/occams/cms/assets_controller.rb