From 96d45d5ed380fb8f2763d6872d0270ecfa37efd2 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Mon, 13 Jun 2016 16:04:54 -0700 Subject: [PATCH] add support for CMake --- lib/docs/filters/cmake/clean_html.rb | 43 +++++++++++++++++++ lib/docs/filters/cmake/entries.rb | 64 ++++++++++++++++++++++++++++ lib/docs/scrapers/cmake.rb | 32 ++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 lib/docs/filters/cmake/clean_html.rb create mode 100644 lib/docs/filters/cmake/entries.rb create mode 100644 lib/docs/scrapers/cmake.rb diff --git a/lib/docs/filters/cmake/clean_html.rb b/lib/docs/filters/cmake/clean_html.rb new file mode 100644 index 00000000..b499dbd3 --- /dev/null +++ b/lib/docs/filters/cmake/clean_html.rb @@ -0,0 +1,43 @@ +module Docs + class Cmake + class CleanHtmlFilter < Filter + # since each property category has its own entry redirect to that one instead + URL_MAPPING = { + '/manual/cmake-properties.7#properties-of-global-scope' => '/../cmake-properties-of-global-scope/', + '/manual/cmake-properties.7#properties-on-directories' => '/../cmake-properties-on-directories/', + '/manual/cmake-properties.7#target-properties' => '/../cmake-properties-on-targets/', + '/manual/cmake-properties.7.html#properties-on-tests' => '/../cmake-properties-on-tests/', + '/manual/cmake-properties.7.html#properties-on-source-files' => '/../cmake-properties-on-source-files/', + '/manual/cmake-properties.7.html#properties-on-cache-entries' => '/../cmake-properties-on-cache-entries/', + '/manual/cmake-properties.7.html#properties-on-installed-files' => '/../cmake-properties-on-installed-files/', + '/manual/cmake-properties.7.html#deprecated-properties-on-directories' => '/../cmake-deprecated-properties-on-directories/', + '/manual/cmake-properties.7.html#deprecated-properties-on-targets' => '/../cmake-deprecated-properties-on-targets/', + '/manual/cmake-properties.7.html#deprecated-properties-on-source-files' => '/../cmake-deprecated-properties-on-source-files/' + } + + def call + css('.headerlink').remove + if root_page? + css('#release-notes').remove + css('#index-and-search').remove + return doc + end + css('.toc-backref').each do |link| + link.replace(link.text) + end + css('#contents').remove + + # change urls pointing to entries which don't have a default entry + css('a').each do |link| + URL_MAPPING.each do |key, value| + if link['href'].end_with? key + link['href'] = link['href'][0..-(key.length + 1)] + value + end + end + end + + doc + end + end + end +end diff --git a/lib/docs/filters/cmake/entries.rb b/lib/docs/filters/cmake/entries.rb new file mode 100644 index 00000000..5d6f8cea --- /dev/null +++ b/lib/docs/filters/cmake/entries.rb @@ -0,0 +1,64 @@ +module Docs + class Cmake + class EntriesFilter < Docs::EntriesFilter + MISCELLANEOUS = { + 'manual/cmake.1' => 'CMake', + 'manual/ctest.1' => 'CTest', + 'manual/cpack.1' => 'CPack', + 'manual/cmake-gui.1' => 'CMake GUI', + 'manual/ccmake.1' => 'CCMake', + 'manual/cmake-buildsystem.7' => 'Buildsystem', + 'manual/cmake-commands.7' => 'Commands', + 'manual/cmake-compile-features.7' => 'Compile Features', + 'manual/cmake-developer.7' => 'Developer', + 'manual/cmake-generator-expressions.7' => 'Generator Expressions', + 'manual/cmake-generators.7' => 'Generators', + 'manual/cmake-language.7' => 'Language', + 'manual/cmake-modules.7' => 'Modules', + 'manual/cmake-packages.7' => 'Packages', + 'manual/cmake-policies.7' => 'Policies', + 'manual/cmake-properties.7' => 'Properties', + 'manual/cmake-qt.7' => 'Qt', + 'manual/cmake-toolchains.7' => 'Toolchains', + 'manual/cmake-variables.7' => 'Variables' } + + GROUPS = { + 'command' => 'Commands', + 'policy' => 'Policies', + 'prop_gbl' => 'Properties of Global Scope', + 'prop_dir' => 'Properties on Directories', + 'prop_tgt' => 'Properties on Targets', + 'prop_test' => 'Properties on Tests', + 'prop_sf' => 'Properties on Source Files', + 'prop_cache' => 'Properties on Cache Entries', + 'prop_inst' => 'Properties on Installed Files', + 'variable' => 'Variables' } + + def get_name + if MISCELLANEOUS.key?(slug) + return MISCELLANEOUS[slug] + end + parts = slug.split('/') + name = parts.drop(1).first + if name == '' + return slug + end + if parts.first == 'command' + name += '()' + end + name + end + + def get_type + if MISCELLANEOUS.key?(slug) + return 'Miscellaneous' + end + parts = slug.split('/') + if GROUPS.key?(parts.first) + return GROUPS[parts.first] + end + slug + end + end + end +end diff --git a/lib/docs/scrapers/cmake.rb b/lib/docs/scrapers/cmake.rb new file mode 100644 index 00000000..631ecc31 --- /dev/null +++ b/lib/docs/scrapers/cmake.rb @@ -0,0 +1,32 @@ +module Docs + class Cmake < UrlScraper + self.name = 'CMake' + self.slug = 'cmake' + self.type = 'cmake' + self.release = '3.5' + self.base_url = 'https://cmake.org/cmake/help/v3.5/' + + options[:skip] = %w( + release/index.html + genindex.html + search.html + ) + + options[:only_patterns] = [ + /manual/, + /command/, + /policy/, + /prop_/, + /variable/ + ] + + options[:container] = '.body' + + html_filters.push 'cmake/clean_html', 'cmake/entries' + + options[:attribution] = <<-HTML + © 2000–2016 Kitware, Inc.
+ Licensed under the BSD 3-clause License. + HTML + end +end