Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErbRenderer should always return an HTML-safe String #2098

Merged
merged 3 commits into from
Nov 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/presenters/outcome_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(i18n_prefix, node, state = nil, options = {})
end

def title
@renderer.content_for(:title, html: false).chomp
@renderer.single_line_of_content_for(:title)
end

def body(html: true)
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/start_node_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def initialize(i18n_prefix, node, state = nil, options = {})
end

def title
@renderer.content_for(:title, html: false).chomp
@renderer.single_line_of_content_for(:title)
end

def meta_description
@renderer.content_for(:meta_description, html: false).chomp
@renderer.single_line_of_content_for(:meta_description)
end

def body(html: true)
Expand Down
6 changes: 5 additions & 1 deletion lib/smart_answer/erb_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ def initialize(template_directory:, template_name:, locals: {}, helpers: [])
helpers.each { |helper| @view.extend(helper) }
end

def single_line_of_content_for(key)
content_for(key, html: false).chomp.html_safe
end

def content_for(key, html: true)
content = rendered_view.content_for(key) || ''
content = strip_leading_spaces(content.to_str)
html ? GovspeakPresenter.new(content).html : normalize_blank_lines(content)
html ? GovspeakPresenter.new(content).html : normalize_blank_lines(content).html_safe
end

def erb_template_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory redundancy pay - GOV.UK</title>
<title>Calculate your employee's statutory redundancy pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory redundancy pay
Calculate your employee's statutory redundancy pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory redundancy pay - GOV.UK</title>
<title>Calculate your employee's statutory redundancy pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory redundancy pay
Calculate your employee's statutory redundancy pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory redundancy pay - GOV.UK</title>
<title>Calculate your employee's statutory redundancy pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory redundancy pay
Calculate your employee's statutory redundancy pay
</h1>
</div>
</header>
Expand Down
4 changes: 2 additions & 2 deletions test/artefacts/calculate-employee-redundancy-pay/y.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory redundancy pay - GOV.UK</title>
<title>Calculate your employee's statutory redundancy pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory redundancy pay
Calculate your employee's statutory redundancy pay
</h1>
</div>
</header>
Expand Down
4 changes: 2 additions & 2 deletions test/artefacts/calculate-married-couples-allowance/y.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
4 changes: 2 additions & 2 deletions test/artefacts/calculate-married-couples-allowance/yes.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your Married Couple&#39;s Allowance - GOV.UK</title>
<title>Calculate your Married Couple's Allowance - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your Married Couple&#39;s Allowance
Calculate your Married Couple's Allowance
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory sick pay - GOV.UK</title>
<title>Calculate your employee's statutory sick pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory sick pay
Calculate your employee's statutory sick pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory sick pay - GOV.UK</title>
<title>Calculate your employee's statutory sick pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory sick pay
Calculate your employee's statutory sick pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory sick pay - GOV.UK</title>
<title>Calculate your employee's statutory sick pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory sick pay
Calculate your employee's statutory sick pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory sick pay - GOV.UK</title>
<title>Calculate your employee's statutory sick pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory sick pay
Calculate your employee's statutory sick pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory sick pay - GOV.UK</title>
<title>Calculate your employee's statutory sick pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory sick pay
Calculate your employee's statutory sick pay
</h1>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" media="all" href="/smartanswers/application.css" />
<link rel="stylesheet" media="print" href="/smartanswers/print.css" />
<title>Calculate your employee&#39;s statutory sick pay - GOV.UK</title>
<title>Calculate your employee's statutory sick pay - GOV.UK</title>
<script src="/smartanswers/smart-answers.js" defer="defer"></script>
<meta name="robots" content="noindex">

Expand All @@ -22,7 +22,7 @@
<header class="page-header group">
<div>
<h1>
Calculate your employee&#39;s statutory sick pay
Calculate your employee's statutory sick pay
</h1>
</div>
</header>
Expand Down
Loading