Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Phalcon version 3 and add Phalcon version 4 #1376

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 72 additions & 28 deletions lib/docs/filters/phalcon/clean_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,89 @@ module Docs
class Phalcon
class CleanHtmlFilter < Filter
def call
@doc = at_css('.body')

if root_page?
at_css('h1').content = 'Phalcon'
end
# left navigation bar
css('.doc-article-nav-wr').remove

css('#what-is-phalcon', '#other-formats').remove
# right navigation bar
css('.phalcon-blog__right-item').remove

css('#methods > p > strong, #constants > p > strong').each do |node|
node.parent.name = 'h3'
node.parent['id'] = node.content.parameterize
node.parent['class'] = 'method-signature'
node.parent.inner_html = node.parent.inner_html.sub(/inherited from .*/, '<small>\0</small>')
end
css('header').remove

css('.headerlink').each do |node|
id = node['href'][1..-1]
node.parent['id'] ||= id
node.remove
end
css('footer').remove

css('div[class^="highlight-"]').each do |node|
code = node.at_css('pre').content
code.remove! %r{\A\s*<\?php\s*} unless code.include?(' ?>')
node.content = code
node.name = 'pre'
node['data-language'] = node['class'][/highlight-(\w+)/, 1]
node['data-language'] = 'php' if node['data-language'] == 'html+php'
# initial table of contents
if !(slug=='index')
css('.docSearch-content > ul').remove
end

css('.section').each do |node|
node.before(node.children).remove
end
css('hr').remove

### syntax highlight ###

css('.highlighter-rouge').each do |node|

next if node.classes.include?('language-yaml')
next if node.classes.include?('language-ini')
node.set_attribute('data-language', 'php')
node.remove_class('highlighter-rouge')
node.add_class('highlight-php')

node.css('.kt').each do |subnode|
subnode.remove_class('kt')
subnode.add_class('token constant')
end

node.css('.nb, .n').each do |subnode|
subnode.remove_class('nb')
subnode.remove_class('n')
subnode.add_class('token function')
end

node.css('.k, .kn, .kc, .cp').each do |subnode|
subnode.remove_class('k')
subnode.remove_class('kn')
subnode.remove_class('kc')
subnode.remove_class('cp')
subnode.add_class('token keyword')
end

node.css('.nv, .no').each do |subnode|
subnode.remove_class('nv')
subnode.remove_class('no')
subnode.add_class('token variable')
end

node.css('.s2').each do |subnode|
subnode.remove_class('s2')
subnode.add_class('token double-quoted-string string')
end

node.css('.p').each do |subnode|
subnode.remove_class('p')
subnode.add_class('token punctuation')
end

node.css('.nc, .nf').each do |subnode|
subnode.remove_class('nc')
subnode.remove_class('nf')
subnode.add_class('token class-name')
end

node.css('.o').each do |subnode|
subnode.remove_class('o')
subnode.add_class('token operator')
end

node.css('.cd').each do |subnode|
subnode.remove_class('cd')
subnode.add_class('token comment')
end

css('table[border]').each do |node|
node.remove_attribute('border')
end

doc

end
end
end
Expand Down
22 changes: 9 additions & 13 deletions lib/docs/filters/phalcon/entries.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
module Docs
class Phalcon
class EntriesFilter < Docs::EntriesFilter

def get_name
(at_css('h1 > strong') || at_css('h1')).content.strip.remove('Phalcon\\')
return 'Phalcon' if slug == 'index'
at_css('h1').content.gsub(/\bClass\b|\bAbstract\b|\bFinal\b|Phalcon\\|\bInterface\b/i, '').strip
end

def get_type
if slug.start_with?('reference')
'Guides'
else
path = name.split('\\')
path[0] == 'Mvc' ? path[0..1].join('\\') : path[0]
end
name
end

def additional_entries
entries = []

css('.method-signature').each do |node|
next if node.content.include?('inherited from') || node.content.include?('protected ') || node.content.include?('private ')
name = node.at_css('strong').content.strip
next if name == '__construct' || name == '__toString'
name.prepend "#{self.name}::"
entries << [name, node['id']]
css('h1').each do |node|
entrie_name = node.content.gsub(/\bClass\b|\bAbstract\b|\bFinal\b|Phalcon\\|\bInterface\b/i, '').strip
next if entrie_name == name
entries << [entrie_name, node['id'], name]
end

entries
end

end
end
end
68 changes: 57 additions & 11 deletions lib/docs/scrapers/phalcon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,75 @@ class Phalcon < UrlScraper
html_filters.push 'phalcon/clean_html', 'phalcon/entries'

