Skip to content

Commit 6512f29

Browse files
authored
Merge pull request #2221 from Cimbali/click
Add click documentation
2 parents d7e3e91 + 206993b commit 6512f29

File tree

7 files changed

+101
-1
lines changed

7 files changed

+101
-1
lines changed

assets/javascripts/news.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
[
33
"2024-02-20",
4-
"New documentation: <a href=\"/nextjs/\">Next.js</a>"
4+
"New documentations: <a href=\"/nextjs/\">Next.js</a>, <a href=\"/click/\">click</a>"
55
],
66
[
77
"2024-01-24",

lib/docs/filters/click/entries.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Docs
2+
class Click
3+
class EntriesFilter < Docs::EntriesFilter
4+
TYPE_BY_SLUG = {}
5+
6+
def call
7+
if root_page?
8+
css('section').each do |node|
9+
next if ['documentation', 'api-reference'].include?(node['id'])
10+
type = node.at_css('h2').content.strip
11+
node.css('li > a').each do |toclink|
12+
slug = toclink['href'].split('/')[-2]
13+
TYPE_BY_SLUG[slug] = type
14+
end
15+
end
16+
end
17+
super
18+
end
19+
20+
def get_name
21+
return at_css('h1').content.strip
22+
end
23+
24+
def get_type
25+
TYPE_BY_SLUG[slug.split('/').first] || at_css('h1').content.strip
26+
end
27+
28+
def include_default_entry?
29+
TYPE_BY_SLUG.include?(slug.split('/').first)
30+
end
31+
32+
def additional_entries
33+
return [] if root_page? || TYPE_BY_SLUG.include?(slug.split('/').first)
34+
35+
if slug == 'api/'
36+
entries = []
37+
doc.css('> section').each do |section|
38+
title = section.at_css('h2').content.strip
39+
section.css('dl.py > dt[id]').each do |dt|
40+
name = dt['id'].split('.')[1..].join('.')
41+
name << '()' if dt.parent.classes.intersect?(['function', 'method', 'classmethod', 'staticmethod'])
42+
entries << [name, dt['id'], title]
43+
end
44+
end
45+
return entries
46+
end
47+
48+
(doc.css('> section') || []).map do |section|
49+
title = section.at_css('h2').content.strip
50+
[title, section['id']]
51+
end
52+
end
53+
54+
private
55+
56+
end
57+
end
58+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Docs
2+
class Click
3+
class PreCleanHtmlFilter < Filter
4+
def call
5+
# Remove ¶ character from headers
6+
css('.headerlink').remove
7+
doc
8+
end
9+
end
10+
end
11+
end

lib/docs/scrapers/click.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Docs
2+
class Click < UrlScraper
3+
self.name = 'click'
4+
self.type = 'sphinx'
5+
self.root_path = 'index.html'
6+
self.links = {
7+
home: 'https://click.palletsprojects.com/',
8+
code: 'https://github.com/pallets/click'
9+
}
10+
11+
html_filters.push 'click/pre_clean_html', 'click/entries', 'sphinx/clean_html'
12+
13+
options[:container] = '.body > section'
14+
options[:skip] = ['changes/', 'genindex/', 'py-modindex/']
15+
options[:title] = false
16+
17+
options[:attribution] = <<-HTML
18+
&copy; Copyright 2014 Pallets.<br>
19+
Licensed under the BSD 3-Clause License.<br>
20+
We are not supported nor endorsed by Pallets.
21+
HTML
22+
23+
self.release = '8.1.x'
24+
self.base_url = "https://click.palletsprojects.com/en/#{self.release}/"
25+
26+
def get_latest_version(opts)
27+
get_latest_github_release('pallets', 'click', opts)
28+
end
29+
end
30+
end

public/icons/docs/click/16.png

641 Bytes
Loading
797 Bytes
Loading

public/icons/docs/click/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/pallets/click/blob/main/docs/_static/click-icon.png

0 commit comments

Comments
 (0)