History

Merge pull request #1455 from MasterEnoc/phpunit

Add Phpunit version 8 and 9

Simon Legner committed 5 years ago

Commit 6fe102e2 parents 08e3646 ae21fad5 files · +146 −56Browse files

Unified · Split

5 files
  1. lib/docs/filters/phpunit/clean_html.rb +9 −48
  2. lib/docs/filters/phpunit/clean_html_old.rb +64 −0
  3. lib/docs/filters/phpunit/entries.rb +3 −1
  4. lib/docs/filters/phpunit/entries_old.rb +25 −0
  5. lib/docs/scrapers/phpunit.rb +45 −7
lib/docs/filters/phpunit/clean_html.rb+9−48
@@ -2,59 +2,20 @@ module Docs · 1 unmodified line
22 class Phpunit
33 class CleanHtmlFilter < Filter
44 def call
5− root_page? ? root : other
6− doc
7− end
8−
9− def root
10− doc.inner_html = ' '
11− end
12−
13− def other
14− @doc = doc.at_css('div.appendix, div.chapter')
15−
16− css('.example-break', '.table-break').remove
17−
18− css('a[id]').each do |node|
19− next unless node.content.blank?
20− node.parent['id'] = node['id']
21− node.remove
22− end
23−
24− css('.titlepage').each do |node|
25− title = node.at_css('h1, .title')
26− title.content = title.content.remove(/(Chapter|Appendix)\s+\w+\.\s+/)
27− node.before(title).remove
28− end
29−
30− css('.section').each do |node|
31− node.before(node.children).remove
32− end
33−
34− css('[style], [border], [valign]').each do |node|
35− node.remove_attribute('style')
36− node.remove_attribute('border')
37− node.remove_attribute('valign')
38− end
395
40− css('.warning h3', '.alert h3').each do |node|
41− node.remove if node.content == 'Note'
42− end
43−
44− css('p > code.literal:first-child:last-child').each do |node|
45− next if node.previous_sibling && node.previous_sibling.content.present?
46− next if node.next_sibling && node.next_sibling.content.present?
47− node.parent.name = 'pre'
48− node.parent['class'] = 'programlisting'
49− node.parent.content = node.content
6+ css('pre').each do |node|
7+ node['class'] = 'highlight'
8+ node['data-language'] = 'php'
509 end
5110
52− css('pre', '.term').each do |node|
53− node.content = node.content
11+ if slug.match(/assertion|annotations|configuration/)
12+ css('h2').each do |node|
13+ node['id'] = node.content
14+ end
5415 end
5516
56− css('pre.programlisting').each do |node|
57− node['data-language'] = 'php'
17+ css('h1').each do |node|
18+ node.content = node.content.gsub(/\d*\./, '').strip
5819 end
5920
6021 doc
lib/docs/filters/phpunit/clean_html_old.rb+64−0
@@ -0,0 +1,64 @@
1+module Docs
2+ class Phpunit
3+ class CleanHtmlOldFilter < Filter
4+ def call
5+ root_page? ? root : other
6+ doc
7+ end
8+
9+ def root
10+ doc.inner_html = ' '
11+ end
12+
13+ def other
14+ @doc = doc.at_css('div.appendix, div.chapter')
15+
16+ css('.example-break', '.table-break').remove
17+
18+ css('a[id]').each do |node|
19+ next unless node.content.blank?
20+ node.parent['id'] = node['id']
21+ node.remove
22+ end
23+
24+ css('.titlepage').each do |node|
25+ title = node.at_css('h1, .title')
26+ title.content = title.content.remove(/(Chapter|Appendix)\s+\w+\.\s+/)
27+ node.before(title).remove
28+ end
29+
30+ css('.section').each do |node|
31+ node.before(node.children).remove
32+ end
33+
34+ css('[style], [border], [valign]').each do |node|
35+ node.remove_attribute('style')
36+ node.remove_attribute('border')
37+ node.remove_attribute('valign')
38+ end
39+
40+ css('.warning h3', '.alert h3').each do |node|
41+ node.remove if node.content == 'Note'
42+ end
43+
44+ css('p > code.literal:first-child:last-child').each do |node|
45+ next if node.previous_sibling && node.previous_sibling.content.present?
46+ next if node.next_sibling && node.next_sibling.content.present?
47+ node.parent.name = 'pre'
48+ node.parent['class'] = 'programlisting'
49+ node.parent.content = node.content
50+ end
51+
52+ css('pre', '.term').each do |node|
53+ node.content = node.content
54+ end
55+
56+ css('pre.programlisting').each do |node|
57+ node['data-language'] = 'php'
58+ end
59+
60+ doc
61+ end
62+ end
63+ end
64+end
lib/docs/filters/phpunit/entries.rb+3−1
@@ -1,12 +1,13 @@
11 module Docs
22 class Phpunit
33 class EntriesFilter < Docs::EntriesFilter
4+
45 def get_name
56 at_css('h1').content
67 end
78
89 def get_type
9− if name.in?(%w(Assertions Annotations))
10+ if name.in? ['Assertions', 'Annotations', 'The XML Configuration File']
1011 name
1112 else
1213 'Guides'
@@ -20,6 +21,7 @@ module Docs · 7 unmodified lines
2021 [node.content, node['id']]
2122 end
2223 end
24+
2325 end
2426 end
2527 end
lib/docs/filters/phpunit/entries_old.rb+25−0
@@ -0,0 +1,25 @@
1+module Docs
2+ class Phpunit
3+ class EntriesOldFilter < Docs::EntriesFilter
4+ def get_name
5+ at_css('h1').content
6+ end
7+
8+ def get_type
9+ if name.in?(%w(Assertions Annotations))
10+ name
11+ else
12+ 'Guides'
13+ end
14+ end
15+
16+ def additional_entries
17+ return [] if type == 'Guides'
18+
19+ css('h2').map do |node|
20+ [node.content, node['id']]
21+ end
22+ end
23+ end
24+ end
25+end
lib/docs/scrapers/phpunit.rb+45−7
@@ -8,34 +8,71 @@ module Docs · 7 unmodified lines
88 code: 'https://github.com/sebastianbergmann/phpunit'
99 }
1010
11− html_filters.push 'phpunit/clean_html', 'phpunit/entries', 'title'
11+ options[:skip] = [
12+ 'bibliography.html',
13+ 'copyright.html'
14+ ]
1215
1316 options[:root_title] = 'PHPUnit'
1417 options[:title] = false
1518
16− options[:skip] = %w(
17− appendixes.index.html
18− appendixes.bibliography.html
19− appendixes.copyright.html)
20−
2119 options[:attribution] = <<-HTML
22− &copy; 2005&ndash;2017 Sebastian Bergmann<br>
20+ &copy; 2005&ndash;2020 Sebastian Bergmann<br>
2321 Licensed under the Creative Commons Attribution 3.0 Unported License.
2422 HTML
2523
24+ FILTERS = %w(phpunit/clean_html phpunit/entries title)
25+
26+ version '9' do
27+ self.release = '9.5'
28+ self.base_url = "https://phpunit.readthedocs.io/en/#{release}/"
29+
30+ html_filters.push FILTERS
31+
32+ options[:container] = '.document'
33+ end
34+
35+ version '8' do
36+ self.release = '8.5'
37+ self.base_url = "https://phpunit.readthedocs.io/en/#{release}/"
38+
39+ html_filters.push FILTERS
40+
41+ options[:container] = '.document'
42+ end
43+
44+ OLDFILTERS = %w(phpunit/clean_html_old phpunit/entries_old title)
45+
46+ OLDSKIP = %w(
47+ appendixes.index.html
48+ appendixes.bibliography.html
49+ appendixes.copyright.html)
50+
2651 version '6' do
2752 self.release = '6.5'
2853 self.base_url = "https://phpunit.de/manual/#{release}/en/"
54+
55+ html_filters.push OLDFILTERS
56+
57+ options[:skip] = OLDSKIP
2958 end
3059
3160 version '5' do
3261 self.release = '5.7'
3362 self.base_url = "https://phpunit.de/manual/#{release}/en/"
63+
64+ html_filters.push OLDFILTERS
65+
66+ options[:skip] = OLDSKIP
3467 end
3568
3669 version '4' do
3770 self.release = '4.8'
3871 self.base_url = "https://phpunit.de/manual/#{release}/en/"
72+
73+ options[:skip] = OLDSKIP
74+
75+ html_filters.push OLDFILTERS
3976 end
4077
4178 def get_latest_version(opts)
@@ -43,5 +80,6 @@ module Docs · 1 unmodified line
4380 label = doc.at_css('.rst-current-version').content.strip
4481 label.scan(/v: ([0-9.]+)/)[0][0]
4582 end
83+
4684 end
4785 end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t