History

Add Enzyme documentation

Jasper van Merle committed 8 years ago

Commit 552b5261 parent bec78bf4 files · +92 −0Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  2. lib/docs/filters/enzyme/clean_html.rb +34 −0
  3. lib/docs/filters/enzyme/entries.rb +33 −0
  4. lib/docs/scrapers/enzyme.rb +20 −0
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -255,6 +255,11 @@ credits = [ · 254 unmodified lines
255255 '2017 Yehuda Katz, Tom Dale and Ember.js contributors',
256256 'MIT',
257257 'https://raw.githubusercontent.com/emberjs/ember.js/master/LICENSE'
258+ ], [
259+ 'Enzyme',
260+ '2015 Airbnb, Inc.',
261+ 'MIT',
262+ 'https://raw.githubusercontent.com/airbnb/enzyme/master/LICENSE.md'
258263 ], [
259264 'Erlang',
260265 '2010-2017 Ericsson AB',
lib/docs/filters/enzyme/clean_html.rb+34−0
@@ -0,0 +1,34 @@
1+module Docs
2+ class Enzyme
3+ class CleanHtmlFilter < Filter
4+ def call
5+ @doc = at_css('.page-inner > section')
6+
7+ # Clean headers
8+ css('h1').each do |node|
9+ node.content = node.content
10+ end
11+
12+ # Make headers on reference pages bigger
13+ if subpath.include?('ReactWrapper') || subpath.include?('ShallowWrapper')
14+ css('h4').each do |node|
15+ node.name = 'h2'
16+ end
17+ end
18+
19+ # Make code blocks detectable by Prism
20+ css('pre').each do |node|
21+ cls = node.at_css('code')['class']
22+
23+ unless cls.nil?
24+ node['data-language'] = cls.split('-')[1]
25+ end
26+
27+ node.content = node.content
28+ end
29+
30+ doc
31+ end
32+ end
33+ end
34+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+20−0
@@ -0,0 +1,20 @@
1+module Docs
2+ class Enzyme < UrlScraper
3+ self.type = 'simple'
4+ self.release = '3.6.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 CONTRIBUTING.html)
14+
15+ options[:attribution] = <<-HTML
16+ &copy; 2015 Airbnb, Inc.<br>
17+ Licensed under the MIT License.
18+ HTML
19+ end
20+end