From f3472a073b3f52a30c01590382458236180c14ad Mon Sep 17 00:00:00 2001 From: Phil Scherer Date: Sun, 15 Nov 2020 09:29:35 +0000 Subject: [PATCH] Update CakePHP documentation --- .../filters/cakephp/clean_html_39_plus.rb | 37 +++++++++ lib/docs/filters/cakephp/entries_39_plus.rb | 52 ++++++++++++ lib/docs/scrapers/cakephp.rb | 79 ++++++++++++++++++- 3 files changed, 164 insertions(+), 4 deletions(-) create mode 100755 lib/docs/filters/cakephp/clean_html_39_plus.rb create mode 100755 lib/docs/filters/cakephp/entries_39_plus.rb diff --git a/lib/docs/filters/cakephp/clean_html_39_plus.rb b/lib/docs/filters/cakephp/clean_html_39_plus.rb new file mode 100755 index 00000000..955ef715 --- /dev/null +++ b/lib/docs/filters/cakephp/clean_html_39_plus.rb @@ -0,0 +1,37 @@ +module Docs + class Cakephp + class CleanHtml39PlusFilter < Filter + def call + @doc = root_page? ? at_css('#content') : at_css('#right').at_css('div') + + css('a.permalink').remove + + css('.member-summary h3').each do |node| + node.name = 'div' + node.remove_attribute('class') + end + + css('h6').each do |node| + node.name = 'h4' + end + + css('pre').each do |node| + node.content = node.content.strip + node['data-language'] = 'php' + end + + # Move dummy anchor to method and property name + + css('.method-detail').each do |node| + node.at_css('.method-name')['id'] = node.at_css('a')['id'] + end + + css('.property-detail').each do |node| + node.at_css('.property-name')['id'] = node.at_css('a')['id'] + end + + doc + end + end + end +end diff --git a/lib/docs/filters/cakephp/entries_39_plus.rb b/lib/docs/filters/cakephp/entries_39_plus.rb new file mode 100755 index 00000000..2b628b6f --- /dev/null +++ b/lib/docs/filters/cakephp/entries_39_plus.rb @@ -0,0 +1,52 @@ +module Docs + class Cakephp + class Entries39PlusFilter < Docs::EntriesFilter + def page_type + @page_type ||= slug.split('-').first + end + + def slug_without_page_type + @slug_without_page_type ||= slug.split('-').last + end + + def get_name + case page_type + when 'class', 'trait', 'interface' + slug.split('.').last.concat(" (#{self.page_type})") + when 'namespace' + slug_without_page_type.split('.').tap do |path| + path.shift if path.length > 1 + end.join('\\').concat(" (namespace)") + end + end + + def get_type + case page_type + when 'class', 'trait', 'interface' + slug_without_page_type.split('.')[1..-2].join('\\') + when 'namespace' + slug_without_page_type.split('.')[1..-1].join('\\') + end + end + + def additional_entries + return [] unless page_type == 'class' + class_name = slug.split('.').last + return [] if class_name.end_with?('Exception') + entries = [] + + css('h3.method-name').each do |node| + method_name = node['id'].concat('()') + entries << ["#{class_name}::#{method_name}", node['id']] + end + + css('h3.property-name').each do |node| + property_name = node['id'] + entries << ["#{class_name}::#{property_name}", node['id']] + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/cakephp.rb b/lib/docs/scrapers/cakephp.rb index d913a214..e240a592 100644 --- a/lib/docs/scrapers/cakephp.rb +++ b/lib/docs/scrapers/cakephp.rb @@ -8,10 +8,6 @@ module Docs code: 'https://github.com/cakephp/cakephp' } - html_filters.push 'cakephp/clean_html', 'cakephp/entries' - - options[:container] = '#right' - options[:skip_patterns] = [/\Asource-/] options[:attribution] = <<-HTML @@ -21,64 +17,139 @@ module Docs We are not endorsed by or affiliated with CakePHP. HTML + version '4.1' do + self.release = '4.1.6' + self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html_39_plus', 'cakephp/entries_39_plus' + + options[:container] = '.page-container' + end + + version '4.0' do + self.release = '4.0.8' + self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html_39_plus', 'cakephp/entries_39_plus' + + options[:container] = '.page-container' + end + + version '3.9' do + self.release = '3.9.4' + self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html_39_plus', 'cakephp/entries_39_plus' + + options[:container] = '.page-container' + end + version '3.8' do self.release = '3.8.3' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.7' do self.release = '3.7.9' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.6' do self.release = '3.6.15' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.5' do self.release = '3.5.15' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.4' do self.release = '3.4.13' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.3' do self.release = '3.3.15' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.2' do self.release = '3.2.14' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '3.1' do self.release = '3.1.13' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '2.10' do self.release = '2.10.3' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '2.9' do self.release = '2.9.4' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '2.8' do self.release = '2.8.8' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end version '2.7' do self.release = '2.7.11' self.base_url = "https://api.cakephp.org/#{self.version}/" + + html_filters.push 'cakephp/clean_html', 'cakephp/entries' + + options[:container] = '#right' end def get_latest_version(opts)