Skip to content

Commit 13f761f

Browse files
committed
WIP
- add basic component - update all components spec to ignore new component, as no stylesheet - outstanding issue of first line not rendering properly, hacks in place
1 parent 965063b commit 13f761f

6 files changed

Lines changed: 75 additions & 2 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require "govspeak"
2+
3+
module GovspeakTranslatorHelper
4+
def parse_govspeak(block)
5+
doc = Govspeak::Document.new("\n\n\n\n#{block.strip}")
6+
doc.to_html.strip
7+
end
8+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<% content = capture do %>
2+
<%= yield %>
3+
<% end %>
4+
<% if content.strip.length > 0 %>
5+
<%= render "govuk_publishing_components/components/govspeak", {} do %>
6+
<%= raw parse_govspeak(content) %>
7+
<% end %>
8+
<% end %>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Govspeak translator
2+
description: Translates govspeak markdown into HTML.
3+
accessibility_criteria: |
4+
- headings must be part of a correct heading structure for the page
5+
- text should have a text contrast ratio higher than 4.5:1 against the background colour to meet WCAG AA
6+
shared_accessibility_criteria:
7+
- link
8+
examples:
9+
default:
10+
data:
11+
block: |
12+
##A heading
13+
14+
This is a paragraph. See how it looks.
15+
16+
* This is a list item
17+
* This is another list item
18+
* One more list item
19+
20+
###Another heading
21+
22+
$A
23+
HM Revenue and Customs
24+
Bradford
25+
BD98 1YY
26+
$A

spec/components/all_components_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
expect(yaml["accessibility_criteria"] || yaml["shared_accessibility_criteria"]).to be_truthy
1919
end
2020

21-
it "has the correct class in the ERB template" do
21+
it "has the correct class in the ERB template", skip: component_name.in?(%w[govspeak_translator]) do
2222
erb = File.read(filename)
2323
class_name = "app-c-#{component_name.dasherize}"
2424
expect(erb).to include(class_name)
@@ -34,7 +34,7 @@
3434
expect(File).to exist(rspec_file)
3535
end
3636

37-
it "has a correctly named SCSS file" do
37+
it "has a correctly named SCSS file", skip: component_name.in?(%w[govspeak_translator]) do
3838
css_file = "#{__dir__}/../../app/assets/stylesheets/components/_#{component_name.tr('_', '-')}.scss"
3939
expect(File).to exist(css_file)
4040
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
RSpec.describe "GovspeakTranslatorComponent", type: :view do
2+
def component_name
3+
"govspeak_translator"
4+
end
5+
6+
it "renders nothing when required params are not passed" do
7+
expect(render_component({})).to be_empty
8+
end
9+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
RSpec.describe GovspeakTranslatorHelper do
2+
describe "#parse_govspeak" do
3+
it "converts simple govspeak into markup" do
4+
str = "#heading"
5+
expect(parse_govspeak(str)).to eq("<h1 id=\"heading\">heading</h1>")
6+
end
7+
8+
it "converts multi line govspeak into markup" do
9+
str = "
10+
#heading
11+
12+
This is a paragraph
13+
"
14+
expect(parse_govspeak(str)).to eq("<h1 id=\"heading\">heading</h1>\n\n<p>This is a paragraph</p>")
15+
end
16+
17+
it "ignores formatting" do
18+
str = "\n\t\t\t#heading\n\n\t"
19+
expect(parse_govspeak(str)).to eq("<h1 id=\"heading\">heading</h1>")
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)