Skip to content

Commit

Permalink
Allow inset-text to take a block
Browse files Browse the repository at this point in the history
Can now pass an arbitrary block to the inset-text component to
have content rendered inset. If both 'text' and a block are
provided, 'text' takes precedence (mutually exclusive).

This is a compromise solution, rather than copying the inset-prompt
component from content-publisher (for use in collections-publisher),
for the reason that under current GOV.UK architecture the component
CSS would be added to the stylesheets for our end users (not just
the users using the publishing app). See:
#1077

Once merged, we will use this latest inset-text component and
manually recreate what the inset-prompt component looks like by
passing components to the inset-text component as a block.

Trello: https://trello.com/c/TcBpLRuC/48-add-inset-prompt-component-to-govukpublishingcomponents
  • Loading branch information
ChrisBAshton committed Aug 30, 2019
1 parent 9f1d4d5 commit 2f046dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<%
id ||= "inset-text-#{SecureRandom.hex(4)}"
%>

<%= tag.div id: id, class: "gem-c-inset-text govuk-inset-text" do %>
<%= text %>
<% if defined? text %>
<%= text %>
<% elsif block_given? %>
<%= yield %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ examples:
default:
data:
text: "It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application."

with_block:
data:
block: |
<div>
<h2 id='heading'>To publish this step by step you need to</h2>
<a href='/foo'>Check for broken links</a>
</div>
19 changes: 19 additions & 0 deletions spec/components/inset_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,23 @@ def component_name

assert_select(".govuk-inset-text", text: "It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application.")
end

it "renders a block" do
block = "
<h2 id='heading'>To publish this step by step you need to</h2>
<a href='/foo'>Check for broken links</a>
".html_safe
render_component({}) { block }

assert_select(".govuk-inset-text h2#heading", text: "To publish this step by step you need to")
assert_select(".govuk-inset-text a[href='/foo']", text: "Check for broken links")
end

it "renders only the text if both text and block are provided" do
block = "<p id='foo'>Foo</p>".html_safe
render_component(text: 'Bar') { block }

assert_select(".govuk-inset-text", text: "Bar")
assert_select(".govuk-inset-text p#foo", false, "Block should not have rendered")
end
end

0 comments on commit 2f046dc

Please sign in to comment.