govspeak 0.8.12 → 0.8.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,7 @@ then create a new document
20
20
 
21
21
  # Extensions
22
22
 
23
- In addition to the [standard Markdown syntax](http://daringfireball.net/projects/markdown/syntax "Markdown syntax"), we have added our own extensions.
23
+ In addition to the [standard Markdown syntax](http://daringfireball.net/projects/markdown/syntax "Markdown syntax"), we have added our own extensions.
24
24
 
25
25
  ## Callouts
26
26
 
@@ -30,8 +30,8 @@ In addition to the [standard Markdown syntax](http://daringfireball.net/projects
30
30
 
31
31
  creates a callout with an info (i) icon.
32
32
 
33
- <div class="application-notice info-notice">
34
- <p>This is an information callout</p>
33
+ <div class="application-notice info-notice">
34
+ <p>This is an information callout</p>
35
35
  </div>
36
36
 
37
37
  ### Warning callouts
@@ -40,8 +40,8 @@ creates a callout with an info (i) icon.
40
40
 
41
41
  creates a callout with a warning or alert (!) icon
42
42
 
43
- <div class="application-notice help-notice">
44
- <p>This is a warning callout</p>
43
+ <div class="application-notice help-notice">
44
+ <p>This is a warning callout</p>
45
45
  </div>
46
46
 
47
47
  ### Example callout
@@ -51,7 +51,7 @@ creates a callout with a warning or alert (!) icon
51
51
  $E
52
52
 
53
53
  creates an example box
54
-
54
+
55
55
  <div class="example">
56
56
  <p><strong>Example:</strong> Open the pod bay doors</p>
57
57
  </div>
@@ -66,7 +66,7 @@ highlights the enclosed text in yellow
66
66
 
67
67
  <h3 class="advisory">
68
68
  <span>This is a very important message or warning</span>
69
- </h3>
69
+ </h3>
70
70
 
71
71
  ### Answer
72
72
 
@@ -85,8 +85,8 @@ creates a large pink highlight box with optional preamble text and giant text de
85
85
  ### Contact
86
86
 
87
87
  $C
88
- **Student Finance England**
89
- **Telephone:** 0845 300 50 90
88
+ **Student Finance England**
89
+ **Telephone:** 0845 300 50 90
90
90
  **Minicom:** 0845 604 44 34
91
91
  $C
92
92
 
@@ -108,8 +108,8 @@ creates an address box
108
108
 
109
109
  <div class="address vcard"><div class="adr org fn"><p>
110
110
  Hercules House
111
- <br>Hercules Road
112
- <br>London SE1 7DU
111
+ <br>Hercules Road
112
+ <br>London SE1 7DU
113
113
  <br></p></div></div>
114
114
 
115
115
  ## Downloads
data/lib/govspeak.rb CHANGED
@@ -9,7 +9,7 @@ module Govspeak
9
9
  @@extensions = []
10
10
 
11
11
  attr_accessor :images
12
-
12
+
13
13
  def self.to_html(source, options = {})
14
14
  new(source, options).to_html
15
15
  end
@@ -25,7 +25,7 @@ module Govspeak
25
25
  @kramdown_doc ||= Kramdown::Document.new(preprocess(@source), @options)
26
26
  end
27
27
  private :kramdown_doc
28
-
28
+
29
29
  def to_html
30
30
  kramdown_doc.to_html
31
31
  end
@@ -46,7 +46,7 @@ module Govspeak
46
46
  end
47
47
  source
48
48
  end
49
-
49
+
50
50
  def encode(text)
51
51
  HTMLEntities.new.encode(text)
52
52
  end
@@ -72,8 +72,8 @@ module Govspeak
72
72
  content = parser ? parser.new("#{body.strip}\n").to_html : body.strip
73
73
  %{<div class="#{class_name}">\n#{content}</div>\n}
74
74
  }
75
- end
76
-
75
+ end
76
+
77
77
  def insert_strong_inside_p(body, parser=Kramdown::Document)
78
78
  parser.new(body.strip).to_html.sub(/^<p>(.*)<\/p>$/,"<p><strong>\\1</strong></p>")
79
79
  end
@@ -107,7 +107,7 @@ module Govspeak
107
107
  extension('map_link', surrounded_by("((", "))")) { |body|
108
108
  %{<div class="map"><iframe width="200" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="#{body.strip}&output=embed"></iframe><br /><small><a href="#{body.strip}">View Larger Map</a></small></div>}
109
109
  }
110
-
110
+
111
111
  extension('attached-image', /^!!([0-9]+)/) do |image_number|
112
112
  image = images[image_number.to_i - 1]
113
113
  if image
@@ -117,7 +117,7 @@ module Govspeak
117
117
  ""
118
118
  end
119
119
  end
120
-
120
+
121
121
  def render_image(url, alt_text, caption = nil)
122
122
  lines = []
123
123
  lines << '<figure class="image embedded">'
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "0.8.12"
2
+ VERSION = "0.8.13"
3
3
  end
@@ -11,7 +11,7 @@ require 'govspeak_test_helper'
11
11
 
12
12
  class GovspeakTest < Test::Unit::TestCase
13
13
  include GovspeakTestHelper
14
-
14
+
15
15
  test "simple smoke-test" do
16
16
  rendered = Govspeak::Document.new("*this is markdown*").to_html
17
17
  assert_equal "<p><em>this is markdown</em></p>\n", rendered
@@ -31,7 +31,7 @@ class GovspeakTest < Test::Unit::TestCase
31
31
  rendered = Govspeak::Document.new("this \n{::highlight-answer}Lead in to *BIG TEXT*\n{:/highlight-answer}").to_html
32
32
  assert_equal %Q{<p>this </p>\n\n<div class="highlight-answer">\n<p>Lead in to <em>BIG TEXT</em></p>\n</div>\n}, rendered
33
33
  end
34
-
34
+
35
35
  test "extracts headers with text, level and generated id" do
36
36
  document = Govspeak::Document.new %{
37
37
  # Big title
@@ -94,7 +94,7 @@ Teston
94
94
  </div>}
95
95
  assert_text_output "The following is very informational I am very informational"
96
96
  end
97
-
97
+
98
98
  test_given_govspeak "^ I am very informational" do
99
99
  assert_html_output %{
100
100
  <div class="application-notice info-notice">
@@ -102,14 +102,14 @@ Teston
102
102
  </div>}
103
103
  assert_text_output "I am very informational"
104
104
  end
105
-
105
+
106
106
  test_given_govspeak "@ I am very important @" do
107
107
  assert_html_output %{
108
108
  <div class="advisory"><p><strong>I am very important</strong></p>
109
109
  </div>}
110
110
  assert_text_output "I am very important"
111
111
  end
112
-
112
+
113
113
  test_given_govspeak "
114
114
  The following is very important
115
115
  @ I am very important @
@@ -121,7 +121,7 @@ Teston
121
121
  </div>}
122
122
  assert_text_output "The following is very important I am very important"
123
123
  end
124
-
124
+
125
125
  test_given_govspeak "% I am very helpful %" do
126
126
  assert_html_output %{
127
127
  <div class="application-notice help-notice">
@@ -129,7 +129,7 @@ Teston
129
129
  </div>}
130
130
  assert_text_output "I am very helpful"
131
131
  end
132
-
132
+
133
133
  test_given_govspeak "The following is very helpful\n% I am very helpful %" do
134
134
  assert_html_output %{
135
135
  <p>The following is very helpful</p>
@@ -139,7 +139,7 @@ Teston
139
139
  </div>}
140
140
  assert_text_output "The following is very helpful I am very helpful"
141
141
  end
142
-
142
+
143
143
  test_given_govspeak "## Hello ##\n\n% I am very helpful %\r\n### Young Workers ###\n\n" do
144
144
  assert_html_output %{
145
145
  <h2 id="hello">Hello</h2>
@@ -151,7 +151,7 @@ Teston
151
151
  <h3 id="young-workers">Young Workers</h3>}
152
152
  assert_text_output "Hello I am very helpful Young Workers"
153
153
  end
154
-
154
+
155
155
  test_given_govspeak "% I am very helpful" do
156
156
  assert_html_output %{
157
157
  <div class="application-notice help-notice">
@@ -159,17 +159,17 @@ Teston
159
159
  </div>}
160
160
  assert_text_output "I am very helpful"
161
161
  end
162
-
162
+
163
163
  test_given_govspeak "This is a [link](http://www.google.com) isn't it?" do
164
164
  assert_html_output '<p>This is a <a href="http://www.google.com">link</a> isn&rsquo;t it?</p>'
165
165
  assert_text_output "This is a link isn’t it?"
166
166
  end
167
-
167
+
168
168
  test_given_govspeak "This is a [link with an at sign in it](http://www.google.com/@dg/@this) isn't it?" do
169
169
  assert_html_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>'
170
170
  assert_text_output "This is a link with an at sign in it isn’t it?"
171
171
  end
172
-
172
+
173
173
  test_given_govspeak "
174
174
  HTML
175
175
 
@@ -177,12 +177,12 @@ Teston
177
177
  assert_html_output %{<p><abbr title="Hyper Text Markup Language">HTML</abbr></p>}
178
178
  assert_text_output "HTML"
179
179
  end
180
-
180
+
181
181
  test_given_govspeak "x[a link](http://rubyforge.org)x" do
182
182
  assert_html_output '<p><a href="http://rubyforge.org" rel="external">a link</a></p>'
183
183
  assert_text_output "a link"
184
184
  end
185
-
185
+
186
186
  # Regression test - the surrounded_by helper doesn't require the closing x
187
187
  # so 'xaa' was getting picked up by the external link helper above
188
188
  # TODO: review whether we should require closing symbols for these extensions
@@ -202,7 +202,7 @@ Teston
202
202
  </div>}
203
203
  assert_text_output "rainbow"
204
204
  end
205
-
205
+
206
206
  test_given_govspeak "$C help, send cake $C" do
207
207
  assert_html_output %{
208
208
  <div class="contact">
@@ -210,7 +210,7 @@ Teston
210
210
  </div>}
211
211
  assert_text_output "help, send cake"
212
212
  end
213
-
213
+
214
214
  test_given_govspeak "
215
215
  $A
216
216
  street
@@ -222,7 +222,7 @@ Teston
222
222
  </p></div></div>}
