History

add support for CMake

Dirk Thomas committed 10 years ago

Commit 96d45d51 parent b53aa503 files · +139 −0Browse files

Unified · Split

3 files
  1. lib/docs/filters/cmake/clean_html.rb +43 −0
  2. lib/docs/filters/cmake/entries.rb +64 −0
  3. lib/docs/scrapers/cmake.rb +32 −0
lib/docs/filters/cmake/clean_html.rb+43−0
@@ -0,0 +1,43 @@
1module Docs
2 class Cmake
3 class CleanHtmlFilter < Filter
4 # since each property category has its own entry redirect to that one instead
5 URL_MAPPING = {
6 '/manual/cmake-properties.7#properties-of-global-scope' => '/../cmake-properties-of-global-scope/',
7 '/manual/cmake-properties.7#properties-on-directories' => '/../cmake-properties-on-directories/',
8 '/manual/cmake-properties.7#target-properties' => '/../cmake-properties-on-targets/',
9 '/manual/cmake-properties.7.html#properties-on-tests' => '/../cmake-properties-on-tests/',
10 '/manual/cmake-properties.7.html#properties-on-source-files' => '/../cmake-properties-on-source-files/',
11 '/manual/cmake-properties.7.html#properties-on-cache-entries' => '/../cmake-properties-on-cache-entries/',
12 '/manual/cmake-properties.7.html#properties-on-installed-files' => '/../cmake-properties-on-installed-files/',
13 '/manual/cmake-properties.7.html#deprecated-properties-on-directories' => '/../cmake-deprecated-properties-on-directories/',
14 '/manual/cmake-properties.7.html#deprecated-properties-on-targets' => '/../cmake-deprecated-properties-on-targets/',
15 '/manual/cmake-properties.7.html#deprecated-properties-on-source-files' => '/../cmake-deprecated-properties-on-source-files/'
16 }
17
18 def call
19 css('.headerlink').remove
20 if root_page?
21 css('#release-notes').remove
22 css('#index-and-search').remove
23 return doc
24 end
25 css('.toc-backref').each do |link|
26 link.replace(link.text)
27 end
28 css('#contents').remove
29
30 # change urls pointing to entries which don't have a default entry
31 css('a').each do |link|
32 URL_MAPPING.each do |key, value|
33 if link['href'].end_with? key
34 link['href'] = link['href'][0..-(key.length + 1)] + value
35 end
36 end
37 end
38
39 doc
40 end
41 end
42 end
43end
lib/docs/filters/cmake/entries.rb+64−0
@@ -0,0 +1,64 @@
1module Docs
2 class Cmake
3 class EntriesFilter < Docs::EntriesFilter
4 MISCELLANEOUS = {
5 'manual/cmake.1' => 'CMake',
6 'manual/ctest.1' => 'CTest',
7 'manual/cpack.1' => 'CPack',
8 'manual/cmake-gui.1' => 'CMake GUI',
9 'manual/ccmake.1' => 'CCMake',
10 'manual/cmake-buildsystem.7' => 'Buildsystem',
11 'manual/cmake-commands.7' => 'Commands',
12 'manual/cmake-compile-features.7' => 'Compile Features',
13 'manual/cmake-developer.7' => 'Developer',
14 'manual/cmake-generator-expressions.7' => 'Generator Expressions',
15 'manual/cmake-generators.7' => 'Generators',
16 'manual/cmake-language.7' => 'Language',
17 'manual/cmake-modules.7' => 'Modules',
18 'manual/cmake-packages.7' => 'Packages',
19 'manual/cmake-policies.7' => 'Policies',
20 'manual/cmake-properties.7' => 'Properties',
21 'manual/cmake-qt.7' => 'Qt',
22 'manual/cmake-toolchains.7' => 'Toolchains',
23 'manual/cmake-variables.7' => 'Variables' }
24
25 GROUPS = {
26 'command' => 'Commands',
27 'policy' => 'Policies',
28 'prop_gbl' => 'Properties of Global Scope',
29 'prop_dir' => 'Properties on Directories',
30 'prop_tgt' => 'Properties on Targets',
31 'prop_test' => 'Properties on Tests',
32 'prop_sf' => 'Properties on Source Files',
33 'prop_cache' => 'Properties on Cache Entries',
34 'prop_inst' => 'Properties on Installed Files',
35 'variable' => 'Variables' }
36
37 def get_name
38 if MISCELLANEOUS.key?(slug)
39 return MISCELLANEOUS[slug]
40 end
41 parts = slug.split('/')
42 name = parts.drop(1).first
43 if name == ''
44 return slug
45 end
46 if parts.first == 'command'
47 name += '()'
48 end
49 name
50 end
51
52 def get_type
53 if MISCELLANEOUS.key?(slug)
54 return 'Miscellaneous'
55 end
56 parts = slug.split('/')
57 if GROUPS.key?(parts.first)
58 return GROUPS[parts.first]
59 end
60 slug
61 end
62 end
63 end
64end
lib/docs/scrapers/cmake.rb+32−0
@@ -0,0 +1,32 @@
1module Docs
2 class Cmake < UrlScraper
3 self.name = 'CMake'
4 self.slug = 'cmake'
5 self.type = 'cmake'
6 self.release = '3.5'
7 self.base_url = 'https://cmake.org/cmake/help/v3.5/'
8
9 options[:skip] = %w(
10 release/index.html
11 genindex.html
12 search.html
13 )
14
15 options[:only_patterns] = [
16 /manual/,
17 /command/,
18 /policy/,
19 /prop_/,
20 /variable/
21 ]
22
23 options[:container] = '.body'
24
25 html_filters.push 'cmake/clean_html', 'cmake/entries'
26
27 options[:attribution] = <<-HTML
28 &copy; 2000&ndash;2016 Kitware, Inc.<br>
29 Licensed under the BSD 3-clause License.
30 HTML
31 end
32end