govspeak 3.5.1 → 3.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54b9c75ce59284172221f263176a47cc93035180
4
- data.tar.gz: 9a6f7c98b35bc753ecc21e0e8aa25234867d2f19
3
+ metadata.gz: 62bbf045a81a14edccdebbc6f9bfe8b16053fe83
4
+ data.tar.gz: 51b63bd95386ba9a1409b8aeab3f9fed85dc169f
5
5
  SHA512:
6
- metadata.gz: 17fac603e4006e23750e4c129b69650d1ec106a71d0b1568a542fa4f1f65e474edd60c56d39de6297481281c1d1e45a51fbda84c41443915a63e9a9edb59006a
7
- data.tar.gz: e29081388c7bf5207a68bd41a7dc1c1fdf0c3d7e3d040d88ee6ce102e9d19e91931f30144d3dc4299f8f0feb3f69c4481f06e3564a3d76767cb7cbf9641f04c5
6
+ metadata.gz: 144b044eaac74204158ab084b8aa65faa911b0f1f37aee17037950a3a6f89b0da67f2813e448bbeb435429db02fe15db0c087c9ad114d396643ea030ad7e98df
7
+ data.tar.gz: 2bbad23f71d71361666a73fb59a93eea150134c5e3239c93ed9726e1c6894de96184ae88a2628b9f3201440d98411bc13486d4ddb298eb5a4510da74f1e1e1c6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.5.2
2
+
3
+ * Fix a couple of issues with the [header_extractor](https://github.com/alphagov/govspeak/blob/master/lib/govspeak/header_extractor.rb). The method now picks up headers nested inside `blocks`, and when ID's are [explicitly set](http://kramdown.gettalong.org/syntax.html#specifying-a-header-id). See [https://github.com/alphagov/govspeak/pull/66](https://github.com/alphagov/govspeak/pull/66) for more.
4
+
1
5
  ## 3.5.1
2
6
 
3
7
  * Continue to support non-strict URIs in links on Ruby 2.2.x. See [https://github.com/alphagov/govspeak/issues/57](https://github.com/alphagov/govspeak/issues/57)
@@ -3,11 +3,45 @@ module Govspeak
3
3
 
4
4
  class HeaderExtractor < Kramdown::Converter::Base
5
5
  def convert(doc)
6
- doc.root.children.map do |el|
6
+ headers = []
7
+
8
+ doc.root.children.each do |el|
7
9
  if el.type == :header
8
- Header.new(el.options[:raw_text], el.options[:level], generate_id(el.options[:raw_text]))
10
+ headers << build_header(el)
11
+ next
12
+ end
13
+
14
+ headers << find_headers(el) if el.type == :html_element
15
+ end
16
+
17
+ headers.flatten.compact
18
+ end
19
+
20
+ private
21
+ def id(el)
22
+ el.attr.fetch('id', generate_id(el.options[:raw_text]))
23
+ end
24
+
25
+ def build_header(el)
26
+ Header.new(el.options[:raw_text], el.options[:level], id(el))
27
+ end
28
+
29
+ def find_headers(parent)
30
+ headers = []
31
+
32
+ if parent.type == :header
33
+ headers << build_header(parent)
34
+ elsif parent.type == :html_element
35
+ parent.children.each do |child|
36
+ if child.type == :header
37
+ headers << build_header(child)
38
+ elsif child.children.size > 0
39
+ headers << find_headers(child)
40
+ end
9
41
  end
10
- end.compact
42
+ end
43
+
44
+ headers
11
45
  end
12
46
  end
13
- end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "3.5.1"
2
+ VERSION = "3.5.2"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class GovspeakStructuredHeadersTest < Test::Unit::TestCase
3
+ class GovspeakStructuredHeadersTest < Minitest::Test
4
4
 
5
5
  def document_body
6
6
  %{
@@ -5,7 +5,7 @@ require 'govspeak_test_helper'
5
5
 
6
6
  require 'ostruct'
7
7
 
8
- class GovspeakTest < Test::Unit::TestCase
8
+ class GovspeakTest < Minitest::Test
9
9
  include GovspeakTestHelper
10
10
 
11
11
  test "simple smoke-test" do
@@ -56,6 +56,43 @@ class GovspeakTest < Test::Unit::TestCase
56
56
  ], document.headers
57
57
  end
58
58
 
59
+ test "extracts headers when nested inside blocks" do
60
+ document = Govspeak::Document.new %{
61
+ # First title
62
+
63
+ <div markdown="1">
64
+ ## Nested subtitle
65
+ </div>
66
+
67
+ <div>
68
+ <div markdown="1">
69
+ ### Double nested subtitle
70
+ </div>
71
+ <div markdown="1">
72
+ ### Second double subtitle
73
+ </div>
74
+ </div>
75
+ }
76
+ assert_equal [
77
+ Govspeak::Header.new('First title', 1, 'first-title'),
78
+ Govspeak::Header.new('Nested subtitle', 2, 'nested-subtitle'),
79
+ Govspeak::Header.new('Double nested subtitle', 3, 'double-nested-subtitle'),
80
+ Govspeak::Header.new('Second double subtitle', 3, 'second-double-subtitle')
81
+ ], document.headers
82
+ end
83
+
84
+ test "extracts headers with explicitly specified ids" do
85
+ document = Govspeak::Document.new %{
86
+ # First title
87
+
88
+ ## Second title {#special}
89
+ }
90
+ assert_equal [
91
+ Govspeak::Header.new('First title', 1, 'first-title'),
92
+ Govspeak::Header.new('Second title', 2, 'special'),
93
+ ], document.headers
94
+ end
95
+
59
96
  test "extracts text with no HTML and normalised spacing" do
60
97
  input = "# foo\n\nbar baz "
61
98
  doc = Govspeak::Document.new(input)
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class HtmlSanitizerTest < Test::Unit::TestCase
3
+ class HtmlSanitizerTest < Minitest::Test
4
4
 
5
5
  test "disallow a script tag" do
6
6
  html = "<script>alert('XSS')</script>"
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class HtmlValidatorTest < Test::Unit::TestCase
3
+ class HtmlValidatorTest < Minitest::Test
4
4
  test "allow Govspeak Markdown" do
5
5
  values = [
6
6
  "## is H2",
data/test/test_helper.rb CHANGED
@@ -9,9 +9,9 @@ $:.unshift(File.expand_path("../lib")) unless $:.include?(File.expand_path("../l
9
9
  require 'bundler'
10
10
  Bundler.setup :default, :development, :test
11
11
 
12
- require 'test/unit'
12
+ require 'minitest/autorun'
13
13
 
14
- class Test::Unit::TestCase
14
+ class Minitest::Test
15
15
  class << self
16
16
  def test(name, &block)
17
17
  clean_name = name.gsub(/\s+/,'_')
@@ -1,6 +1,6 @@
1
1
  require 'with_deep_merge'
2
2
 
3
- class WithDeepMergeTest < Test::Unit::TestCase
3
+ class WithDeepMergeTest < Minitest::Test
4
4
  include WithDeepMerge
5
5
 
6
6
  def test_simple_merge
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Griffiths
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-23 00:00:00.000000000 Z
12
+ date: 2016-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: 1.1.1
112
+ - !ruby/object:Gem::Dependency
113
+ name: minitest
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 5.8.3
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 5.8.3
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: simplecov
114
128
  requirement: !ruby/object:Gem::Requirement