History

Merge pull request #882 from jmerle/enzyme

Add Enzyme documentation

Jasper van Merle committed 7 years ago

Commit 9f2941c2 parents 39ec9e4 af412d64 files · +103 −0Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  2. lib/docs/filters/enzyme/clean_html.rb +41 −0
  3. lib/docs/filters/enzyme/entries.rb +33 −0
  4. lib/docs/scrapers/enzyme.rb +24 −0
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -266,6 +266,11 @@ credits = [ · 265 unmodified lines
266266 '2017 Yehuda Katz, Tom Dale and Ember.js contributors',
267267 'MIT',
268268 'https://raw.githubusercontent.com/emberjs/ember.js/master/LICENSE'
269+ ], [
270+ 'Enzyme',
271+ '2015 Airbnb, Inc.',
272+ 'MIT',
273+ 'https://raw.githubusercontent.com/airbnb/enzyme/master/LICENSE.md'
269274 ], [
270275 'Erlang',
271276 '2010-2017 Ericsson AB',
lib/docs/filters/enzyme/clean_html.rb+41−0
@@ -0,0 +1,41 @@
1+module Docs
2+ class Enzyme
3+ class CleanHtmlFilter < Filter
4+ def call
5+ @doc = at_css('.page-inner > section')
6+
7+ # Remove badges
8+ if root_page?
9+ css('a > img').each do |node|
10+ node.parent.remove
11+ end
12+ end
13+
14+ # Clean headers
15+ css('h1').each do |node|
16+ node.content = node.content
17+ end
18+
19+ # Make headers on reference pages bigger
20+ if subpath.include?('api/')
21+ css('h3, h4').each do |node|
22+ node.name = 'h2'
23+ end
24+ end
25+
26+ # Make code blocks detectable by Prism
27+ css('pre').each do |node|
28+ cls = node.at_css('code')['class']
29+
30+ unless cls.nil?
31+ node['data-language'] = cls.split('-')[1]
32+ end
33+
34+ node.content = node.content
35+ end
36+
37+ doc
38+ end
39+ end
40+ end
41+end
lib/docs/filters/enzyme/entries.rb+33−0
@@ -0,0 +1,33 @@
1+module Docs
2+ class Enzyme
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('.page-inner h1').content
6+
7+ if name.include?('(')
8+ until_parenthesis = name[0..name.index('(')]
9+
10+ if until_parenthesis.include?(' ')
11+ until_parenthesis[0..-3]
12+ else
13+ until_parenthesis + ')'
14+ end
15+ else
16+ name
17+ end
18+ end
19+
20+ def get_type
21+ active_level = at_css('.chapter.active')['data-level']
22+
23+ # It's a parent level if it contains only one dot
24+ if active_level.count('.') == 1
25+ at_css('.chapter.active > a').content
26+ else
27+ parent_level = active_level[0..active_level.rindex('.') - 1]
28+ at_css(".chapter[data-level=\"#{parent_level}\"] > a").content
29+ end
30+ end
31+ end
32+ end
33+end
lib/docs/scrapers/enzyme.rb+24−0
@@ -0,0 +1,24 @@
1+module Docs
2+ class Enzyme < UrlScraper
3+ self.type = 'simple'
4+ self.release = '3.10.0'
5+ self.base_url = 'https://airbnb.io/enzyme/'
6+ self.root_path = 'index.html'
7+ self.links = {
8+ code: 'https://github.com/airbnb/enzyme'
9+ }
10+
11+ html_filters.push 'enzyme/entries', 'enzyme/clean_html'
12+
13+ options[:skip] = %w(CHANGELOG.html docs/future.html docs/guides.html docs/api/ CONTRIBUTING.html)
14+
15+ options[:attribution] = <<-HTML
16+ &copy; 2015 Airbnb, Inc.<br>
17+ Licensed under the MIT License.
18+ HTML
19+
20+ def get_latest_version(opts)
21+ get_npm_version('enzyme', opts)
22+ end
23+ end
24+end