From 131f97a918660b2e11b072f5cef132defb4e991d Mon Sep 17 00:00:00 2001 From: Cimbali Date: Fri, 17 May 2024 12:10:36 +0200 Subject: [PATCH 1/5] Add click documentation --- lib/docs/filters/click/clean_html.rb | 15 ++++++++ lib/docs/filters/click/entries.rb | 45 +++++++++++++++++++++++ lib/docs/filters/click/pre_clean_html.rb | 11 ++++++ lib/docs/scrapers/click.rb | 29 +++++++++++++++ public/icons/docs/click/16.png | Bin 0 -> 641 bytes public/icons/docs/click/16@2x.png | Bin 0 -> 797 bytes public/icons/docs/click/SOURCE | 1 + 7 files changed, 101 insertions(+) create mode 100644 lib/docs/filters/click/clean_html.rb create mode 100644 lib/docs/filters/click/entries.rb create mode 100644 lib/docs/filters/click/pre_clean_html.rb create mode 100644 lib/docs/scrapers/click.rb create mode 100644 public/icons/docs/click/16.png create mode 100644 public/icons/docs/click/16@2x.png create mode 100644 public/icons/docs/click/SOURCE diff --git a/lib/docs/filters/click/clean_html.rb b/lib/docs/filters/click/clean_html.rb new file mode 100644 index 00000000..914ee6b4 --- /dev/null +++ b/lib/docs/filters/click/clean_html.rb @@ -0,0 +1,15 @@ +module Docs + class Click + class CleanHtmlFilter < Filter + def call + if root_page? + # Image renders quite badly in dark mode + at_css('h1 + a.image-reference').remove + # All superfluous + css('#documentation, #api-reference, #miscellaneous-pages').remove + end + doc + end + end + end +end diff --git a/lib/docs/filters/click/entries.rb b/lib/docs/filters/click/entries.rb new file mode 100644 index 00000000..09b3a761 --- /dev/null +++ b/lib/docs/filters/click/entries.rb @@ -0,0 +1,45 @@ +module Docs + class Click + class EntriesFilter < Docs::EntriesFilter + + def initialize(*) + super + end + + def get_name + return at_css('h1').content.strip + end + + def get_type + return at_css('h1').content.strip + end + + def include_default_entry? + false + end + + def additional_entries + return [] if root_page? + + if slug == 'api/' + entries = [] + doc.css('> section').each do |section| + title = section.at_css('h2').content.strip + section.css('> dl.py > dt[id]').each do |dt| + entries << [dt['id'], dt['id'], title] + end + end + return entries + end + + (doc.css('> section') || []).map do |section| + title = section.at_css('h2').content.strip + [title, section['id']] + end + end + + private + + end + end +end diff --git a/lib/docs/filters/click/pre_clean_html.rb b/lib/docs/filters/click/pre_clean_html.rb new file mode 100644 index 00000000..6413aa61 --- /dev/null +++ b/lib/docs/filters/click/pre_clean_html.rb @@ -0,0 +1,11 @@ +module Docs + class Click + class PreCleanHtmlFilter < Filter + def call + # Remove ¶ character from tag w/ name & type + css('.headerlink').remove + doc + end + end + end +end diff --git a/lib/docs/scrapers/click.rb b/lib/docs/scrapers/click.rb new file mode 100644 index 00000000..7e0121cc --- /dev/null +++ b/lib/docs/scrapers/click.rb @@ -0,0 +1,29 @@ +module Docs + class Click < UrlScraper + self.name = 'click' + self.type = 'sphinx' #'simple' + self.release = '8.1.7' + self.base_url = 'https://click.palletsprojects.com/en/8.1.x/' + self.root_path = 'index.html' + self.links = { + home: 'https://click.palletsprojects.com/', + code: 'https://github.com/pallets/click' + } + + html_filters.push 'click/pre_clean_html', 'click/entries', 'click/clean_html', 'sphinx/clean_html', 'title' + + options[:skip] = ['changes/', 'genindex/', 'py-modindex/', 'license/'] + options[:container] = '.body > section' + options[:title] = false + + options[:attribution] = <<-HTML + © Copyright 2014 Pallets.
+ Licensed under the BSD 3-Clause License.
+ We are not supported nor endorsed by Pallets. + HTML + + def get_latest_version(opts) + get_latest_github_release('pallets', 'click', opts) + end + end +end diff --git a/public/icons/docs/click/16.png b/public/icons/docs/click/16.png new file mode 100644 index 0000000000000000000000000000000000000000..d1497c30c0c30a981c9956370eee509d2a5f7341 GIT binary patch literal 641 zcmV-{0)G98P)EX>4Tx04R}tkv&MmKpe$iTT4Z%B6bjQ2vVKwq9Ts93Pq?8YK2xEOfLO`CJjl7 zi=*ILaPVWX>fqw6tAnc`2!4P#J2)x2NQwVT3N2zhIPS;0dyl(!fWJ{;s@W9>RLwHd z$%K&2tqP%61Tla<#4su`Q=b#X6g)J&;^Mfxh}i>#<}RQpJzslOnRO;LM#+JSngm}GF0Me;;5o(l<&{F ztZ?4qtX68Qbx;1na9&$k<~q$0B(aDkh!7y7hB7L!sIM|KQcR?2KjGmYcKjl_WO9|k z$gzMbR7j2={11M2YZj&^-K1~=2)@|%#~2XW1)6o+{yw(t<_QpZ2ClTWzuEw1KS{5* zwdfJhzYSbmw>5bWxZDATo^;8O94SE4Unl_YXY@@uVDJ{`S#x`9?c?+T$WT|Q8{ps& z7%x)xy2rb_JA3>0Osl^iyz+9yfFmui00006VoOIv0RI600RN!9r;`8x010qNS#tmY z3ljhU3ljkVnw%H_000McNliru=milDFAnLvw50$50DehCK~y-)?b0y{!cY)|;qRG; z7)T-F3A~aP_Ff=uE|Vi@>pASjTJQj3qs?L=C`k$nahidJe|MH${`x_!Fd7Q4aX^jK z7cQ{HxG!9U-*H2OBhEwDm|=%$S0INcY_Pxu*O!z_%%eWR3HwO?RD~Ahn?X6600000NkvXXu0mjf7?KhQ literal 0 HcmV?d00001 diff --git a/public/icons/docs/click/16@2x.png b/public/icons/docs/click/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..3bc91ffbd56e0e6075714c6b4131c1e06c140c54 GIT binary patch literal 797 zcmV+&1LFLNP)EX>4Tx04R}tkv&MmKpe$iTT4Z%B6bjQ2vVKwq9Ts93Pq?8YK2xEOfLO`CJjl7 zi=*ILaPVWX>fqw6tAnc`2!4P#J2)x2NQwVT3N2zhIPS;0dyl(!fWJ{;s@W9>RLwHd z$%K&2tqP%61Tla<#4su`Q=b#X6g)J&;^Mfxh}i>#<}RQpJzslOnRO;LM#+JSngm}GF0Me;;5o(l<&{F ztZ?4qtX68Qbx;1na9&$k<~q$0B(aDkh!7y7hB7L!sIM|KQcR?2KjGmYcKjl_WO9|k z$gzMbR7j2={11M2YZj&^-K1~=2)@|%#~2XW1)6o+{yw(t<_QpZ2ClTWzuEw1KS{5* zwdfJhzYSbmw>5bWxZDATo^;8O94SE4Unl_YXY@@uVDJ{`S#x`9?c?+T$WT|Q8{ps& z7%x)xy2rb_JA3>0Osl^iyz+9yfFmui00006VoOIv0RI600RN!9r;`8x010qNS#tmY z3ljhU3ljkVnw%H_000McNliru=milDE<2_aLB{|90UAj}K~z}7?bN$U13?tV@n7zW z#?DF+TN_Jl1q;!)u(Ov`zJZ0kot9#wU>)!Q?6eUP#74mz+8D?tHWQF#6Jn7p$oyeo zIWT)J^L>X%Boc{4BK@gjKF;n6Bn?I8+_vcOQT9w%7|^@6mPh~3_fvq8v_PR0+!&rga0MTD9^zlWr_@b7t03yupaM$R!wx2b6Yj8$hXKi_(7 Date: Fri, 17 May 2024 17:29:38 +0200 Subject: [PATCH 2/5] Simplify processing, add multiple versions --- lib/docs/filters/click/clean_html.rb | 15 ------- lib/docs/filters/click/pre_clean_html.rb | 2 +- lib/docs/scrapers/click.rb | 53 +++++++++++++++++++++--- 3 files changed, 49 insertions(+), 21 deletions(-) delete mode 100644 lib/docs/filters/click/clean_html.rb diff --git a/lib/docs/filters/click/clean_html.rb b/lib/docs/filters/click/clean_html.rb deleted file mode 100644 index 914ee6b4..00000000 --- a/lib/docs/filters/click/clean_html.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Docs - class Click - class CleanHtmlFilter < Filter - def call - if root_page? - # Image renders quite badly in dark mode - at_css('h1 + a.image-reference').remove - # All superfluous - css('#documentation, #api-reference, #miscellaneous-pages').remove - end - doc - end - end - end -end diff --git a/lib/docs/filters/click/pre_clean_html.rb b/lib/docs/filters/click/pre_clean_html.rb index 6413aa61..e0552a6a 100644 --- a/lib/docs/filters/click/pre_clean_html.rb +++ b/lib/docs/filters/click/pre_clean_html.rb @@ -2,7 +2,7 @@ module Docs class Click class PreCleanHtmlFilter < Filter def call - # Remove ¶ character from tag w/ name & type + # Remove ¶ character from headers css('.headerlink').remove doc end diff --git a/lib/docs/scrapers/click.rb b/lib/docs/scrapers/click.rb index 7e0121cc..ce5167f4 100644 --- a/lib/docs/scrapers/click.rb +++ b/lib/docs/scrapers/click.rb @@ -1,19 +1,17 @@ module Docs class Click < UrlScraper self.name = 'click' - self.type = 'sphinx' #'simple' - self.release = '8.1.7' - self.base_url = 'https://click.palletsprojects.com/en/8.1.x/' + self.type = 'sphinx' self.root_path = 'index.html' self.links = { home: 'https://click.palletsprojects.com/', code: 'https://github.com/pallets/click' } - html_filters.push 'click/pre_clean_html', 'click/entries', 'click/clean_html', 'sphinx/clean_html', 'title' + html_filters.push 'click/pre_clean_html', 'click/entries', 'sphinx/clean_html' - options[:skip] = ['changes/', 'genindex/', 'py-modindex/', 'license/'] options[:container] = '.body > section' + options[:skip] = ['changes/', 'genindex/', 'py-modindex/'] options[:title] = false options[:attribution] = <<-HTML @@ -22,6 +20,51 @@ module Docs We are not supported nor endorsed by Pallets. HTML + version '8.1' do + self.release = '8.1.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '8.0' do + self.release = '8.0.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '7' do + self.release = '7.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '6' do + self.release = '6.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '5' do + self.release = '5.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '4' do + self.release = '4.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '3' do + self.release = '3.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '2' do + self.release = '2.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + + version '1' do + self.release = '1.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" + end + def get_latest_version(opts) get_latest_github_release('pallets', 'click', opts) end From d6274d6b26d0690b8b09b9bee7bcbe1ae8745789 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Sat, 18 May 2024 01:29:25 +0200 Subject: [PATCH 3/5] Include license etc. as misc pages, based on main page --- lib/docs/filters/click/entries.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/docs/filters/click/entries.rb b/lib/docs/filters/click/entries.rb index 09b3a761..9512eb8a 100644 --- a/lib/docs/filters/click/entries.rb +++ b/lib/docs/filters/click/entries.rb @@ -1,8 +1,19 @@ module Docs class Click class EntriesFilter < Docs::EntriesFilter - - def initialize(*) + TYPE_BY_SLUG = {} + + def call + if root_page? + css('section').each do |node| + next if ['documentation', 'api-reference'].include?(node['id']) + type = node.at_css('h2').content.strip + node.css('li > a').each do |toclink| + slug = toclink['href'].split('/')[-2] + TYPE_BY_SLUG[slug] = type + end + end + end super end @@ -11,15 +22,15 @@ module Docs end def get_type - return at_css('h1').content.strip + TYPE_BY_SLUG[slug.split('/').first] || at_css('h1').content.strip end def include_default_entry? - false + TYPE_BY_SLUG.include?(slug.split('/').first) end def additional_entries - return [] if root_page? + return [] if root_page? || TYPE_BY_SLUG.include?(slug.split('/').first) if slug == 'api/' entries = [] From 8db6ffce17405c13cf5e55d2fdf7a094918f2af5 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Thu, 23 May 2024 15:51:57 +0100 Subject: [PATCH 4/5] Adjust API entry selection and naming Get all (not only top-level) definitions, add () suffix on functions (and methods of all kinds). --- lib/docs/filters/click/entries.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/docs/filters/click/entries.rb b/lib/docs/filters/click/entries.rb index 9512eb8a..01fa1a72 100644 --- a/lib/docs/filters/click/entries.rb +++ b/lib/docs/filters/click/entries.rb @@ -36,8 +36,10 @@ module Docs entries = [] doc.css('> section').each do |section| title = section.at_css('h2').content.strip - section.css('> dl.py > dt[id]').each do |dt| - entries << [dt['id'], dt['id'], title] + section.css('dl.py > dt[id]').each do |dt| + name = dt['id'].split('.')[1..].join('.') + name << '()' if dt.parent.classes.intersect?(['function', 'method', 'classmethod', 'staticmethod']) + entries << [name, dt['id'], title] end end return entries From 206993ba1b88ecca03c102cf762adf866645d0de Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Wed, 12 Jun 2024 21:02:38 +0200 Subject: [PATCH 5/5] Update click documentation (8.1.x) --- assets/javascripts/news.json | 2 +- lib/docs/scrapers/click.rb | 46 ++---------------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/assets/javascripts/news.json b/assets/javascripts/news.json index d7ae6452..07dc5645 100644 --- a/assets/javascripts/news.json +++ b/assets/javascripts/news.json @@ -1,7 +1,7 @@ [ [ "2024-02-20", - "New documentation: Next.js" + "New documentations: Next.js, click" ], [ "2024-01-24", diff --git a/lib/docs/scrapers/click.rb b/lib/docs/scrapers/click.rb index ce5167f4..71c2a423 100644 --- a/lib/docs/scrapers/click.rb +++ b/lib/docs/scrapers/click.rb @@ -20,50 +20,8 @@ module Docs We are not supported nor endorsed by Pallets. HTML - version '8.1' do - self.release = '8.1.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '8.0' do - self.release = '8.0.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '7' do - self.release = '7.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '6' do - self.release = '6.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '5' do - self.release = '5.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '4' do - self.release = '4.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '3' do - self.release = '3.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '2' do - self.release = '2.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end - - version '1' do - self.release = '1.x' - self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" - end + self.release = '8.1.x' + self.base_url = "https://click.palletsprojects.com/en/#{self.release}/" def get_latest_version(opts) get_latest_github_release('pallets', 'click', opts)