diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index f06c1e1f..4929be30 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -72,6 +72,7 @@ 'pages/rust', 'pages/socketio', 'pages/sphinx', + 'pages/tcl_tk', 'pages/underscore', 'pages/vagrant', 'pages/vue', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index e412763a..290a8e68 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -72,6 +72,7 @@ 'pages/rust', 'pages/socketio', 'pages/sphinx', + 'pages/tcl_tk', 'pages/underscore', 'pages/vagrant', 'pages/vue', diff --git a/assets/stylesheets/pages/_tcl_tk.scss b/assets/stylesheets/pages/_tcl_tk.scss new file mode 100644 index 00000000..26ac6358 --- /dev/null +++ b/assets/stylesheets/pages/_tcl_tk.scss @@ -0,0 +1,19 @@ +._tcl_tk { + /* make content listing more compact */ + .description { + margin: 0; + > dd { + margin: 0; + } + } + dl { + margin: 0; + } + .copy { + /* per page copyright */ + white-space: pre; + font-size: 80%; + border-top: 1px solid #6A6A6A; + margin-top: 2em; + } +} diff --git a/lib/docs/filters/tcl_tk/clean_html.rb b/lib/docs/filters/tcl_tk/clean_html.rb new file mode 100644 index 00000000..f2a0e931 --- /dev/null +++ b/lib/docs/filters/tcl_tk/clean_html.rb @@ -0,0 +1,52 @@ +module Docs + class TclTk + class CleanHtmlFilter < Filter + def call + # Page Title + css('h2').remove + # Navigation + css('h3:first-child').remove + # restore breaks in copyright + txt = at_css('div.copy').content + at_css('div.copy').content = txt.gsub! /.Copyright/, "\n\\0" + + file = result[:path].split('/')[-1] + re = Regexp.new('^' + Regexp.escape(file) + '(#.*)$') + css('a[name]').each do |node| + if node['href'] then + # useless name + node.remove_attribute 'name' + # make fragments relativ + if node['href'].match re then + node['href'] = node['href'].sub re, '\\1' + end + else + # move name to id + node.parent['id'] = node['name'] + node.parent.content = node.content + end + end + + # remove keywords headline + css('h3').each do |node| + if node.content == 'KEYWORDS' then + node.remove + end + end + # remove keywords links + css('a').each do |node| + attr = node.attribute('href') + if attr && attr.value.match(/\/Keywords\//) then + # the ',' + if node.next_sibling then + node.next_sibling.remove + end + node.remove + end + end + + doc + end + end + end +end diff --git a/lib/docs/filters/tcl_tk/entries.rb b/lib/docs/filters/tcl_tk/entries.rb new file mode 100644 index 00000000..f3dcd909 --- /dev/null +++ b/lib/docs/filters/tcl_tk/entries.rb @@ -0,0 +1,57 @@ +module Docs + class TclTk + class EntriesFilter < Docs::EntriesFilter + #def additional_entries + # type = nil + #end + + def split_slug + slug.sub! /\.html?/, '' + return *slug.split('/') + end + + TYPE_MAP = { + 'TclCmd' => 'Tcl', + 'TkCmd' => 'Tk', + 'ItclCmd' => 'incr', + 'SqliteCmd' => 'tdbc', + 'TdbcCmd' => 'tdbc', + 'TdbcmysqlCmd' => 'tdbc', + 'TdbcodbcCmd' => 'tdbc', + 'TdbcpostgresCmd' => 'tdbc', + 'TdbcsqliteCmd' => 'tdbc', + 'ThreadCmd' => 'Thread', + 'UserCmd' => 'App' + } + + def get_type + type, name = split_slug + type = TYPE_MAP[type] || type + if name == 'contents' then + type = nil + end + type + end + + def get_name + type, name = split_slug + name + end + + def additional_entries + type, name = split_slug + if type != 'TclCmd' || name != 'library' then + return [] + end + # special rule for library page which contains multiple commands at once + entries = [] + css('a > b').each do |node| + text = node.content.strip + id = node.parent['href'].sub /^.*#(.*)$/, '\\1' + entries << [text, id, TYPE_MAP[type]] + end + return entries + end + end + end +end diff --git a/lib/docs/scrapers/tcl_tk.rb b/lib/docs/scrapers/tcl_tk.rb new file mode 100644 index 00000000..e790b9e4 --- /dev/null +++ b/lib/docs/scrapers/tcl_tk.rb @@ -0,0 +1,42 @@ +module Docs + class TclTk < UrlScraper + self.name = 'Tcl/Tk' + self.type = 'tcl_tk' + self.slug = 'tcl' + self.version = '8.6' + # test URL: + self.base_url = 'http://localhost/tcl/' + # real URL: + #self.base_url = 'http://www.tcl.tk/man/tcl/' + self.root_path = 'contents.htm' + + html_filters.push 'tcl_tk/clean_html', 'tcl_tk/entries' + + options[:skip_links] = false + + options[:trailing_slash] = false + options[:skip] = ['siteinfo.htm'] + options[:skip_patterns] = [ + # ignore keyword list pages + /^Keywords\//, + # ignore C-API, only required for extension developers + /^TclLib\//, + /^TkLib\//, + /^ItclLib\//, + /^TdbcLib\// + ] + + # TODO can't figure out howto convert .htm => .html in filenames + # to save as "xyz.html" instead of "xyz.htm.html" + #options[:fix_urls] = ->(url) do + # url.sub! /\.htm($|#)/, '.html\\1' + # url + #end + + # Each Page contains a specific list of copyrights, only add the + # overall license link + options[:attribution] = <<-HTML + Licensed under Tcl/Tk Terms + HTML + end +end diff --git a/public/icons/docs/tcl_tk/16.png b/public/icons/docs/tcl_tk/16.png new file mode 100644 index 00000000..8752547d Binary files /dev/null and b/public/icons/docs/tcl_tk/16.png differ diff --git a/public/icons/docs/tcl_tk/16@2.png b/public/icons/docs/tcl_tk/16@2.png new file mode 100644 index 00000000..1d784a29 Binary files /dev/null and b/public/icons/docs/tcl_tk/16@2.png differ diff --git a/public/icons/docs/tcl_tk/SOURCE b/public/icons/docs/tcl_tk/SOURCE new file mode 100644 index 00000000..91f3566f --- /dev/null +++ b/public/icons/docs/tcl_tk/SOURCE @@ -0,0 +1 @@ +https://commons.wikimedia.org/wiki/File:Tcl.svg