Skip to content

Commit

Permalink
Improve sass suggestion
Browse files Browse the repository at this point in the history
- streamline supporting sass into one line
- only add a component to it if it has a sass file
- wrap in a textarea for ease of copying and pasting
  • Loading branch information
andysellick committed Oct 11, 2019
1 parent 2ee60c6 commit 88d7d17
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/assets/stylesheets/component_guide/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@import "govuk/helpers/all";
@import "govuk/core/all";

@import "govuk_publishing_components/all_components";

$gem-guide-border-width: 1px;

.component-guide-wrapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file should be included in an application prior to specific components
// It provides govuk-frontend and supporting gem component helpers and mixins

@import "govuk/all";
@import 'govuk_publishing_components/components/helpers/variables';
@import 'govuk_publishing_components/components/helpers/brand-colours';
@import 'govuk_publishing_components/components/mixins/govuk-template-link-focus-override';
@import 'govuk_publishing_components/components/mixins/media-down';
@import 'govuk_publishing_components/components/mixins/margins';
@import 'govuk_publishing_components/components/mixins/clearfix';
@import 'govuk_publishing_components/components/mixins/css3';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def preview

def components_in_use_sass
components_in_use.map { |component|
"@import 'govuk_publishing_components/components/#{component}';"
}.join("\n").prepend("@import 'govuk_publishing_components/govuk-frontend';\n")
"@import 'govuk_publishing_components/components/_#{component.gsub('_', '-')}';" if component_has_sass_file(component.gsub('_', '-'))
}.join("\n").squeeze("\n").prepend("@import 'govuk_publishing_components/component_support';\n")
end

private
Expand All @@ -64,12 +64,16 @@ def components_in_use
files = Dir["#{Rails.root}/app/views/**/*.html.erb"]
files.each do |file|
data = File.read(file)
matches << data.scan(/(govuk_publishing_components\/components\/[a-z_]+)/)
matches << data.scan(/(govuk_publishing_components\/components\/[a-z_-]+)/)
end

matches.flatten.uniq.map(&:to_s).sort.map{ |m| m.gsub('govuk_publishing_components/components/', '') }
end

def component_has_sass_file(component)
Pathname.new(File.expand_path(File.dirname(__FILE__)) + "/../../assets/stylesheets/govuk_publishing_components/components/_#{component}.scss").exist?
end

def index_breadcrumb
{
title: GovukPublishingComponents::Config.component_guide_title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
<%= render "govuk_publishing_components/components/details", {
title: "Suggested Sass for this application"
} do %>
<pre><%= @components_in_use_sass %></pre>
<%= render "govuk_publishing_components/components/textarea", {
label: {
text: "Add this to your application's main scss file"
},
name: "more-detail",
value: @components_in_use_sass
} %>
<% end %>
<pre>

Expand Down

0 comments on commit 88d7d17

Please sign in to comment.