223
223
  assert_text_output "street road"
224
224
  end
225
-
225
+
226
226
  test_given_govspeak "
227
227
  $P
228
228
  $I
@@ -232,7 +232,7 @@ Teston
232
232
  assert_html_output %{<div class="place">\n<div class="information">\n<p>help</p>\n</div>\n</div>}
233
233
  assert_text_output "help"
234
234
  end
235
-
235
+
236
236
  test_given_govspeak "
237
237
  $D
238
238
  can you tell me how to get to...
@@ -243,7 +243,7 @@ Teston
243
243
  </div>}
244
244
  assert_text_output "can you tell me how to get to…"
245
245
  end
246
-
246
+
247
247
  test_given_govspeak "
248
248
  1. rod
249
249
  2. jane
@@ -251,14 +251,14 @@ Teston
251
251
  assert_html_output "<ol>\n <li>rod</li>\n <li>jane</li>\n <li>freddy</li>\n</ol>"
252
252
  assert_text_output "rod jane freddy"
253
253
  end
254
-
254
+
255
255
  test_given_govspeak "
256
256
  ((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))
257
257
  " do
258
258
  assert_html_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>}
259
259
  assert_text_output "View Larger Map"
260
260
  end
261
-
261
+
262
262
  test_given_govspeak "
263
263
  s1. zippy
