History

Add Immutable.js documentation

Closes #513.

Thibaut Courouble committed 9 years ago

Commit fd151681 parent a5b44b413 files · +137 −-4Browse files

Unified · Split

13 files
  1. assets/images/docs.png +0 −0
  2. assets/images/docs@2x.png +0 −0
  3. assets/javascripts/news.json +3 −0
  4. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  5. assets/javascripts/views/pages/simple.coffee +1 −0
  6. assets/stylesheets/global/_icons.scss +1 −0
  7. assets/stylesheets/pages/_simple.scss +1 −0
  8. lib/docs/filters/immutable/clean_html.rb +48 −0
  9. lib/docs/filters/immutable/entries.rb +23 −0
  10. lib/docs/scrapers/immutable.rb +58 −0
  11. public/icons/docs/immutable/16.png +0 −0
  12. public/icons/docs/immutable/16@2x.png +0 −0
  13. public/icons/docs/immutable/SOURCE +1 −0
assets/images/docs.png+0−0

Binary file not shown.

assets/images/docs@2x.png+0−0

Binary file not shown.

assets/javascripts/news.json+3−0
@@ -1,5 +1,8 @@
11 [
22 [
3+ "2016-11-20",
4+ "New documentation: <a href=\"/immutable/\">Immutable.js</a>"
5+ ], [
36 "2016-10-10",
47 "New documentations: <a href=\"/scikit_learn/\">scikit-learn</a> and <a href=\"/statsmodels/\">Statsmodels</a>"
58 ], [
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -254,6 +254,11 @@ credits = [ · 253 unmodified lines
254254 '2005-2016 Haxe Foundation',
255255 'MIT',
256256 'http://haxe.org/foundation/open-source.html'
257+ ], [
258+ 'Immutable.js',
259+ '2014-2016 Facebook, Inc.',
260+ 'BSD',
261+ 'https://raw.githubusercontent.com/facebook/immutable-js/master/LICENSE'
257262 ], [
258263 'InfluxData',
259264 '2015 InfluxData, Inc.',
assets/javascripts/views/pages/simple.coffee+1−0
@@ -22,6 +22,7 @@ app.views.ElixirPage = · 21 unmodified lines
2222 app.views.EmberPage =
2323 app.views.ExpressPage =
2424 app.views.GoPage =
25+app.views.ImmutablePage =
2526 app.views.InfluxdataPage =
2627 app.views.KnockoutPage =
2728 app.views.KotlinPage =
assets/stylesheets/global/_icons.scss+1−0
@@ -72,6 +72,7 @@ · 71 unmodified lines
7272 ._icon-angularjs:before { background-position: -9rem -1rem; }
7373 ._icon-coffeescript:before { background-position: 0 -2rem; @extend %darkIconFix !optional; }
7474 ._icon-ember:before { background-position: -1rem -2rem; }
75+._icon-immutable:before { background-position: -3rem -2rem; @extend %darkIconFix !optional; }
7576 ._icon-jqueryui:before { background-position: -4rem -2rem; }
7677 ._icon-jquerymobile:before { background-position: -5rem -2rem; }
7778 ._icon-lodash:before { background-position: -6rem -2rem; }
assets/stylesheets/pages/_simple.scss+1−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 ._gnu,
2626 ._grunt,
2727 ._haxe,
28+._immutable,
2829 ._influxdata,
2930 ._less,
3031 ._lodash,
lib/docs/filters/immutable/clean_html.rb+48−0
@@ -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
lib/docs/filters/immutable/entries.rb+23−0
@@ -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
lib/docs/scrapers/immutable.rb+58−0
@@ -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+ &copy; 2014&ndash;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
public/icons/docs/immutable/16.png+0−0

Binary file not shown.

public/icons/docs/immutable/16@2x.png+0−0

Binary file not shown.

public/icons/docs/immutable/SOURCE+1−0
@@ -0,0 +1 @@
1+https://raw.githubusercontent.com/facebook/immutable-js/master/pages/src/static/favicon.png