History

Add Vitest documentation (0.24.0)

Simon Legner committed 4 years ago

Commit cd41d391 parent 4d03b4a8 files · +62 −-1Browse files

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

Unified · Split

3 files
  1. lib/docs/filters/vite/clean_html.rb +1 −0
  2. lib/docs/filters/vitest/entries.rb +28 −0
  3. lib/docs/scrapers/vitest.rb +28 −0
lib/docs/filters/vite/clean_html.rb+1−0
@@ -2,6 +2,7 @@ module Docs · 1 unmodified line
22 class Vite
33 class CleanHtmlFilter < Filter
44 def call
5+ return "<h1>Vitest</h1><p>A Vite-native unit test framework. It's fast!</p>" if root_page? && current_url.host == 'vitest.dev'
56 return '<h1>Vite</h1>' if root_page?
67 @doc = at_css('main h1').parent
78
lib/docs/filters/vitest/entries.rb+28−0
@@ -0,0 +1,28 @@
1+module Docs
2+ class Vitest
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('h1').content
6+ name.sub! %r{\s*#\s*}, ''
7+ name
8+ end
9+
10+ def get_type
11+ name = at_css('h1').content
12+ name.sub! %r{\s*#\s*}, ''
13+ name
14+ end
15+
16+ def additional_entries
17+ return [] if root_page?
18+ css('h2[id], h3[id]').each_with_object [] do |node, entries|
19+ text = node.content.strip
20+ text.sub! %r{\s*#\s*}, ''
21+ next if text == 'Example'
22+ text.prepend "#{name}: " unless slug.starts_with?('api') || slug.starts_with?('config')
23+ entries << [text, node['id']]
24+ end
25+ end
26+ end
27+ end
28+end
lib/docs/scrapers/vitest.rb+28−0
@@ -0,0 +1,28 @@
1+module Docs
2+ class Vitest < UrlScraper
3+ self.name = 'Vitest'
4+ self.slug = 'vitest'
5+ self.type = 'simple'
6+ self.links = {
7+ home: 'https://vitest.dev/',
8+ code: 'https://github.com/vitest-dev/vitest'
9+ }
10+
11+ options[:root_title] = 'Vitest'
12+
13+ options[:attribution] = <<-HTML
14+ &copy; 2021-Present Anthony Fu<br>
15+ &copy; 2021-Present Matias Capeletto<br>
16+ Licensed under the MIT License.
17+ HTML
18+
19+ self.release = '0.24.0'
20+ self.base_url = 'https://vitest.dev/'
21+ self.initial_paths = %w(guide/)
22+ html_filters.push 'vitest/entries', 'vite/clean_html'
23+
24+ def get_latest_version(opts)
25+ get_npm_version('vitest', opts)
26+ end
27+ end
28+end