-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #759 from alphagov/create-shared-helper-for-compon…
…ents Create shared helper for components
- Loading branch information
Showing
17 changed files
with
123 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
app/assets/stylesheets/govuk_publishing_components/components/_textarea.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
@import "govuk-frontend/components/textarea/textarea"; | ||
|
||
.gem-c-textarea .govuk-textarea { | ||
margin-bottom: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/views/govuk_publishing_components/components/_hint.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
app/views/govuk_publishing_components/components/_subscription-links.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
lib/govuk_publishing_components/presenters/accordion_helper.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/govuk_publishing_components/presenters/shared_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
class SharedHelper | ||
attr_reader :options, :margin_bottom, :heading_level | ||
|
||
def initialize(local_assigns) | ||
@options = local_assigns | ||
@margin_bottom = @options[:margin_bottom] || 3 | ||
@heading_level = @options[:heading_level] || 2 | ||
end | ||
|
||
def get_margin_bottom | ||
[*0..9].include?(@margin_bottom) ? "govuk-!-margin-bottom-#{margin_bottom}" : "govuk-!-margin-bottom-3" | ||
end | ||
|
||
def get_heading_level | ||
return [*1..6].include?(@heading_level) ? "h#{@heading_level}" : "h2" unless @heading_level.zero? | ||
|
||
"span" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
RSpec.describe GovukPublishingComponents::Presenters::SharedHelper do | ||
describe "Shared component helper" do | ||
it "returns a default margin class" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new({}) | ||
margin_class = shared_helper.get_margin_bottom | ||
expect(margin_class).to eql('govuk-!-margin-bottom-3') | ||
end | ||
|
||
it "returns a given margin class" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(margin_bottom: 6) | ||
margin_class = shared_helper.get_margin_bottom | ||
expect(margin_class).to eql('govuk-!-margin-bottom-6') | ||
end | ||
|
||
it "returns the default margin class if passed value is wrong" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(margin_bottom: "a") | ||
margin_class = shared_helper.get_margin_bottom | ||
expect(margin_class).to eql('govuk-!-margin-bottom-3') | ||
end | ||
|
||
it "returns a default heading level" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new({}) | ||
heading = shared_helper.get_heading_level | ||
expect(heading).to eql('h2') | ||
end | ||
|
||
it "returns a given heading level" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(heading_level: 6) | ||
heading = shared_helper.get_heading_level | ||
expect(heading).to eql('h6') | ||
end | ||
|
||
it "returns the default heading level if passed value is wrong" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(heading_level: 9) | ||
heading = shared_helper.get_heading_level | ||
expect(heading).to eql('h2') | ||
end | ||
|
||
it "returns a span instead of a heading if heading level is 0" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(heading_level: 0) | ||
result = shared_helper.get_heading_level | ||
expect(result).to eql('span') | ||
end | ||
end | ||
end |