Skip to content

Commit

Permalink
Serve JS and CSS without asset pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisbernard committed Apr 21, 2023
1 parent d33737f commit 84f8970
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 20 deletions.
15 changes: 0 additions & 15 deletions app/assets/stylesheets/active_analytics/application.css

This file was deleted.

27 changes: 27 additions & 0 deletions app/controllers/active_analytics/assets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_dependency "active_analytics/application_controller"

module ActiveAnalytics
class AssetsController < ApplicationController
def show
if endpoints.include?(File.basename(request.path))
expires_in(1.day, public: true)
render(params[:id], mime_type: mime_type)
else
raise ActionController::RoutingError.new
end
end

private

def endpoints
return @endpoints if @endpoints
folder = ActiveAnalytics::Engine.root.join("app/views", controller_path)
files = folder.each_child.map { |path| File.basename(path).delete_suffix(".erb") }
@endpoints = files.delete_if { |str| str.start_with?("_") }
end

def mime_type
Mime::Type.lookup_by_extension(File.extname(request.path).delete_prefix("."))
end
end
end
2 changes: 2 additions & 0 deletions app/views/active_analytics/assets/application.css.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render "charts" %>
<%= render "style" %>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//= require active_analytics/ariato

ActiveAnalytics = {}

ActiveAnalytics.Header = function() {
Expand All @@ -13,4 +11,4 @@ ActiveAnalytics.Header.prototype.toggleDateRangeForm = function() {
form.setAttribute("hidden", "hidden")
}

Ariato.launchWhenDomIsReady()
Ariato.launchWhenDomIsReady()
File renamed without changes.
6 changes: 4 additions & 2 deletions app/views/layouts/active_analytics/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "active_analytics/application", media: "all" %>
<%= javascript_include_tag "active_analytics/application" %>
<%= tag.link rel: "stylesheet", href: asset_path(:ariato, format: :css) %>
<%= tag.link rel: "stylesheet", href: asset_path(:application, format: :css) %>
<%= tag.script "", src: asset_path(:ariato, format: :js) %>
<%= tag.script "", src: asset_path(:application, format: :js) %>
</head>

<body>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ActiveAnalytics::Engine.routes.draw do
resources :assets, only: [:show]
get "/:site", to: "sites#show", as: :site, constraints: {site: /[^\/]+/}

# Referrers
Expand All @@ -9,5 +10,6 @@
get "/:site/pages", to: "pages#index", constraints: {site: /[^\/]+/}, as: :pages
get "/:site/*page", to: "pages#show", as: :page, constraints: {site: /[^\/]+/}


root to: "sites#index", as: :active_analytics
end

2 comments on commit 84f8970

@alexisbernard
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shroy there is no more asset pipeline dependency. You should give it a try ! (cf #5)

Not released yet gem "active_analytics", git: "https://github.com/BaseSecrete/active_analytics.git".

@shroy
Copy link

@shroy shroy commented on 84f8970 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexisbernard Thanks for the heads up! Excited to give it a spin!

Please sign in to comment.