diff --git a/lib/flamegraph/renderer.rb b/lib/flamegraph/renderer.rb index 60249b7..c8e43e4 100644 --- a/lib/flamegraph/renderer.rb +++ b/lib/flamegraph/renderer.rb @@ -9,16 +9,8 @@ def initialize(stacks) def graph_html(embed_resources) body = ERB.new(read('flamegraph.html.erb')).result - body.sub! "/**INCLUDES**/", - if embed_resources - embed("jquery.min.js","d3.min.js","lodash.min.js") - else - ' - -' - end - - body.sub!("/**DATA**/", ::JSON.generate(graph_data)); + body.sub!('/**INCLUDES**/', includes(embed_resources)) + body.sub!('/**DATA**/', ::JSON.generate(graph_data)) body end @@ -81,13 +73,38 @@ def graph_data private - def embed(*files) - out = "" - files.each do |file| - body = read(file) - out << "" - end - out + def include_files + [ + 'https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js' + ] + end + + def includes(embed_resources) + include_files.map do |file| + if embed_resources + embed(file) + else + link(file) + end + end.join("\n") + end + + def embed(file) + file = file.split('/').last + body = read(file) + return "" if file =~ /\.js$/ + return "" if file =~ /\.css$/ + + '' + end + + def link(file) + return "" if file =~ /\.js$/ + return "" if file =~ /\.css$/ + + '' end def read(file)