Closes #513.
Showing the changes to lib/docs (3 of 13 files). Show all
Unified · Split
| @@ -0,0 +1,48 @@ | |||
| 1 | module Docs | ||
| 2 | class Immutable | ||
| 3 | class CleanHtmlFilter < Filter | ||
| 4 | def call | ||
| 5 | css('section', 'span', 'div[data-reactid]').each do |node| | ||
| 6 | node.before(node.children).remove | ||
| 7 | end | ||
| 8 | |||
| 9 | css('.codeBlock').each do |node| | ||
| 10 | node.name = 'pre' | ||
| 11 | node.content = node.content | ||
| 12 | node['data-language'] = 'js' | ||
| 13 | end | ||
| 14 | |||
| 15 | css('*[data-reactid]').remove_attr('data-reactid') | ||
| 16 | css('a[target]').remove_attr('target') | ||
| 17 | |||
| 18 | css('a[href^="#"]').each do |node| | ||
| 19 | node['href'] = node['href'].sub(/\A#\//, '#').gsub('/', '.').downcase | ||
| 20 | end | ||
| 21 | |||
| 22 | type = type_id = nil | ||
| 23 | css('*').each do |node| | ||
| 24 | if node.name == 'h1' | ||
| 25 | node['id'] = type_id = node.content.strip.downcase | ||
| 26 | type = node.content.strip | ||
| 27 | elsif node.name == 'h3' | ||
| 28 | node['id'] = node.content.strip.downcase | ||
| 29 | node['id'] = node['id'].remove('()') unless node['id'] == "#{type_id}()" | ||
| 30 | |||
| 31 | unless node['id'].start_with?(type_id) | ||
| 32 | node.content = "#{type}##{node.content}" | ||
| 33 | node['id'] = "#{type_id}.#{node['id']}" unless node['id'].start_with?("#{type_id}.") | ||
| 34 | end | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | css('h4.groupTitle').each do |node| | ||
| 39 | node.name = 'h2' | ||
| 40 | end | ||
| 41 | |||
| 42 | css('*[class]').remove_attr('class') | ||
| 43 | |||
| 44 | doc | ||
| 45 | end | ||
| 46 | end | ||
| 47 | end | ||
| 48 | end | ||
| @@ -0,0 +1,23 @@ | |||
| 1 | module Docs | ||
| 2 | class Immutable | ||
| 3 | class EntriesFilter < Docs::EntriesFilter | ||
| 4 | def additional_entries | ||
| 5 | entries = [] | ||
| 6 | type = nil | ||
| 7 | |||
| 8 | css('*').each do |node| | ||
| 9 | if node.name == 'h1' | ||
| 10 | name = node.content | ||
| 11 | type = node.content.split('.').first | ||
| 12 | entries << [name, node['id'], type] | ||
| 13 | elsif node.name == 'h3' | ||
| 14 | name = node.content | ||
| 15 | entries << [name, node['id'], type] | ||
| 16 | end | ||
| 17 | end | ||
| 18 | |||
| 19 | entries | ||
| 20 | end | ||
| 21 | end | ||
| 22 | end | ||
| 23 | end | ||
| @@ -0,0 +1,58 @@ | |||
| 1 | module Docs | ||
| 2 | class Immutable < UrlScraper | ||
| 3 | self.name = 'Immutable.js' | ||
| 4 | self.slug = 'immutable' | ||
| 5 | self.type = 'immutable' | ||
| 6 | self.release = '3.8.1' | ||
| 7 | self.base_url = 'https://facebook.github.io/immutable-js/docs/' | ||
| 8 | self.links = { | ||
| 9 | home: 'https://facebook.github.io/immutable-js/', | ||
| 10 | code: 'https://github.com/facebook/immutable-js' | ||
| 11 | } | ||
| 12 | |||
| 13 | html_filters.push 'immutable/clean_html', 'immutable/entries', 'title' | ||
| 14 | |||
| 15 | options[:skip_links] = true | ||
| 16 | options[:container] = '.docContents' | ||
| 17 | options[:root_title] = 'Immutable.js' | ||
| 18 | |||
| 19 | options[:attribution] = <<-HTML | ||
| 20 | © 2014–2015 Facebook, Inc.<br> | ||
| 21 | Licensed under the 3-clause BSD License. | ||
| 22 | HTML | ||
| 23 | |||
| 24 | stub '' do | ||
| 25 | capybara = load_capybara_selenium | ||
| 26 | capybara.app_host = 'https://facebook.github.io' | ||
| 27 | capybara.visit(URL.parse(self.base_url).path) | ||
| 28 | capybara.execute_script <<-JS | ||
| 29 | var content, event, links, link; | ||
| 30 | |||
| 31 | event = document.createEvent('Event'); | ||
| 32 | event.initEvent('hashchange', false, false); | ||
| 33 | |||
| 34 | content = document.querySelector('.docContents section').cloneNode(true); | ||
| 35 | links = Array.prototype.slice.call(document.querySelectorAll('.sideBar .scrollContent a')); | ||
| 36 | |||
| 37 | while (link = links.shift()) { | ||
| 38 | if (!document.body.contains(link)) { | ||
| 39 | document.body.appendChild(link); | ||
| 40 | } | ||
| 41 | |||
| 42 | link.click(); | ||
| 43 | dispatchEvent(event); | ||
| 44 | content.innerHTML += document.querySelector('.docContents').innerHTML; | ||
| 45 | |||
| 46 | document.querySelectorAll('.sideBar .scrollContent .groupTitle').forEach(function(el) { | ||
| 47 | if (el.textContent == 'Types') { | ||
| 48 | Array.prototype.unshift.apply(links, Array.prototype.slice.call(el.parentNode.querySelectorAll('a'))); | ||
| 49 | } | ||
| 50 | }); | ||
| 51 | } | ||
| 52 | |||
| 53 | document.querySelector('.docContents').innerHTML = content.innerHTML; | ||
| 54 | JS | ||
| 55 | capybara.html | ||
| 56 | end | ||
| 57 | end | ||
| 58 | end | ||