264
264
  s2. bungle
@@ -275,7 +275,7 @@ Teston
275
275
  </ol>}
276
276
  assert_text_output "zippy bungle george"
277
277
  end
278
-
278
+
279
279
  test_given_govspeak ":scotland: I am very devolved\n and very scottish \n:scotland:" do
280
280
  assert_html_output '
281
281
  <div class="devolved-content scotland">
@@ -285,15 +285,15 @@ Teston
285
285
  </div>
286
286
  </div>
287
287
  '
288
- end
288
+ end
289
289
 
290
290
  test_given_govspeak "@ Message with [a link](http://foo.bar/)@" do
291
291
  assert_html_output %{
292
292
  <div class="advisory"><p><strong>Message with <a href="http://foo.bar/">a link</a></strong></p>
293
293
  </div>
294
- }
294
+ }
295
295
  end
296
-
296
+
297
297
  test "can reference attached images using !!n" do
298
298
  images = [OpenStruct.new(alt_text: 'my alt', url: "http://example.com/image.jpg")]
299
299
  given_govspeak "!!1", images do
@@ -319,7 +319,7 @@ Teston
319
319
  test "silently ignores an image attachment if the referenced image is missing" do
320
320
  doc = Govspeak::Document.new("!!1")
321
321
  doc.images = []
