From 552b526509945c8a5722907d2bab49b1fb0e5dae Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Sat, 6 Oct 2018 15:25:47 +0200 Subject: [PATCH 1/3] Add Enzyme documentation --- .../templates/pages/about_tmpl.coffee | 5 +++ lib/docs/filters/enzyme/clean_html.rb | 34 +++++++++++++++++++ lib/docs/filters/enzyme/entries.rb | 33 ++++++++++++++++++ lib/docs/scrapers/enzyme.rb | 20 +++++++++++ 4 files changed, 92 insertions(+) create mode 100644 lib/docs/filters/enzyme/clean_html.rb create mode 100644 lib/docs/filters/enzyme/entries.rb create mode 100644 lib/docs/scrapers/enzyme.rb diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 629682fb..6de04159 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -255,6 +255,11 @@ credits = [ '2017 Yehuda Katz, Tom Dale and Ember.js contributors', 'MIT', 'https://raw.githubusercontent.com/emberjs/ember.js/master/LICENSE' + ], [ + 'Enzyme', + '2015 Airbnb, Inc.', + 'MIT', + 'https://raw.githubusercontent.com/airbnb/enzyme/master/LICENSE.md' ], [ 'Erlang', '2010-2017 Ericsson AB', diff --git a/lib/docs/filters/enzyme/clean_html.rb b/lib/docs/filters/enzyme/clean_html.rb new file mode 100644 index 00000000..8a42ad0d --- /dev/null +++ b/lib/docs/filters/enzyme/clean_html.rb @@ -0,0 +1,34 @@ +module Docs + class Enzyme + class CleanHtmlFilter < Filter + def call + @doc = at_css('.page-inner > section') + + # Clean headers + css('h1').each do |node| + node.content = node.content + end + + # Make headers on reference pages bigger + if subpath.include?('ReactWrapper') || subpath.include?('ShallowWrapper') + css('h4').each do |node| + node.name = 'h2' + end + end + + # Make code blocks detectable by Prism + css('pre').each do |node| + cls = node.at_css('code')['class'] + + unless cls.nil? + node['data-language'] = cls.split('-')[1] + end + + node.content = node.content + end + + doc + end + end + end +end diff --git a/lib/docs/filters/enzyme/entries.rb b/lib/docs/filters/enzyme/entries.rb new file mode 100644 index 00000000..aa28bcca --- /dev/null +++ b/lib/docs/filters/enzyme/entries.rb @@ -0,0 +1,33 @@ +module Docs + class Enzyme + class EntriesFilter < Docs::EntriesFilter + def get_name + name = at_css('.page-inner h1').content + + if name.include?('(') + until_parenthesis = name[0..name.index('(')] + + if until_parenthesis.include?(' ') + until_parenthesis[0..-3] + else + until_parenthesis + ')' + end + else + name + end + end + + def get_type + active_level = at_css('.chapter.active')['data-level'] + + # It's a parent level if it contains only one dot + if active_level.count('.') == 1 + at_css('.chapter.active > a').content + else + parent_level = active_level[0..active_level.rindex('.') - 1] + at_css(".chapter[data-level=\"#{parent_level}\"] > a").content + end + end + end + end +end diff --git a/lib/docs/scrapers/enzyme.rb b/lib/docs/scrapers/enzyme.rb new file mode 100644 index 00000000..7c225bdc --- /dev/null +++ b/lib/docs/scrapers/enzyme.rb @@ -0,0 +1,20 @@ +module Docs + class Enzyme < UrlScraper + self.type = 'simple' + self.release = '3.6.0' + self.base_url = 'https://airbnb.io/enzyme/' + self.root_path = 'index.html' + self.links = { + code: 'https://github.com/airbnb/enzyme' + } + + html_filters.push 'enzyme/entries', 'enzyme/clean_html' + + options[:skip] = %w(CHANGELOG.html docs/future.html CONTRIBUTING.html) + + options[:attribution] = <<-HTML + © 2015 Airbnb, Inc.
+ Licensed under the MIT License. + HTML + end +end From abe3d4b370e519d88c4ff6e8976bbc848a04e1bd Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Tue, 13 Aug 2019 23:05:16 +0200 Subject: [PATCH 2/3] enzyme: add get_latest_version and update release --- lib/docs/scrapers/enzyme.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/docs/scrapers/enzyme.rb b/lib/docs/scrapers/enzyme.rb index 7c225bdc..4bdbb82f 100644 --- a/lib/docs/scrapers/enzyme.rb +++ b/lib/docs/scrapers/enzyme.rb @@ -1,7 +1,7 @@ module Docs class Enzyme < UrlScraper self.type = 'simple' - self.release = '3.6.0' + self.release = '3.10.0' self.base_url = 'https://airbnb.io/enzyme/' self.root_path = 'index.html' self.links = { @@ -16,5 +16,9 @@ module Docs © 2015 Airbnb, Inc.
Licensed under the MIT License. HTML + + def get_latest_version(opts) + get_npm_version('enzyme', opts) + end end end From af412d641ebead801d1cb9b5cd6e72fe71998852 Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Wed, 28 Aug 2019 20:16:41 +0200 Subject: [PATCH 3/3] enzyme: process review comments --- lib/docs/filters/enzyme/clean_html.rb | 11 +++++++++-- lib/docs/scrapers/enzyme.rb | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/docs/filters/enzyme/clean_html.rb b/lib/docs/filters/enzyme/clean_html.rb index 8a42ad0d..caf7980f 100644 --- a/lib/docs/filters/enzyme/clean_html.rb +++ b/lib/docs/filters/enzyme/clean_html.rb @@ -4,14 +4,21 @@ module Docs def call @doc = at_css('.page-inner > section') + # Remove badges + if root_page? + css('a > img').each do |node| + node.parent.remove + end + end + # Clean headers css('h1').each do |node| node.content = node.content end # Make headers on reference pages bigger - if subpath.include?('ReactWrapper') || subpath.include?('ShallowWrapper') - css('h4').each do |node| + if subpath.include?('api/') + css('h3, h4').each do |node| node.name = 'h2' end end diff --git a/lib/docs/scrapers/enzyme.rb b/lib/docs/scrapers/enzyme.rb index 4bdbb82f..1af4ed60 100644 --- a/lib/docs/scrapers/enzyme.rb +++ b/lib/docs/scrapers/enzyme.rb @@ -10,7 +10,7 @@ module Docs html_filters.push 'enzyme/entries', 'enzyme/clean_html' - options[:skip] = %w(CHANGELOG.html docs/future.html CONTRIBUTING.html) + options[:skip] = %w(CHANGELOG.html docs/future.html docs/guides.html docs/api/ CONTRIBUTING.html) options[:attribution] = <<-HTML © 2015 Airbnb, Inc.