History

Update and improve PHP documentation (7.0.3)

Thibaut Courouble committed 10 years ago

Commit 44e1f211 parent b8658d98 files · +113 −17Browse files

Unified · Split

8 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +1 −1
  2. assets/stylesheets/pages/_php.scss +1 −0
  3. lib/docs/core/scraper.rb +61 −0
  4. lib/docs/filters/php/clean_html.rb +12 −0
  5. lib/docs/filters/php/entries.rb +9 −2
  6. lib/docs/filters/php/fix_urls.rb +1 −1
  7. lib/docs/filters/php/internal_urls.rb +3 −0
  8. lib/docs/scrapers/php.rb +25 −13
assets/javascripts/templates/pages/about_tmpl.coffee+1−1
@@ -311,7 +311,7 @@ credits = [ · 310 unmodified lines
311311 'https://raw.githubusercontent.com/phoenixframework/phoenix/master/LICENSE.md'
312312 ], [
313313 'PHP',
314− '1997-2015 The PHP Documentation Group',
314+ '1997-2016 The PHP Documentation Group',
315315 'CC BY',
316316 'https://creativecommons.org/licenses/by/3.0/'
317317 ], [
assets/stylesheets/pages/_php.scss+1−0
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 @extend %lined-heading;
55 }
66
7+ h2 { @extend %block-heading; }
78 h3.title { @extend %block-heading; }
89
910 .verinfo {
lib/docs/core/scraper.rb+61−0
@@ -186,5 +186,66 @@ module Docs · 185 unmodified lines
186186 Typhoeus.stub(root_url.to_s).and_return(response)
187187 end
188188 end
189+
190+ module FixInternalUrlsBehavior
191+ def self.included(base)
192+ base.extend ClassMethods
193+ end
194+
195+ module ClassMethods
196+ attr_reader :internal_urls
197+
198+ def store_pages(store)
199+ instrument 'info.doc', msg: 'Building internal urls...'
200+ with_internal_urls do
201+ instrument 'info.doc', msg: 'Building pages...'
202+ super
203+ end
204+ end
205+
206+ private
207+
208+ def with_internal_urls
209+ @internal_urls = new.fetch_internal_urls
210+ yield
211+ ensure
212+ @internal_urls = nil
213+ end
214+ end
215+
216+ def fetch_internal_urls
217+ result = []
218+ build_pages do |page|
219+ result << base_url.subpath_to(page[:response_url]) if page[:entries].present?
220+ end
221+ result
222+ end
223+
224+ def initial_urls
225+ return super unless self.class.internal_urls
226+ @initial_urls ||= self.class.internal_urls.map(&method(:url_for)).freeze
227+ end
228+
229+ private
230+
231+ def additional_options
232+ if self.class.internal_urls
233+ {
234+ only: self.class.internal_urls.to_set,
235+ only_patterns: nil,
236+ skip: nil,
237+ skip_patterns: nil,
238+ skip_links: nil,
239+ fixed_internal_urls: true
240+ }
241+ else
242+ {}
243+ end
244+ end
245+
246+ def process_response(response)
247+ super.merge! response_url: response.url
248+ end
249+ end
189250 end
190251 end
lib/docs/filters/php/clean_html.rb+12−0
@@ -25,6 +25,18 @@ module Docs · 24 unmodified lines
2525 node.inner_html = node.inner_html.gsub(br, "\n")
2626 node.content = node.content
2727 end
28+
29+ css('> h2:first-child.title').each do |node|
30+ node.name = 'h1'
31+ end
32+
33+ css('div.partintro', 'div.section').each do |node|
34+ node.before(node.children).remove
35+ end
36+
37+ css('.title + .verinfo + .title').each do |node|
38+ node.after(node.previous_element)
39+ end
2840 end
2941 end
3042 end
lib/docs/filters/php/entries.rb+9−2
@@ -25,6 +25,7 @@ module Docs · 24 unmodified lines
2525 'tidy' => 'Tidy',
2626 'Worker' => 'pthreads',
2727 'XsltProcessor' => 'XSLT',
28+ 'Yar' => 'Yar',
2829 'ZipArchive' => 'Zip' }
2930
3031 %w(APC Directory DOM Event Gearman Gmagick Imagick mysqli OAuth PDO Reflection
@@ -46,13 +47,16 @@ module Docs · 15 unmodified lines
4647 end
4748
4849 REPLACE_TYPES = {
50+ 'Error' => 'Errors',
4951 'Exceptions' => 'SPL/Exceptions',
52+ 'finfo' => 'File System',
5053 'GD and Image' => 'Image',
5154 'Gmagick' => 'Image/GraphicsMagick',
5255 'Imagick' => 'Image/ImageMagick',
5356 'Interfaces' => 'SPL/Interfaces',
5457 'Iterators' => 'SPL/Iterators',
5558 'mysqli' => 'Database/MySQL',
59+ 'PCRE Patterns' => 'PCRE Reference',
5660 'PostgreSQL' => 'Database/PostgreSQL',
5761 'Session' => 'Sessions',
5862 'Session PgSQL' => 'Database/PostgreSQL',
@@ -62,7 +66,7 @@ module Docs · 3 unmodified lines
6266 'Yaml' => 'YAML' }
6367
6468 TYPE_GROUPS = {
65− 'Classes and Functions' => ['Classes/Object', 'Function handling', 'Predefined Interfaces and Classes', 'runkit'],
69+ 'Classes and Functions' => ['Classes/Object', 'Function handling', 'Predefined Interfaces and Classes', 'runkit', 'Throwable'],
6670 'Encoding' => ['Gettext', 'iconv', 'Multibyte String'],
6771 'Compression' => ['Bzip2', 'Zip', 'Zlib'],
6872 'Cryptography' => ['Hash', 'Mcrypt', 'OpenSSL', 'Password Hashing'],
@@ -90,6 +94,9 @@ module Docs · 21 unmodified lines
9094 end
9195
9296 def get_type
97+ return 'Language Reference' if subpath.start_with?('language.')
98+ return 'PCRE Reference' if subpath.start_with?('regexp.')
99+
93100 type = at_css('.up').content.strip
94101 type = 'SPL/Iterators' if type.end_with? 'Iterator'
95102 type.remove! ' Functions'
@@ -108,7 +115,7 @@ module Docs · 12 unmodified lines
108115 end
109116
110117 def include_default_entry?
111− !initial_page? && doc.at_css('.reference', '.refentry', '.sect1')
118+ !initial_page? && doc.at_css('.reference', '.refentry', '.sect1', '.simpara', '.para')
112119 end
113120 end
114121 end
lib/docs/filters/php/fix_urls.rb+1−1
@@ -3,7 +3,7 @@ module Docs · 2 unmodified lines
33 class FixUrlsFilter < Filter
44 def call
55 html.gsub! File.join(Php.base_url, Php.root_path), Php.base_url
6− html.gsub! %r{http://www\.php\.net/manual/en/([^"']+?)\.html}, 'http://www.php.net/manual/en/\1.php'
6+ html.gsub! %r{https://secure\.php\.net/manual/en/([^"']+?)\.html}, 'https://secure.php.net/manual/en/\1.php'
77 html
88 end
99 end
lib/docs/filters/php/internal_urls.rb+3−0
@@ -2,9 +2,12 @@ module Docs · 1 unmodified line
22 class Php
33 class InternalUrlsFilter < Filter
44 def call
5+ return doc if context[:fixed_internal_urls]
6+
57 if subpath.start_with?('book.') || subpath.start_with?('class.')
68 result[:internal_urls] = internal_urls
79 end
10+
811 doc
912 end
1013
lib/docs/scrapers/php.rb+25−13
@@ -1,19 +1,28 @@
11 module Docs
22 class Php < FileScraper
3+ include FixInternalUrlsBehavior
4+
35 self.name = 'PHP'
46 self.type = 'php'
5− self.release = 'up to 5.6.13'
6− self.base_url = 'http://www.php.net/manual/en/'
7+ self.release = 'up to 7.0.3'
8+ self.base_url = 'https://secure.php.net/manual/en/'
79 self.root_path = 'index.html'
810 self.initial_paths = %w(
911 funcref.html
12+ langref.html
1013 refs.database.html
1114 set.mysqlinfo.html
1215 language.control-structures.html
16+ reference.pcre.pattern.syntax.html
1317 reserved.exceptions.html
1418 reserved.interfaces.html
1519 reserved.variables.html)
1620
21+ self.links = {
22+ home: 'https://secure.php.net/',
23+ code: 'https://github.com/php/php-src'
24+ }
25+
1726 # Downloaded from php.net/download-docs.php
1827 self.dir = '/Users/Thibaut/DevDocs/Docs/PHP'
1928
@@ -25,34 +34,37 @@ module Docs · 5 unmodified lines
2534 options[:skip_links] = ->(filter) { !filter.initial_page? }
2635
2736 options[:only_patterns] = [
37+ /\Alanguage\./,
2838 /\Aclass\./,
2939 /\Afunction\./,
3040 /\Acontrol-structures/,
41+ /\Aregexp\./,
3142 /\Areserved\.exceptions/,
3243 /\Areserved\.interfaces/,
3344 /\Areserved\.variables/]
3445
35− BOOKS = %w(apache apc array bc bzip2 calendar classobj ctype curl datetime
36− dba dir dom eio errorfunc event exec fileinfo filesystem filter ftp funchand
37− gearman geoip gettext gmagick hash http iconv iisfunc image imagick imap
38− info inotify intl json ldap libevent libxml mail mailparse math mbstring
39− mcrypt memcached misc mysqli network oauth openssl outcontrol password
40− pcre pdo pgsql posix pthreads regex runkit reflection session
41− session-pgsql simplexml soap sockets solr sphinx spl spl-types sqlite3
42− sqlsrv ssh2 stats stream strings taint tidy uodbc url var varnish xml
43− xmlreader xmlrpc xmlwriter xsl yaf yaml zip zlib)
46+ BOOKS = %w(apache apc array bc bzip2 calendar csprng classobj ctype curl
47+ datetime dba dir dom eio errorfunc event exec fileinfo filesystem filter
48+ ftp funchand gearman geoip gettext gmagick gmp hash iconv iisfunc image
49+ imagick imap info inotify intl json ldap libevent libxml mail mailparse
50+ math mbstring mcrypt memcached misc mysqli network oauth openssl
51+ outcontrol password pcre pdo pgsql posix pthreads regex runkit reflection
52+ sca session session-pgsql simplexml soap sockets solr sphinx spl
53+ spl-types sqlite3 sqlsrv ssh2 stats stream strings taint tidy uodbc url
54+ var varnish xml xmlreader xmlrpc xmlwriter xsl yaf yar yaml zip zlib)
4455
4556 options[:only] = BOOKS.map { |s| "book.#{s}.html" }
4657
4758 options[:skip] = %w(
4859 control-structures.intro.html
4960 control-structures.alternative-syntax.html
50− function.mssql-select-db.html)
61+ function.mssql-select-db.html
62+ pthreads.modifiers.html)
5163
5264 options[:skip_patterns] = [/mysqlnd/]
5365
5466 options[:attribution] = <<-HTML
55− &copy; 1997&ndash;2015 The PHP Documentation Group<br>
67+ &copy; 1997&ndash;2016 The PHP Documentation Group<br>
5668 Licensed under the Creative Commons Attribution License v3.0 or later.
5769 HTML
5870 end