Update and improve PHP documentation (7.0.3)

pull/343/merge
Thibaut Courouble 9 years ago
parent b8658d9708
commit 44e1f216c4

@ -311,7 +311,7 @@ credits = [
'https://raw.githubusercontent.com/phoenixframework/phoenix/master/LICENSE.md' 'https://raw.githubusercontent.com/phoenixframework/phoenix/master/LICENSE.md'
], [ ], [
'PHP', 'PHP',
'1997-2015 The PHP Documentation Group', '1997-2016 The PHP Documentation Group',
'CC BY', 'CC BY',
'https://creativecommons.org/licenses/by/3.0/' 'https://creativecommons.org/licenses/by/3.0/'
], [ ], [

@ -4,6 +4,7 @@
@extend %lined-heading; @extend %lined-heading;
} }
h2 { @extend %block-heading; }
h3.title { @extend %block-heading; } h3.title { @extend %block-heading; }
.verinfo { .verinfo {

@ -186,5 +186,66 @@ module Docs
Typhoeus.stub(root_url.to_s).and_return(response) Typhoeus.stub(root_url.to_s).and_return(response)
end end
end end
module FixInternalUrlsBehavior
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
attr_reader :internal_urls
def store_pages(store)
instrument 'info.doc', msg: 'Building internal urls...'
with_internal_urls do
instrument 'info.doc', msg: 'Building pages...'
super
end
end
private
def with_internal_urls
@internal_urls = new.fetch_internal_urls
yield
ensure
@internal_urls = nil
end
end
def fetch_internal_urls
result = []
build_pages do |page|
result << base_url.subpath_to(page[:response_url]) if page[:entries].present?
end
result
end
def initial_urls
return super unless self.class.internal_urls
@initial_urls ||= self.class.internal_urls.map(&method(:url_for)).freeze
end
private
def additional_options
if self.class.internal_urls
{
only: self.class.internal_urls.to_set,
only_patterns: nil,
skip: nil,
skip_patterns: nil,
skip_links: nil,
fixed_internal_urls: true
}
else
{}
end
end
def process_response(response)
super.merge! response_url: response.url
end
end
end end
end end

@ -25,6 +25,18 @@ module Docs
node.inner_html = node.inner_html.gsub(br, "\n") node.inner_html = node.inner_html.gsub(br, "\n")
node.content = node.content node.content = node.content
end end
css('> h2:first-child.title').each do |node|
node.name = 'h1'
end
css('div.partintro', 'div.section').each do |node|
node.before(node.children).remove
end
css('.title + .verinfo + .title').each do |node|
node.after(node.previous_element)
end
end end
end end
end end

@ -25,6 +25,7 @@ module Docs
'tidy' => 'Tidy', 'tidy' => 'Tidy',
'Worker' => 'pthreads', 'Worker' => 'pthreads',
'XsltProcessor' => 'XSLT', 'XsltProcessor' => 'XSLT',
'Yar' => 'Yar',
'ZipArchive' => 'Zip' } 'ZipArchive' => 'Zip' }
%w(APC Directory DOM Event Gearman Gmagick Imagick mysqli OAuth PDO Reflection %w(APC Directory DOM Event Gearman Gmagick Imagick mysqli OAuth PDO Reflection
@ -46,13 +47,16 @@ module Docs
end end
REPLACE_TYPES = { REPLACE_TYPES = {
'Error' => 'Errors',
'Exceptions' => 'SPL/Exceptions', 'Exceptions' => 'SPL/Exceptions',
'finfo' => 'File System',
'GD and Image' => 'Image', 'GD and Image' => 'Image',
'Gmagick' => 'Image/GraphicsMagick', 'Gmagick' => 'Image/GraphicsMagick',
'Imagick' => 'Image/ImageMagick', 'Imagick' => 'Image/ImageMagick',
'Interfaces' => 'SPL/Interfaces', 'Interfaces' => 'SPL/Interfaces',
'Iterators' => 'SPL/Iterators', 'Iterators' => 'SPL/Iterators',
'mysqli' => 'Database/MySQL', 'mysqli' => 'Database/MySQL',
'PCRE Patterns' => 'PCRE Reference',
'PostgreSQL' => 'Database/PostgreSQL', 'PostgreSQL' => 'Database/PostgreSQL',
'Session' => 'Sessions', 'Session' => 'Sessions',
'Session PgSQL' => 'Database/PostgreSQL', 'Session PgSQL' => 'Database/PostgreSQL',
@ -62,7 +66,7 @@ module Docs
'Yaml' => 'YAML' } 'Yaml' => 'YAML' }
TYPE_GROUPS = { TYPE_GROUPS = {
'Classes and Functions' => ['Classes/Object', 'Function handling', 'Predefined Interfaces and Classes', 'runkit'], 'Classes and Functions' => ['Classes/Object', 'Function handling', 'Predefined Interfaces and Classes', 'runkit', 'Throwable'],
'Encoding' => ['Gettext', 'iconv', 'Multibyte String'], 'Encoding' => ['Gettext', 'iconv', 'Multibyte String'],
'Compression' => ['Bzip2', 'Zip', 'Zlib'], 'Compression' => ['Bzip2', 'Zip', 'Zlib'],
'Cryptography' => ['Hash', 'Mcrypt', 'OpenSSL', 'Password Hashing'], 'Cryptography' => ['Hash', 'Mcrypt', 'OpenSSL', 'Password Hashing'],
@ -90,6 +94,9 @@ module Docs
end end
def get_type def get_type
return 'Language Reference' if subpath.start_with?('language.')
return 'PCRE Reference' if subpath.start_with?('regexp.')
type = at_css('.up').content.strip type = at_css('.up').content.strip
type = 'SPL/Iterators' if type.end_with? 'Iterator' type = 'SPL/Iterators' if type.end_with? 'Iterator'
type.remove! ' Functions' type.remove! ' Functions'
@ -108,7 +115,7 @@ module Docs
end end
def include_default_entry? def include_default_entry?
!initial_page? && doc.at_css('.reference', '.refentry', '.sect1') !initial_page? && doc.at_css('.reference', '.refentry', '.sect1', '.simpara', '.para')
end end
end end
end end

@ -3,7 +3,7 @@ module Docs
class FixUrlsFilter < Filter class FixUrlsFilter < Filter
def call def call
html.gsub! File.join(Php.base_url, Php.root_path), Php.base_url html.gsub! File.join(Php.base_url, Php.root_path), Php.base_url
html.gsub! %r{http://www\.php\.net/manual/en/([^"']+?)\.html}, 'http://www.php.net/manual/en/\1.php' html.gsub! %r{https://secure\.php\.net/manual/en/([^"']+?)\.html}, 'https://secure.php.net/manual/en/\1.php'
html html
end end
end end

@ -2,9 +2,12 @@ module Docs
class Php class Php
class InternalUrlsFilter < Filter class InternalUrlsFilter < Filter
def call def call
return doc if context[:fixed_internal_urls]
if subpath.start_with?('book.') || subpath.start_with?('class.') if subpath.start_with?('book.') || subpath.start_with?('class.')
result[:internal_urls] = internal_urls result[:internal_urls] = internal_urls
end end
doc doc
end end

@ -1,19 +1,28 @@
module Docs module Docs
class Php < FileScraper class Php < FileScraper
include FixInternalUrlsBehavior
self.name = 'PHP' self.name = 'PHP'
self.type = 'php' self.type = 'php'
self.release = 'up to 5.6.13' self.release = 'up to 7.0.3'
self.base_url = 'http://www.php.net/manual/en/' self.base_url = 'https://secure.php.net/manual/en/'
self.root_path = 'index.html' self.root_path = 'index.html'
self.initial_paths = %w( self.initial_paths = %w(
funcref.html funcref.html
langref.html
refs.database.html refs.database.html
set.mysqlinfo.html set.mysqlinfo.html
language.control-structures.html language.control-structures.html
reference.pcre.pattern.syntax.html
reserved.exceptions.html reserved.exceptions.html
reserved.interfaces.html reserved.interfaces.html
reserved.variables.html) reserved.variables.html)
self.links = {
home: 'https://secure.php.net/',
code: 'https://github.com/php/php-src'
}
# Downloaded from php.net/download-docs.php # Downloaded from php.net/download-docs.php
self.dir = '/Users/Thibaut/DevDocs/Docs/PHP' self.dir = '/Users/Thibaut/DevDocs/Docs/PHP'
@ -25,34 +34,37 @@ module Docs
options[:skip_links] = ->(filter) { !filter.initial_page? } options[:skip_links] = ->(filter) { !filter.initial_page? }
options[:only_patterns] = [ options[:only_patterns] = [
/\Alanguage\./,
/\Aclass\./, /\Aclass\./,
/\Afunction\./, /\Afunction\./,
/\Acontrol-structures/, /\Acontrol-structures/,
/\Aregexp\./,
/\Areserved\.exceptions/, /\Areserved\.exceptions/,
/\Areserved\.interfaces/, /\Areserved\.interfaces/,
/\Areserved\.variables/] /\Areserved\.variables/]
BOOKS = %w(apache apc array bc bzip2 calendar classobj ctype curl datetime BOOKS = %w(apache apc array bc bzip2 calendar csprng classobj ctype curl
dba dir dom eio errorfunc event exec fileinfo filesystem filter ftp funchand datetime dba dir dom eio errorfunc event exec fileinfo filesystem filter
gearman geoip gettext gmagick hash http iconv iisfunc image imagick imap ftp funchand gearman geoip gettext gmagick gmp hash iconv iisfunc image
info inotify intl json ldap libevent libxml mail mailparse math mbstring imagick imap info inotify intl json ldap libevent libxml mail mailparse
mcrypt memcached misc mysqli network oauth openssl outcontrol password math mbstring mcrypt memcached misc mysqli network oauth openssl
pcre pdo pgsql posix pthreads regex runkit reflection session outcontrol password pcre pdo pgsql posix pthreads regex runkit reflection
session-pgsql simplexml soap sockets solr sphinx spl spl-types sqlite3 sca session session-pgsql simplexml soap sockets solr sphinx spl
sqlsrv ssh2 stats stream strings taint tidy uodbc url var varnish xml spl-types sqlite3 sqlsrv ssh2 stats stream strings taint tidy uodbc url
xmlreader xmlrpc xmlwriter xsl yaf yaml zip zlib) var varnish xml xmlreader xmlrpc xmlwriter xsl yaf yar yaml zip zlib)
options[:only] = BOOKS.map { |s| "book.#{s}.html" } options[:only] = BOOKS.map { |s| "book.#{s}.html" }
options[:skip] = %w( options[:skip] = %w(
control-structures.intro.html control-structures.intro.html
control-structures.alternative-syntax.html control-structures.alternative-syntax.html
function.mssql-select-db.html) function.mssql-select-db.html
pthreads.modifiers.html)
options[:skip_patterns] = [/mysqlnd/] options[:skip_patterns] = [/mysqlnd/]
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 1997&ndash;2015 The PHP Documentation Group<br> &copy; 1997&ndash;2016 The PHP Documentation Group<br>
Licensed under the Creative Commons Attribution License v3.0 or later. Licensed under the Creative Commons Attribution License v3.0 or later.
HTML HTML
end end

Loading…
Cancel
Save