govspeak 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/govspeak.rb +5 -0
  2. data/test/govspeak_test.rb +56 -26
  3. metadata +46 -43
data/lib/govspeak.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'kramdown'
2
2
  require 'govspeak/header_extractor'
3
+ require 'htmlentities'
3
4
 
4
5
  module Govspeak
5
6
 
@@ -22,6 +23,10 @@ module Govspeak
22
23
  @doc.to_html
23
24
  end
24
25
 
26
+ def to_text
27
+ HTMLEntities.new.decode(to_html.gsub(/(?:<[^>]+>|\s)+/, " ").strip)
28
+ end
29
+
25
30
  def headers
26
31
  Govspeak::HeaderExtractor.convert(@doc).first
27
32
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'simplecov'
2
4
  require 'simplecov-rcov'
3
5
 
@@ -46,48 +48,61 @@ class GovspeakTest < Test::Unit::TestCase
46
48
  ], document.headers
47
49
  end
48
50
 
51
+ test "extracts text with no HTML and normalised spacing" do
52
+ input = "# foo\n\nbar baz "
53
+ doc = Govspeak::Document.new(input)
54
+ assert_equal "foo bar baz", doc.to_text
55
+ end
56
+
49
57
  test "govspark extensions" do
50
58
  markdown_regression_tests = [
51
59
  {
52
60
  input: "^ I am very informational ^",
53
61
  output: %{<div class="application-notice info-notice">
54
62
  <p>I am very informational</p>
55
- </div>}
63
+ </div>},
64
+ text: "I am very informational"
56
65
  }, {
57
66
  input: "The following is very informational\n^ I am very informational ^",
58
67
  output: %{<p>The following is very informational</p>
59
68
 
60
69
  <div class="application-notice info-notice">
61
70
  <p>I am very informational</p>
62
- </div>}
71
+ </div>},
72
+ text: "The following is very informational I am very informational"
63
73
  }, {
64
74
  input: "^ I am very informational",
65
75
  output: %{<div class="application-notice info-notice">
66
76
  <p>I am very informational</p>
67
- </div>}
77
+ </div>},
78
+ text: "I am very informational"
68
79
  }, {
69
80
  input: "@ I am very important @",
70
81
  output: %{<div class="advisory"><p><strong>I am very important</strong></p>
71
- </div>}
82
+ </div>},
83
+ text: "I am very important"
72
84
  }, {
73
85
  input: "The following is very important
74
86
  @ I am very important @",
75
87
  output: %{<p>The following is very important</p>
76
88
 
77
89
  <div class="advisory"><p><strong>I am very important</strong></p>
78
- </div>}
90
+ </div>},
91
+ text: "The following is very important I am very important"
79
92
  }, {
80
93
  input: "% I am very helpful %",
81
94
  output: %{<div class="application-notice help-notice">
82
95
  <p>I am very helpful</p>
83
- </div>}
96
+ </div>},
97
+ text: "I am very helpful"
84
98
  }, {
85
99
  input: "The following is very helpful\n% I am very helpful %",
86
100
  output: %{<p>The following is very helpful</p>
87
101
 
88
102
  <div class="application-notice help-notice">
89
103
  <p>I am very helpful</p>
90
- </div>}
104
+ </div>},
105
+ text: "The following is very helpful I am very helpful"
91
106
  }, {
92
107
  input: "## Hello ##\n\n% I am very helpful %\r\n### Young Workers ###\n\n",
93
108
  output: %{<h2 id="hello">Hello</h2>
@@ -96,38 +111,46 @@ class GovspeakTest < Test::Unit::TestCase
96
111
  <p>I am very helpful</p>
97
112
  </div>
98
113
 
99
- <h3 id="young-workers">Young Workers</h3>}
114
+ <h3 id="young-workers">Young Workers</h3>},
115
+ text: "Hello I am very helpful Young Workers"
100
116
  }, {
101
117
  input: "% I am very helpful",
102
118
  output: %{<div class="application-notice help-notice">
103
119
  <p>I am very helpful</p>
104
- </div>}
120
+ </div>},
121
+ text: "I am very helpful"
105
122
  }, {
106
123
  input: "This is a [link](http://www.google.com) isn't it?",
107
- output: '<p>This is a <a href="http://www.google.com">link</a> isn&rsquo;t it?</p>'
124
+ output: '<p>This is a <a href="http://www.google.com">link</a> isn&rsquo;t it?</p>',
125
+ text: "This is a link isn’t it?"
108
126
  }, {
109
127
  input: "This is a [link with an at sign in it](http://www.google.com/@dg/@this) isn't it?",
110
- output: '<p>This is a <a href="http://www.google.com/@dg/@this">link with an at sign in it</a> isn&rsquo;t it?</p>'
128
+ output: '<p>This is a <a href="http://www.google.com/@dg/@this">link with an at sign in it</a> isn&rsquo;t it?</p>',
129
+ text: "This is a link with an at sign in it isn’t it?"
111
130
  }, {
112
131
  input: "HTML
113
132
 
114
133
  *[HTML]: Hyper Text Markup Language",
115
- output: %{<p><abbr title="Hyper Text Markup Language">HTML</abbr></p>}
134
+ output: %{<p><abbr title="Hyper Text Markup Language">HTML</abbr></p>},
135
+ text: "HTML"
116
136
  }, {
117
137
  input: "x[a link](http://rubyforge.org)x",
118
- output: '<p><a href="http://rubyforge.org" rel="external">a link</a></p>'
138
+ output: '<p><a href="http://rubyforge.org" rel="external">a link</a></p>',
139
+ text: "a link"
119
140
  }, {
120
141
  input: "$!
121
142
  rainbow
122
143
  $!",
123
144
  output: %{<div class="summary">
124
145
  <p>rainbow</p>
125
- </div>}
146
+ </div>},
147
+ text: "rainbow"
126
148
  }, {
127
149
  input: "$C help, send cake $C",
128
150
  output: %{<div class="contact">
129
151
  <p>help, send cake</p>
130
- </div>}
152
+ </div>},
153
+ text: "help, send cake"
131
154
  }, {
132
155
  input: "$A
133
156
  street
@@ -135,31 +158,36 @@ road
135
158
  $A",
136
159
  output: %{<div class="address vcard"><div class="adr org fn"><p>
137
160
  street<br />road<br />
138
- </p></div></div>}
161
+ </p></div></div>},
162
+ text: "street road"
139
163
  }, {
140
164
  input: "$P
141
165
  $I
142
166
  help
143
167
  $I
144
168
  $P",
145
- output: %{<div class="place">\n<div class="information">\n<p>help</p>\n</div>\n</div>}
169
+ output: %{<div class="place">\n<div class="information">\n<p>help</p>\n</div>\n</div>},
170
+ text: "help"
146
171
  }, {
147
172
  input: "$D
148
173
  can you tell me how to get to...
149
174
  $D",
150
175
  output: %{<div class="form-download">
151
- <p>can you tell me how to get to&hellip;</p>
152
- </div>}
176
+ <p>can you tell me how to get to…</p>
177
+ </div>},
178
+ text: "can you tell me how to get to…"
153
179
  }, {
154
180
  input: "1. rod
155
181
  2. jane
156
182
  3. freddy",
157
- output: "<ol>\n <li>rod</li>\n <li>jane</li>\n <li>freddy</li>\n</ol>"
183
+ output: "<ol>\n <li>rod</li>\n <li>jane</li>\n <li>freddy</li>\n</ol>",
184
+ text: "rod jane freddy"
158
185
  }, {
159
186
  input: "
160
187
  ((http://maps.google.co.uk/maps?q=Winkfield+Rd,+Windsor,+Berkshire+SL4+4AY&hl=en&sll=53.800651,-4.064941&sspn=17.759517,42.055664&vpsrc=0&z=14))
161
188
  ",
162
- output: %{<div class="map"><iframe width="200" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?q=Winkfield+Rd,+Windsor,+Berkshire+SL4+4AY&amp;hl=en&amp;sll=53.800651,-4.064941&amp;sspn=17.759517,42.055664&amp;vpsrc=0&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?q=Winkfield+Rd,+Windsor,+Berkshire+SL4+4AY&amp;hl=en&amp;sll=53.800651,-4.064941&amp;sspn=17.759517,42.055664&amp;vpsrc=0&amp;z=14">View Larger Map</a></small></div>}
189
+ output: %{<div class="map"><iframe width="200" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?q=Winkfield+Rd,+Windsor,+Berkshire+SL4+4AY&amp;hl=en&amp;sll=53.800651,-4.064941&amp;sspn=17.759517,42.055664&amp;vpsrc=0&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?q=Winkfield+Rd,+Windsor,+Berkshire+SL4+4AY&amp;hl=en&amp;sll=53.800651,-4.064941&amp;sspn=17.759517,42.055664&amp;vpsrc=0&amp;z=14">View Larger Map</a></small></div>},
190
+ text: "View Larger Map"
163
191
  }, {
164
192
  input: "s1. zippy
165
193
  s2. bungle
@@ -169,14 +197,16 @@ s3. george
169
197
  <li><p>zippy</p>\n</li>
170
198
  <li><p>bungle</p>\n</li>
171
199
  <li><p>george</p>\n</li>
172
- </ol>}
200
+ </ol>},
201
+ text: "zippy bungle george"
173
202
  }
174
203
  ]
175
204
 
176
- markdown_regression_tests.each do |t|
177
- rendered = Govspeak::Document.new(t[:input]).to_html
178
- assert_equal t[:output].strip, rendered.strip
179
- end
205
+ markdown_regression_tests.each do |t|
206
+ doc = Govspeak::Document.new(t[:input])
207
+ assert_equal t[:output].strip, doc.to_html.strip
208
+ assert_equal t[:text], doc.to_text
209
+ end
180
210
 
181
211
  end
182
212
 
metadata CHANGED
@@ -1,53 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.7
4
5
  prerelease:
5
- version: 0.8.6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ben Griffiths
9
9
  - James Stewart
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-12-20 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2012-01-11 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: kramdown
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &20300980 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
19
+ requirements:
22
20
  - - ~>
23
- - !ruby/object:Gem::Version
21
+ - !ruby/object:Gem::Version
24
22
  version: 0.13.3
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *20300980
26
+ - !ruby/object:Gem::Dependency
27
+ name: htmlentities
28
+ requirement: &20299900 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *20299900
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ requirement: &20299160 !ruby/object:Gem::Requirement
31
40
  none: false
32
- requirements:
41
+ requirements:
33
42
  - - ~>
34
- - !ruby/object:Gem::Version
43
+ - !ruby/object:Gem::Version
35
44
  version: 0.8.0
36
45
  type: :development
37
- version_requirements: *id002
38
- description: |-
39
- A set of extensions to markdown layered on top of the kramdown
40
- library for use in the UK Government Single Domain project
41
- email:
46
+ prerelease: false
47
+ version_requirements: *20299160
48
+ description: ! "A set of extensions to markdown layered on top of the kramdown \nlibrary
49
+ for use in the UK Government Single Domain project"
50
+ email:
42
51
  - ben@alphagov.co.uk
43
52
  - james.stewart@digital.cabinet-office.gov.uk
44
53
  executables: []
45
-
46
54
  extensions: []
47
-
48
55
  extra_rdoc_files: []
49
-
50
- files:
56
+ files:
51
57
  - lib/govspeak/header_extractor.rb
52
58
  - lib/govspeak.rb
53
59
  - Gemfile
@@ -56,31 +62,28 @@ files:
56
62
  - test/test_helper.rb
57
63
  homepage: http://github.com/alphagov/govspeak
58
64
  licenses: []
59
-
60
65
  post_install_message:
61
66
  rdoc_options: []
62
-
63
- require_paths:
67
+ require_paths:
64
68
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
69
+ required_ruby_version: !ruby/object:Gem::Requirement
66
70
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
76
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
77
81
  requirements: []
78
-
79
82
  rubyforge_project:
80
- rubygems_version: 1.8.12
83
+ rubygems_version: 1.8.11
81
84
  signing_key:
82
85
  specification_version: 3
83
86
  summary: Markup language for single domain
84
- test_files:
87
+ test_files:
85
88
  - test/govspeak_test.rb
86
89
  - test/test_helper.rb