322
-
322
+
323
323
  assert_equal %Q{\n}, doc.to_html
324
324
  end
325
325
 
@@ -334,7 +334,7 @@ Teston
334
334
  }
335
335
  end
336
336
  end
337
-
337
+
338
338
  test "ignores a blank caption" do
339
339
  images = [OpenStruct.new(alt_text: "my alt", url: "http://example.com/image.jpg", caption: ' ')]
340
340
  given_govspeak "!!1", images do
@@ -3,32 +3,32 @@ module GovspeakTestHelper
3
3
  def self.included(base)
4
4
  base.extend(ClassMethods)
5
5
  end
6
-
6
+
7
7
  class GovspeakAsserter
8
8
  def initialize(testcase, govspeak, images = [])
9
9
  @testcase = testcase
10
10
  @govspeak = remove_indentation(govspeak)
11
11
  @images = images
12
12
  end
13
-
13
+
14
14
  def document
15
15
  Govspeak::Document.new(@govspeak).tap do |doc|
16
16
  doc.images = @images
17
17
  end
18
18
  end
19
-
19
+
20
20
  def assert_text_output(raw_expected)
21
21
  expected = remove_indentation(raw_expected)
22
22
  actual = document.to_text
23
23
  @testcase.assert expected == actual, describe_error(@govspeak, expected, actual)
24
24
  end
25
-
25
+
26
26
  def assert_html_output(raw_expected)
27
27
  expected = remove_indentation(raw_expected)
28
28
  actual = document.to_html.strip
29
29
  @testcase.assert expected.strip == actual, describe_error(@govspeak, expected.strip, actual)
30
30
  end
31
-
31
+
32
32
  def remove_indentation(raw)
33
33
  lines = raw.split("\n")
34
34
  if lines.first.empty?
@@ -45,11 +45,11 @@ module GovspeakTestHelper
45
45
  raw
46
46
  end
47
47
  end
48
-
48
+
49
49
  def describe_error(govspeak, expected, actual)
50
50
  "Expected:\n#{govspeak}\n\nto produce:\n#{show_linenumbers(expected)}\n\nbut got:\n#{show_linenumbers(actual)}\n"
51
51
  end
52
-
52
+
53
53
  def show_linenumbers(text)
54
54
  lines = text.split "\n"
55
55
  digits = Math.log10(lines.size + 2).ceil
@@ -63,7 +63,7 @@ module GovspeakTestHelper
63
63
  asserter = GovspeakAsserter.new(self, govspeak, images)
64
64
  asserter.instance_eval(&block)
65
65
  end
66
-
66
+
67
67
  module ClassMethods
68
68
  def test_given_govspeak(govspeak, &block)
69
69
  test "Given #{govspeak}" do
@@ -71,4 +71,4 @@ module GovspeakTestHelper
71
71
  end
72
72
  end
73
73
  end
74
- end
74
+ end
data/test/test_helper.rb CHANGED
@@ -11,10 +11,10 @@ class Test::Unit::TestCase
11
11
  clean_name = name.gsub(/\s+/,'_')
12
12
  method = "test_#{clean_name.gsub(/\s+/,'_')}".to_sym
13
13
  already_defined = instance_method(method) rescue false
14
- raise "#{method} exists" if already_defined
14
+ raise "#{method} exists" if already_defined
15
15
  define_method(method, &block)
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
- require 'govspeak'
20
+ require 'govspeak'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.12
5
+ version: 0.8.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Griffiths
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-05-11 00:00:00 Z
14
+ date: 2012-05-29 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: kramdown
@@ -58,7 +58,7 @@ dependencies:
58
58
  prerelease: false
59
59
  version_requirements: *id004
60
60
  description: |-
61
- A set of extensions to markdown layered on top of the kramdown
61
+ A set of extensions to markdown layered on top of the kramdown
62
62
  library for use in the UK Government Single Domain project
63
63
  email:
64
64
  - ben@alphagov.co.uk
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
- hash: 530935927851704938
95
+ hash: -2168654671078793304
96
96
  segments:
97
97
  - 0
98
98
  version: "0"
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- hash: 530935927851704938
104
+ hash: -2168654671078793304
105
105
  segments:
106
106
  - 0
107
107
  version: "0"