Skip to content

Commit

Permalink
Allow assets to be precompiled with Sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaSayegh committed Jul 14, 2020
1 parent 60fb0d5 commit cdc9b2c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/html/includes.js
Expand Up @@ -980,6 +980,7 @@ var MiniProfiler = (function() {
script.getAttribute("data-start-hidden") === "true" ||
sessionStorage["rack-mini-profiler-start-hidden"] === "true";
var htmlContainer = script.getAttribute("data-html-container");
var cssUrl = script.getAttribute("data-css-url");
return {
ids: ids,
path: path,
Expand All @@ -996,7 +997,8 @@ var MiniProfiler = (function() {
toggleShortcut: toggleShortcut,
startHidden: startHidden,
collapseResults: collapseResults,
htmlContainer: htmlContainer
htmlContainer: htmlContainer,
cssUrl: cssUrl
};
})();

Expand Down Expand Up @@ -1056,7 +1058,7 @@ var MiniProfiler = (function() {

var init = function init() {
if (options.authorized) {
var url = options.path + "includes.css?v=" + options.version;
var url = options.cssUrl;

if (document.createStyleSheet) {
document.createStyleSheet(url);
Expand Down Expand Up @@ -1398,4 +1400,5 @@ var MiniProfiler = (function() {
};
})();

window.MiniProfiler = MiniProfiler;
MiniProfiler.init();
2 changes: 1 addition & 1 deletion lib/html/profile_handler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/html/rack-mini-profiler.css
@@ -0,0 +1,3 @@
/*
*= require ./includes
*/
2 changes: 2 additions & 0 deletions lib/html/rack-mini-profiler.js
@@ -0,0 +1,2 @@
//= require ./includes
//= require ./vendor
3 changes: 2 additions & 1 deletion lib/mini_profiler/config.rb
Expand Up @@ -60,7 +60,8 @@ def self.default
:base_url_path, :disable_caching, :enabled,
:flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
:skip_schema_queries, :storage, :storage_failure, :storage_instance,
:storage_options, :user_provider, :enable_advanced_debugging_tools
:storage_options, :user_provider, :enable_advanced_debugging_tools,
:assets_url
attr_accessor :skip_sql_param_names, :suppress_encoding, :max_sql_param_length

# ui accessors
Expand Down
12 changes: 11 additions & 1 deletion lib/mini_profiler/profiler.rb
Expand Up @@ -628,10 +628,20 @@ def ids_comma_separated(env)
# * you do not want script to be automatically appended for the current page. You can also call cancel_auto_inject
def get_profile_script(env)
path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}"
version = MiniProfiler::ASSET_VERSION
if @config.assets_url
url = @config.assets_url.call('rack-mini-profiler.js', version, env)
css_url = @config.assets_url.call('rack-mini-profiler.css', version, env)
end

url = "#{path}includes.js?v=#{version}" if !url
css_url = "#{path}includes.css?v=#{version}" if !css_url

settings = {
path: path,
version: MiniProfiler::ASSET_VERSION,
url: url,
cssUrl: css_url,
version: version,
verticalPosition: @config.vertical_position,
horizontalPosition: @config.horizontal_position,
showTrivial: @config.show_trivial,
Expand Down
7 changes: 7 additions & 0 deletions lib/mini_profiler_rails/railtie.rb
Expand Up @@ -6,6 +6,13 @@
module Rack::MiniProfilerRails
extend Rack::MiniProfilerRailsMethods

class Engine < ::Rails::Engine
engine_name 'rack-mini-profiler'
config.assets.paths << File.expand_path('../../html', __FILE__)
config.assets.precompile << 'rack-mini-profiler.js'
config.assets.precompile << 'rack-mini-profiler.css'
end

# call direct if needed to do a defer init
def self.initialize!(app)

Expand Down

0 comments on commit cdc9b2c

Please sign in to comment.