govspeak 1.2.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/govspeak.rb CHANGED
@@ -22,7 +22,6 @@ module Govspeak
22
22
 
23
23
  def initialize(source, options = {})
24
24
  @source = source ? source.dup : ""
25
- Parser.document_domains = options.delete(:document_domains)
26
25
  @options = {input: PARSER_CLASS_NAME, entity_output: :symbolic}.merge(options)
27
26
  @images = []
28
27
  end
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -1,19 +1,35 @@
1
1
  require "uri"
2
+ require "kramdown/options"
2
3
 
3
4
  module Kramdown
5
+ module Options
6
+ class AlwaysEqual
7
+ def ==(other)
8
+ true
9
+ end
10
+ end
11
+
12
+ define(:document_domains, Object, %w{www.gov.uk}, <<EOF) do |val|
13
+ Defines the domains which are considered local to the document
14
+
15
+ Default: www.gov.uk
16
+ Used by: KramdownWithAutomaticExternalLinks
17
+ EOF
18
+ simple_array_validator(val, :document_domains, AlwaysEqual.new)
19
+ end
20
+ end
21
+
4
22
  module Parser
5
23
  class KramdownWithAutomaticExternalLinks < Kramdown::Parser::Kramdown
6
- class << self
7
- attr_writer :document_domains
8
- def document_domains
9
- @document_domains || %w(www.gov.uk)
10
- end
24
+ def initialize(source, options)
25
+ @document_domains = options[:document_domains] || %w(www.gov.uk)
26
+ super
11
27
  end
12
28
 
13
29
  def add_link(el, href, title, alt_text = nil)
14
30
  begin
15
31
  host = URI.parse(href).host
16
- unless host.nil? || (self.class.document_domains.compact.include?(host))
32
+ unless host.nil? || (@document_domains.compact.include?(host))
17
33
  el.attr['rel'] = 'external'
18
34
  end
19
35
  rescue URI::InvalidURIError, URI::InvalidComponentError
@@ -337,6 +337,20 @@ $CTA
337
337
  </div>}
338
338
  end
339
339
 
340
+ test_given_govspeak "
341
+ [internal link](http://www.not-external.com)
342
+
343
+ $CTA
344
+ Click here to start the tool
345
+ $CTA", [], document_domains: %w(www.not-external.com) do
346
+ assert_html_output %{
347
+ <p><a href="http://www.not-external.com">internal link</a></p>
348
+
349
+ <div class="call-to-action">
350
+ <p>Click here to start the tool</p>
351
+ </div>}
352
+ end
353
+
340
354
  test_given_govspeak "
341
355
  1. rod
342
356
  2. jane
@@ -5,14 +5,15 @@ module GovspeakTestHelper
5
5
  end
6
6
 
7
7
  class GovspeakAsserter
8
- def initialize(testcase, govspeak, images = [])
8
+ def initialize(testcase, govspeak, images = [], options = {})
9
9
  @testcase = testcase
10
10
  @govspeak = remove_indentation(govspeak)
11
11
  @images = images
12
+ @options = options
12
13
  end
13
14
 
14
15
  def document
15
- Govspeak::Document.new(@govspeak).tap do |doc|
16
+ Govspeak::Document.new(@govspeak, @options).tap do |doc|
16
17
  doc.images = @images
17
18
  end
18
19
  end
@@ -59,15 +60,15 @@ module GovspeakTestHelper
59
60
  end
60
61
  end
61
62
 
62
- def given_govspeak(govspeak, images=[], &block)
63
- asserter = GovspeakAsserter.new(self, govspeak, images)
63
+ def given_govspeak(govspeak, images=[], options = {}, &block)
64
+ asserter = GovspeakAsserter.new(self, govspeak, images, options)
64
65
  asserter.instance_eval(&block)
65
66
  end
66
67
 
67
68
  module ClassMethods
68
- def test_given_govspeak(govspeak, &block)
69
+ def test_given_govspeak(govspeak, images=[], options = {}, &block)
69
70
  test "Given #{govspeak}" do
70
- given_govspeak(govspeak, &block)
71
+ given_govspeak(govspeak, images, options, &block)
71
72
  end
72
73
  end
73
74
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.0
5
+ version: 1.2.2
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-09-14 00:00:00 Z
14
+ date: 2012-11-01 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: kramdown
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- hash: 2266013611251793811
133
+ hash: 1267404848853148486
134
134
  segments:
135
135
  - 0
136
136
  version: "0"
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- hash: 2266013611251793811
142
+ hash: 1267404848853148486
143
143
  segments:
144
144
  - 0
145
145
  version: "0"