Skip to content

Commit

Permalink
adding the ability to include extra scripts to flipper-ui via configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
nicastelo committed Jul 3, 2024
1 parent 5aa9cfd commit a27ab6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/flipper/ui/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class Configuration
# Default is false.
attr_accessor :confirm_disable

# Public: An array of scripts to include in the UI. Each script should be
# a hash with a `:src` key and optionally a `:integrity` key. Example:
# config.scripts << { src: "https://example.com/script.js", integrity: "sha384-abc123" }
attr_accessor :scripts

VALID_BANNER_CLASS_VALUES = %w(
danger
dark
Expand Down Expand Up @@ -111,6 +116,7 @@ def initialize
{ title: "Features", href: "features" },
{ title: "Settings", href: "settings" },
]
@scripts = []
end

def using_descriptions?
Expand Down
11 changes: 11 additions & 0 deletions lib/flipper/ui/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,16 @@
<script src="<%= script_name + bootstrap_js[:src] %>" integrity="<%= bootstrap_js[:hash] %>" crossorigin="anonymous"></script>
<script src="<%= script_name %>/js/application.js?v=<%= Flipper::VERSION %>"></script>
<script src="<%= script_name %>/js/version.js?v=<%= Flipper::VERSION %>"></script>
<% unless Flipper::UI.configuration.scripts.empty? %>
<% Flipper::UI.configuration.scripts.each do |script| %>
<script
src="<%= script[:src] %>"
<% if script[:integrity].present? %>
integrity="<%= script[:integrity] %>"
<% end %>
crossorigin="anonymous">
</script>
<% end %>
<% end %>
</body>
</html>
11 changes: 11 additions & 0 deletions spec/flipper/ui/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,15 @@
it { is_expected.to eq(true) }
end
end

describe "#scripts" do
it "has default value" do
expect(configuration.scripts).to eq([])
end

it "can be updated" do
configuration.scripts << { src: "https://example.com/script.js", integrity: "sha384-abc123" }
expect(configuration.scripts).to eq([{ src: "https://example.com/script.js", integrity: "sha384-abc123" }])
end
end
end

0 comments on commit a27ab6a

Please sign in to comment.