options[:root_title] = 'Phalcon'
options[:only_patterns] = [/reference\//, /api\//]
options[:skip] = %w(
api/index.html
reference/license.html)

options[:attribution] = <<-HTML
&copy; 2011&ndash;2017 Phalcon Framework Team<br>
Licensed under the Creative Commons Attribution License 3.0.
HTML

version '3' do
self.release = '3.1.1'
self.base_url = 'https://docs.phalconphp.com/en/latest/'
options[:trailing_slash] = true

version '4' do
self.release = '4.0'
self.base_url = "https://docs.phalcon.io/#{self.release}/en/api"
end

version '2' do
self.release = '2.0.13'
self.base_url = 'https://docs.phalconphp.com/en/2.0.0/'
version '3' do
self.release = '3.4'
self.base_url = "https://docs.phalcon.io/#{self.release}/en/api"

options[:fix_urls] = -> (url) do
url.sub!('Phalcon_Application_Exception', 'Phalcon_Application')
url.sub!('Phalcon_CryptInterface', 'Phalcon_Crypt')
url.sub!('Phalcon_Crypt_Mismatch', 'Phalcon_Crypt')
url.sub!('Phalcon_Crypt_Exception', 'Phalcon_Crypt')
url.sub!('Phalcon_EscaperInterface', 'Phalcon_Escaper')
url.sub!('Phalcon_Loader_Exception', 'Phalcon_Loader')
url.sub!('Phalcon_Mvc_CollectionInterface', 'Phalcon_Mvc_Collection')
url.sub!('Phalcon_Mvc_Collection_ManagerInterface', 'Phalcon_Mvc_Collection')
url.sub!('Phalcon_Mvc_Collection_BehaviorInterface', 'Phalcon_Mvc_Collection')
url.sub!('Phalcon_Mvc_Collection_Behavior', 'Phalcon_Mvc_Collection')
url.sub!('Phalcon_Mvc_ControllerInterface', 'Phalcon_Mvc_Controller')
url.sub!('Phalcon_Mvc_DispatcherInterface', 'Phalcon_Mvc_Dispatcher')
url.sub!('Phalcon_Mvc_Micro_Collection', 'Phalcon_Mvc_Micro')
url.sub!('Phalcon_Mvc_Micro_CollectionInterface', 'Phalcon_Mvc_Micro')
url.sub!('Phalcon_Mvc_ModelInterface', 'Phalcon_Mvc_Model')
url.sub!('Phalcon_Mvc_BehaviorInterface', 'Phalcon_Mvc_Behavior')
url.sub!('Phalcon_Mvc_Model_BinderInterface', 'Phalcon_Mvc_Model_Binder')
url.sub!('Phalcon_Mvc_Model_Managerinterface', 'Phalcon_Mvc_Model_Manager')
url.sub!('Phalcon_Mvc_Model_MessageInterface', 'Phalcon_Mvc_Model_Message')
url.sub!('Phalcon_Mvc_Model_QueryInterface', 'Phalcon_Mvc_Model_Query')
url.sub!('Phalcon_Mvc_Model_Query_StatusInterface', 'Phalcon_Mvc_Model_Query')
url.sub!('Phalcon_Mvc_Model_Query_Builder', 'Phalcon_Mvc_Model_Query')
url.sub!('Phalcon_Mvc_Model_Query_BuilderInterface', 'Phalcon_Mvc_Model_Query')
url.sub!('Phalcon_Mvc_Model_RelationInterface', 'Phalcon_Mvc_Model_Relation')
url.sub!('Phalcon_Mvc_Model_ResulsetInterface', 'Phalcon_Mvc_Model_Resulset')
url.sub!('Phalcon_Mvc_Model_Resulset_Simple', 'Phalcon_Mvc_Model_Resulset')
url.sub!('Phalcon_Mvc_Model_TransactionInterface', 'Phalcon_Mvc_Model_Transaction')
url.sub!('Phalcon_Mvc_Model_Transaction_ManagerInterface', 'Phalcon_Mvc_Model_Transaction')
url.sub!('Phalcon_Mvc_Model_Transaction_Exception', 'Phalcon_Mvc_Model_Transaction')
url.sub!('Phalcon_Mvc_Model_ValidatorInterface', 'Phalcon_Mvc_Model_Validator')
url.sub!('Phalcon_Mvc_Router_RouteInterface', 'Phalcon_Mvc_Router')
url.sub!('Phalcon_Mvc_RouterInterface', 'Phalcon_Mvc_Router')
url.sub!('Phalcon_Mvc_Router_Route', 'Phalcon_Mvc_Router')
url.sub!('Phalcon_Mvc_Router_GroupInterface', 'Phalcon_Mvc_Router')
url.sub!('Phalcon_Mvc_UrlInterface', 'Phalcon_Mvc_Url')
url.sub!('Phalcon_Mvc_ViewBaseInterface', 'Phalcon_Mvc_View')
url.sub!('Phalcon_Mvc_ViewInterface', 'Phalcon_Mvc_View')
url.sub!('Phalcon_Mvc_View_EngineInterface', 'Phalcon_Mvc_View')
url.sub!('Phalcon_Mvc_View_Engine', 'Phalcon_Mvc_View')
url.sub!('Phalcon_Mvc_View_Exception', 'Phalcon_Mvc_View')
url.sub!('Phalcon_Queue_Beanstalk', 'Phalcon_Queue')
url
end

end

def get_latest_version(opts)
doc = fetch_doc('https://docs.phalconphp.com/', opts)
doc.at_css('.header__lang.expand > div > ul > li > a').content
doc.css('.header-dropdown-wrapper').remove
doc.at_css('.header__right > .header__lang').content.strip
end

end
end