Class: RailsWayback::AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_wayback/assets_controller.rb

Overview

Serves the toolbar's bundled assets without depending on the host application's asset pipeline.

Constant Summary collapse

CACHE_CONTROL =
"public, max-age=31536000, immutable"

Instance Method Summary collapse

Instance Method Details

#historical ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/rails_wayback/assets_controller.rb', line 21

def historical
  selection = RailsWayback::RefPolicy.new.authorize(params[:sha])
  return render_rejection(selection) if selection.rejected?

  source = RailsWayback::ViewSource.new
  resolution = resolve_asset(source, selection.sha, params[:path])
  return head :not_found unless resolution

  set_historical_headers(selection.sha, resolution)
  return head :ok if request.head?

  self.response_body = RailsWayback::HistoricalAssetBody.new(
    sha: selection.sha,
    public_path: resolution.public_path,
    view_source: source
  )
rescue RailsWayback::Git::GitError, RailsWayback::MaterializationError => e
  render json: { error: e.message }, status: :service_unavailable
end

#javascript ⇒ Object



17
18
19
# File 'app/controllers/rails_wayback/assets_controller.rb', line 17

def javascript
  render_asset(BarRenderer::SCRIPT, "application/javascript")
end

#stylesheet ⇒ Object



13
14
15
# File 'app/controllers/rails_wayback/assets_controller.rb', line 13

def stylesheet
  render_asset(BarRenderer::STYLES, "text/css")
end