govspeak 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.5.0
2
+
3
+ Added `$PriorityList:x` construct to class the first `x` list items with
4
+ `primary-item`.
5
+ Fixed `rcov` dependency.
6
+
1
7
  ## 1.4.0
2
8
 
3
9
  Added `#structured_headers` method to provide heirarchically structured
data/lib/govspeak.rb CHANGED
@@ -62,8 +62,8 @@ module Govspeak
62
62
 
63
63
  def preprocess(source)
64
64
  @@extensions.each do |title,regexp,block|
65
- source.gsub!(regexp) {|match|
66
- instance_exec($1, &block)
65
+ source.gsub!(regexp) {
66
+ instance_exec(*Regexp.last_match.captures, &block)
67
67
  }
68
68
  end
69
69
  source
@@ -184,5 +184,18 @@ module Govspeak
184
184
  </div>\n}
185
185
  end
186
186
  end
187
+
188
+ extension("Priority list", /\$PriorityList:(\d+)\n(.*)(?:^\s*\n|\Z)/m) do |number_to_show, body|
189
+ number_to_show = number_to_show.to_i
190
+ tagged = 0
191
+ Kramdown::Document.new(body.strip).to_html.gsub(/<li>/) do |match|
192
+ if tagged < number_to_show
193
+ tagged += 1
194
+ '<li class="primary-item">'
195
+ else
196
+ match
197
+ end
198
+ end
199
+ end
187
200
  end
188
201
  end
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -1,11 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'simplecov'
4
- require 'simplecov-rcov'
5
-
6
- SimpleCov.start
7
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
8
-
9
3
  require 'test_helper'
10
4
  require 'govspeak_test_helper'
11
5
 
@@ -453,7 +447,7 @@ $CTA
453
447
  test "can sanitize a document" do
454
448
  document = Govspeak::Document.new("<script>doBadThings();</script>")
455
449
  assert_equal "doBadThings();", document.to_sanitized_html
456
- end
450
+ end
457
451
 
458
452
  test "can sanitize a document without image" do
459
453
  document = Govspeak::Document.new("<script>doBadThings();</script><img src='https://example.com/image.jpg'>")
@@ -469,4 +463,31 @@ $CTA
469
463
  document = Govspeak::Document.new("<div>some content</div>")
470
464
  assert document.valid?
471
465
  end
466
+
467
+ ["$PriorityList:3
468
+ * List item 1
469
+ * List item 2
470
+ * List item 3
471
+ * List item 4
472
+ * List item 5",
473
+ "$PriorityList:3
474
+ * List item 1
475
+ * List item 2
476
+ * List item 3
477
+ * List item 4
478
+ * List item 5
479
+
480
+ "].each do |govspeak|
481
+ test_given_govspeak(govspeak) do
482
+ assert_html_output %|
483
+ <ul>
484
+ <li class="primary-item">List item 1</li>
485
+ <li class="primary-item">List item 2</li>
486
+ <li class="primary-item">List item 3</li>
487
+ <li>List item 4</li>
488
+ <li>List item 5</li>
489
+ </ul>
490
+ |
491
+ end
492
+ end
472
493
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,9 @@
1
+ require 'simplecov'
2
+ require 'simplecov-rcov'
3
+
4
+ SimpleCov.start
5
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
6
+
1
7
  $:.unshift(File.expand_path("../lib")) unless $:.include?(File.expand_path("../lib"))
2
8
 
3
9
  require 'bundler'
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: 1.4.0
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -165,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  segments:
167
167
  - 0
168
- hash: -3957971095230574253
168
+ hash: 132095242591557468
169
169
  required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  none: false
171
171
  requirements:
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  segments:
176
176
  - 0
177
- hash: -3957971095230574253
177
+ hash: 132095242591557468
178
178
  requirements: []
179
179
  rubyforge_project:
180
180
  rubygems_version: 1.8.23