diff --git a/.github/workflows/visual-regression-tests.yml b/.github/workflows/visual-regression-tests.yml index 5eae5f03e5..a0f7c3202b 100644 --- a/.github/workflows/visual-regression-tests.yml +++ b/.github/workflows/visual-regression-tests.yml @@ -53,3 +53,4 @@ jobs: - run: yarn run percy exec -- bundle exec rspec --tag visual_regression env: PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} + MAIN_COMPONENT_GUIDE: true diff --git a/app/controllers/govuk_publishing_components/component_guide_controller.rb b/app/controllers/govuk_publishing_components/component_guide_controller.rb index c50a74b06a..97c1483572 100644 --- a/app/controllers/govuk_publishing_components/component_guide_controller.rb +++ b/app/controllers/govuk_publishing_components/component_guide_controller.rb @@ -9,7 +9,8 @@ def index @component_gem_path = Gem.loaded_specs["govuk_publishing_components"].full_gem_path @component_docs = component_docs.all @gem_component_docs = gem_component_docs.all - @components_in_use_docs = components_in_use_docs.used_in_this_app + @used_components = used_components_names.get_component_docs + @unused_components = unused_components_names.get_component_docs @components_in_use_sass = components_in_use_sass @components_in_use_js = components_in_use_js end @@ -47,7 +48,7 @@ def components_in_use_sass additional_files = "@import 'govuk_publishing_components/govuk_frontend_support';\n" additional_files << "@import 'govuk_publishing_components/component_support';\n" - components = find_all_partials_in(components_in_use) + components = find_all_partials_in(get_used_component_names) components.map { |component| "@import 'govuk_publishing_components/components/#{component.gsub('_', '-')}';" if component_has_sass_file(component.gsub("_", "-")) @@ -57,7 +58,7 @@ def components_in_use_sass def components_in_use_js additional_files = "//= require govuk_publishing_components/lib\n" - components = find_all_partials_in(components_in_use) + components = find_all_partials_in(get_used_component_names) components.map { |component| "//= require govuk_publishing_components/components/#{component.gsub('_', '-')}" if component_has_js_file(component.gsub("_", "-")) @@ -74,11 +75,15 @@ def gem_component_docs @gem_component_docs ||= ComponentDocs.new(gem_components: true) end - def components_in_use_docs - @components_in_use_docs ||= ComponentDocs.new(gem_components: true, limit_to: components_in_use) + def used_components_names + @used_components_names ||= ComponentDocs.new(gem_components: true, limit_to: get_used_component_names) end - def components_in_use + def unused_components_names + @unused_components_names ||= ComponentDocs.new(gem_components: true, limit_to: get_unused_component_names) + end + + def get_used_component_names matches = [] files = Dir["#{@application_path}/app/views/**/*.erb"] @@ -93,6 +98,11 @@ def components_in_use matches.flatten.uniq.map(&:to_s).sort end + def get_unused_component_names + all_components = ComponentDocs.new(gem_components: true).all.map(&:id) + all_components - get_used_component_names + end + def find_all_partials_in(templates) components = [templates] diff --git a/app/models/govuk_publishing_components/component_docs.rb b/app/models/govuk_publishing_components/component_docs.rb index 72c648041b..ba14cfd3a2 100644 --- a/app/models/govuk_publishing_components/component_docs.rb +++ b/app/models/govuk_publishing_components/component_docs.rb @@ -12,11 +12,11 @@ def get(id) end def all - fetch_component_docs.map { |component| build(component) }.sort_by(&:name) + fetch_component_doc_files.map { |component| build(component) }.sort_by(&:name) end - def used_in_this_app - fetch_component_docs.map { |component| build(component) if component_in_use(component[:id]) }.compact.sort_by(&:name) + def get_component_docs + fetch_component_doc_files.map { |component| build(component) if component_in_use?(component[:id]) }.compact.sort_by(&:name) end private @@ -25,13 +25,13 @@ def build(component) ComponentDoc.new(component) end - def fetch_component_docs + def fetch_component_doc_files doc_files = Rails.root.join(@documentation_directory, "*.yml") Dir[doc_files].sort.map { |file| parse_documentation(file) } end - def component_in_use(component) - true if @limit_to.include?(component) + def component_in_use?(component) + @limit_to.include?(component) end def fetch_component_doc(id) diff --git a/app/views/govuk_publishing_components/component_guide/index.html.erb b/app/views/govuk_publishing_components/component_guide/index.html.erb index ee119a13be..5bcf2274bf 100644 --- a/app/views/govuk_publishing_components/component_guide/index.html.erb +++ b/app/views/govuk_publishing_components/component_guide/index.html.erb @@ -15,8 +15,20 @@ } %> -<% unless ENV["MAIN_COMPONENT_GUIDE"] %> -
+ <%= component_doc.description %> +
+@@ -50,12 +62,10 @@
@@ -65,20 +75,19 @@ <% end %>
+ <%= component_doc.description %> +
+- <%= component_doc.description %> -
-If you cannot find a suitable component consider extending an existing component or creating a new one.