History

Merge pull request #2136 from Suraj-Yadav/opengl

Add Opengl documentation (gl4 + gl2.1)

Simon Legner committed 2 years ago

Commit dd553c42 parents fe0d469 d3a731d8 files · +104 −-2Browse files

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

Unified · Split

3 files
  1. lib/docs/filters/opengl/clean_html.rb +32 −0
  2. lib/docs/filters/opengl/entries.rb +25 −0
  3. lib/docs/scrapers/opengl.rb +31 −0
lib/docs/filters/opengl/clean_html.rb+32−0
@@ -0,0 +1,32 @@
1module Docs
2 class Opengl
3 class CleanHtmlFilter < Filter
4 def call
5 return '<h1>OpenGL</h1>' if root_page?
6
7 @doc = at_css('.refentry') if at_css('.refentry')
8
9 # Remove table from function definitions
10 css('.funcprototype-table').each do |node|
11 node.css('td').each do |data|
12 data.replace(data.children)
13 end
14 node.css('tr').each do |row|
15 row.replace(row.children)
16 end
17 node.wrap('<div>')
18 node.parent['id'] = node.css('.fsfunc').text
19 node.replace(node.children)
20 end
21
22 css('a').remove_attribute('target')
23
24 # needed for scraper's options[:attribution]
25 copyright = at_css('h2:contains("Copyright")')
26 copyright.parent['style'] = 'display: none' if copyright
27
28 doc
29 end
30 end
31 end
32 end
lib/docs/filters/opengl/entries.rb+25−0
@@ -0,0 +1,25 @@
1module Docs
2 class Opengl
3 class EntriesFilter < Docs::EntriesFilter
4 def get_name
5 slug.chomp('.xhtml').chomp('.xml')
6 end
7
8 # gl4 also has documentation of GLSL, this string is present under Version Support
9 def get_type
10 return 'GLSL' if html.include?('OpenGL Shading Language Version')
11 'OpenGL'
12 end
13
14 # functions like glUniform1f, glUniform2f, glUniform... have the same documentation
15 def additional_entries
16 entries = []
17 css('.fsfunc').each do |function|
18 next if function.text == name
19 entries << [ function.text, function.text ]
20 end
21 entries
22 end
23 end
24 end
25end
lib/docs/scrapers/opengl.rb+31−0
@@ -0,0 +1,31 @@
1module Docs
2 class Opengl < FileScraper
3 self.type = 'simple'
4 self.name = 'OpenGL'
5 self.root_path = 'index.php'
6 self.links = {
7 home: 'https://registry.khronos.org/OpenGL-Refpages/'
8 }
9 html_filters.push 'opengl/entries', 'opengl/clean_html'
10
11 # indexflat.php is a copy of index.php
12 options[:skip] = %w(indexflat.php)
13
14 options[:attribution] = ->(filter) {
15 # copyright is the last section in these pages
16 return filter.css('h2:contains("Copyright") ~ p').inner_text
17 }
18
19 version '4' do
20 self.root_path = 'index.php'
21 self.release = '4'
22 self.base_url = "https://registry.khronos.org/OpenGL-Refpages/gl#{self.version}/"
23 end
24
25 version '2.1' do
26 self.root_path = 'index.html'
27 self.release = '2.1'
28 self.base_url = "https://registry.khronos.org/OpenGL-Refpages/gl#{self.version}/"
29 end
30 end
31end