Skip to content

Commit

Permalink
Break up long string into a heredoc
Browse files Browse the repository at this point in the history
I know heredocs are weird, but this is *probably* more readable.

I always need to remind myself how the various flavours of heredoc
actually behave. Squiggly heredocs (<<~) remove indentation from their
content. It'll remove the same amount of indentation across all lines,
equal to the indentation of its least-indented line. In this case, all
of our lines start out indented equally, so all indentation ends up
removed from the resulting string.

Also worth noting: the replacement of newline chars in the old string
with actual line breaks in the heredoc. The tests pass, so I hope that
that means the output is identical in all cases that we care about.
  • Loading branch information
mike3985 committed Dec 16, 2024
1 parent 32f738a commit dc833c3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/govspeak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ def render_image(image)
end

extension("address", surrounded_by("$A")) do |body|
%(\n<div class="address"><div class="adr org fn"><p markdown="1">\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n)
<<~BODY
<div class="address"><div class="adr org fn"><p markdown="1">
#{body.sub("\n", '').gsub("\n", '<br />')}
</p></div></div>
BODY
end

extension("legislative list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body|
Expand Down

0 comments on commit dc833c3

Please sign in to comment.