History

Add Tcl/Tk documentation

All commands without extension C-API. No fancy style or anything.

Tobias committed 11 years ago

Commit ae7a5ab1 parent a24a2ce9 files · +171 −-2Browse files

Showing the changes to lib/docs (3 of 9 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/tcl_tk/clean_html.rb +52 −0
  2. lib/docs/filters/tcl_tk/entries.rb +57 −0
  3. lib/docs/scrapers/tcl_tk.rb +42 −0
lib/docs/filters/tcl_tk/clean_html.rb+52−0
@@ -0,0 +1,52 @@
1module Docs
2 class TclTk
3 class CleanHtmlFilter < Filter
4 def call
5 # Page Title
6 css('h2').remove
7 # Navigation
8 css('h3:first-child').remove
9 # restore breaks in copyright
10 txt = at_css('div.copy').content
11 at_css('div.copy').content = txt.gsub! /.Copyright/, "\n\\0"
12
13 file = result[:path].split('/')[-1]
14 re = Regexp.new('^' + Regexp.escape(file) + '(#.*)$')
15 css('a[name]').each do |node|
16 if node['href'] then
17 # useless name
18 node.remove_attribute 'name'
19 # make fragments relativ
20 if node['href'].match re then
21 node['href'] = node['href'].sub re, '\\1'
22 end
23 else
24 # move name to id
25 node.parent['id'] = node['name']
26 node.parent.content = node.content
27 end
28 end
29
30 # remove keywords headline
31 css('h3').each do |node|
32 if node.content == 'KEYWORDS' then
33 node.remove
34 end
35 end
36 # remove keywords links
37 css('a').each do |node|
38 attr = node.attribute('href')
39 if attr && attr.value.match(/\/Keywords\//) then
40 # the ','
41 if node.next_sibling then
42 node.next_sibling.remove
43 end
44 node.remove
45 end
46 end
47
48 doc
49 end
50 end
51 end
52end
lib/docs/filters/tcl_tk/entries.rb+57−0
@@ -0,0 +1,57 @@
1module Docs
2 class TclTk
3 class EntriesFilter < Docs::EntriesFilter
4 #def additional_entries
5 # type = nil
6 #end
7
8 def split_slug
9 slug.sub! /\.html?/, ''
10 return *slug.split('/')
11 end
12
13 TYPE_MAP = {
14 'TclCmd' => 'Tcl',
15 'TkCmd' => 'Tk',
16 'ItclCmd' => 'incr',
17 'SqliteCmd' => 'tdbc',
18 'TdbcCmd' => 'tdbc',
19 'TdbcmysqlCmd' => 'tdbc',
20 'TdbcodbcCmd' => 'tdbc',
21 'TdbcpostgresCmd' => 'tdbc',
22 'TdbcsqliteCmd' => 'tdbc',
23 'ThreadCmd' => 'Thread',
24 'UserCmd' => 'App'
25 }
26
27 def get_type
28 type, name = split_slug
29 type = TYPE_MAP[type] || type
30 if name == 'contents' then
31 type = nil
32 end
33 type
34 end
35
36 def get_name
37 type, name = split_slug
38 name
39 end
40
41 def additional_entries
42 type, name = split_slug
43 if type != 'TclCmd' || name != 'library' then
44 return []
45 end
46 # special rule for library page which contains multiple commands at once
47 entries = []
48 css('a > b').each do |node|
49 text = node.content.strip
50 id = node.parent['href'].sub /^.*#(.*)$/, '\\1'
51 entries << [text, id, TYPE_MAP[type]]
52 end
53 return entries
54 end
55 end
56 end
57end
lib/docs/scrapers/tcl_tk.rb+42−0
@@ -0,0 +1,42 @@
1module Docs
2 class TclTk < UrlScraper
3 self.name = 'Tcl/Tk'
4 self.type = 'tcl_tk'
5 self.slug = 'tcl'
6 self.version = '8.6'
7 # test URL:
8 self.base_url = 'http://localhost/tcl/'
9 # real URL:
10 #self.base_url = 'http://www.tcl.tk/man/tcl/'
11 self.root_path = 'contents.htm'
12
13 html_filters.push 'tcl_tk/clean_html', 'tcl_tk/entries'
14
15 options[:skip_links] = false
16
17 options[:trailing_slash] = false
18 options[:skip] = ['siteinfo.htm']
19 options[:skip_patterns] = [
20 # ignore keyword list pages
21 /^Keywords\//,
22 # ignore C-API, only required for extension developers
23 /^TclLib\//,
24 /^TkLib\//,
25 /^ItclLib\//,
26 /^TdbcLib\//
27 ]
28
29 # TODO can't figure out howto convert .htm => .html in filenames
30 # to save as "xyz.html" instead of "xyz.htm.html"
31 #options[:fix_urls] = ->(url) do
32 # url.sub! /\.htm($|#)/, '.html\\1'
33 # url
34 #end
35
36 # Each Page contains a specific list of copyrights, only add the
37 # overall license link
38 options[:attribution] = <<-HTML
39 Licensed under <a href="http://tcl.tk/software/tcltk/license.html">Tcl/Tk Terms</a>
40 HTML
41 end
42end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t