Skip to content

Commit

Permalink
Add checking what components use govuk-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpatrickpatrick committed Nov 14, 2023
1 parent 6e18f2e commit 298c940
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/models/govuk_publishing_components/audit_comparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(gem_data, results)
@gem_data[:components_by_application] = get_components_by_application || []
@gem_data[:helpers_used_by_applications] = get_helpers_used_by_applications || []
@gem_data[:component_file_details] = combine_all_component_file_details(@gem_data[:component_file_details], @applications_data)
@gem_data[:get_components_using_govuk_frontend_per_application] = get_components_by_application.filter { | component | component[:govuk_frontend] }
end
end

Expand Down Expand Up @@ -279,6 +280,7 @@ def get_components_by_application

results << {
name: component_name,
govuk_frontend: component[:uses_govuk_frontend],
count: locations.length,
locations:,
}
Expand Down
9 changes: 9 additions & 0 deletions app/models/govuk_publishing_components/audit_components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def get_component_asset_detail(detail, component)
else
@component_numbers[type.to_sym] += 1
details["#{type}_exists".to_sym] = true

if type == "javascript" && uses_govuk_frontend?(file)
details[:uses_govuk_frontend] = true
end

details["#{type}_lines".to_sym] = count_lines_in(file)
details["#{type}_link".to_sym] = get_asset_link(type, component)
end
Expand All @@ -130,6 +135,10 @@ def count_lines_in(file)
File.read(file).each_line.count
end

def uses_govuk_frontend?(file)
File.read(file).match(/require govuk\/components/)
end

def clean_files(files, replace)
files.map { |file| clean_file_name(file.gsub(replace, "")) }.sort
end
Expand Down
15 changes: 11 additions & 4 deletions app/views/govuk_publishing_components/audit/_components.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@
items: component_items
%>

<%= render 'items_in_applications',
heading: 'Gem components using govuk-frontend used by applications',
summary: 'Shows which applications use gem components that use govuk-frontend',
content: @components[:get_components_using_govuk_frontend_per_application],
items: component_items
%>

<% helpers_by_component = capture do %>
<dl class="govuk-summary-list">
<% @components[:helper_usage].each do |helper| %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<a href="https://github.com/alphagov/govuk_publishing_components/blob/main/<%= helper[:link] %>" class="govuk-link"><%= helper[:name] %></a>
<a href="https://github.com/alphagov/govuk_publishing_components/blob/main/<%= helper[:link] %>" class="govuk-link"><%= helper[:name] %></a>
</dt>
<dd class="govuk-summary-list__value">
<details class="govuk-details" data-module="govuk-details">
Expand All @@ -82,14 +89,14 @@
<div class="govuk-details__text">
<ul class="govuk-list govuk-list--bullet">
<% helper[:used_by].each do |component| %>
<% github_link = 'https://github.com/alphagov/govuk_publishing_components/tree/main/app/views/govuk_publishing_components/components/' %>
<% github_link = 'https://github.com/alphagov/govuk_publishing_components/tree/main/app/views/govuk_publishing_components/components/' %>
<li>
<a href="<%= github_link %><%= component[:link] %>" class="govuk-link"><%= component[:name] %></a>
</li>
<% end %>
<% end %>
</ul>
</div>
</details>
</details>
</dd>
</div>
<% end %>
Expand Down

0 comments on commit 298c940

Please sign in to comment.