mirror of https://github.com/freeCodeCamp/devdocs
commit
3e1e65efec
@ -1 +1 @@
|
||||
2.6.0
|
||||
2.6.3
|
||||
|
@ -1,2 +1 @@
|
||||
public/icons
|
||||
test
|
||||
test
|
||||
|
@ -1,7 +1,26 @@
|
||||
language: ruby
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libcurl4-openssl-dev
|
||||
|
||||
cache: bundler
|
||||
|
||||
before_script:
|
||||
before_install:
|
||||
- "echo 'gem: --no-document' > ~/.gemrc"
|
||||
- gem update --system
|
||||
- gem install bundler
|
||||
|
||||
script:
|
||||
- if [ "$TRAVIS_EVENT_TYPE" != "cron" ]; then bundle exec rake; fi
|
||||
- if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then bundle exec thor updates:check --github-token $GH_TOKEN --upload; fi
|
||||
|
||||
deploy:
|
||||
provider: heroku
|
||||
app: devdocs
|
||||
on:
|
||||
branch: master
|
||||
condition: $TRAVIS_EVENT_TYPE != cron
|
||||
api_key:
|
||||
secure: "4p1klvWJZSOImzFcKOduILjP93hlOlAhceWlYMKS4tU+TCFE8qTBzdKdFPSCsCgjB+YR9pBss+L0lJpVVMjSwFHXqpKe6EeUSltO2k7DFHfW7kXLUM/L0AfqXz+YXk76XUyZMhvOEbldPfaMaj10e8vgDOQCSHABDyK/4CU+hnI="
|
||||
|
@ -0,0 +1,2 @@
|
||||
|
||||
> Our Code of Conduct is available here: <https://code-of-conduct.freecodecamp.org/>
|
@ -0,0 +1 @@
|
||||
sprites/**/*
|
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 48 KiB |
@ -1,42 +0,0 @@
|
||||
class app.AppCache
|
||||
$.extend @prototype, Events
|
||||
|
||||
@isEnabled: ->
|
||||
try
|
||||
applicationCache and applicationCache.status isnt applicationCache.UNCACHED
|
||||
catch
|
||||
|
||||
constructor: ->
|
||||
@cache = applicationCache
|
||||
@notifyUpdate = true
|
||||
@onUpdateReady() if @cache.status is @cache.UPDATEREADY
|
||||
|
||||
$.on @cache, 'progress', @onProgress
|
||||
$.on @cache, 'updateready', @onUpdateReady
|
||||
|
||||
update: ->
|
||||
@notifyUpdate = true
|
||||
@notifyProgress = true
|
||||
try @cache.update() catch
|
||||
return
|
||||
|
||||
updateInBackground: ->
|
||||
@notifyUpdate = false
|
||||
@notifyProgress = false
|
||||
try @cache.update() catch
|
||||
return
|
||||
|
||||
reload: ->
|
||||
$.on @cache, 'updateready noupdate error', -> app.reboot()
|
||||
@notifyUpdate = false
|
||||
@notifyProgress = true
|
||||
try @cache.update() catch
|
||||
return
|
||||
|
||||
onProgress: (event) =>
|
||||
@trigger 'progress', event if @notifyProgress
|
||||
return
|
||||
|
||||
onUpdateReady: =>
|
||||
@trigger 'updateready' if @notifyUpdate
|
||||
return
|
@ -0,0 +1,49 @@
|
||||
class app.ServiceWorker
|
||||
$.extend @prototype, Events
|
||||
|
||||
@isEnabled: ->
|
||||
!!navigator.serviceWorker and app.config.service_worker_enabled
|
||||
|
||||
constructor: ->
|
||||
@registration = null
|
||||
@notifyUpdate = true
|
||||
|
||||
navigator.serviceWorker.register(app.config.service_worker_path, {scope: '/'})
|
||||
.then(
|
||||
(registration) => @updateRegistration(registration),
|
||||
(error) -> console.error('Could not register service worker:', error)
|
||||
)
|
||||
|
||||
update: ->
|
||||
return unless @registration
|
||||
@notifyUpdate = true
|
||||
return @registration.update().catch(->)
|
||||
|
||||
updateInBackground: ->
|
||||
return unless @registration
|
||||
@notifyUpdate = false
|
||||
return @registration.update().catch(->)
|
||||
|
||||
reload: ->
|
||||
return @updateInBackground().then(() -> app.reboot())
|
||||
|
||||
updateRegistration: (registration) ->
|
||||
@registration = registration
|
||||
$.on @registration, 'updatefound', @onUpdateFound
|
||||
return
|
||||
|
||||
onUpdateFound: =>
|
||||
$.off @installingRegistration, 'statechange', @onStateChange() if @installingRegistration
|
||||
@installingRegistration = @registration.installing
|
||||
$.on @installingRegistration, 'statechange', @onStateChange
|
||||
return
|
||||
|
||||
onStateChange: =>
|
||||
if @installingRegistration and @installingRegistration.state == 'installed' and navigator.serviceWorker.controller
|
||||
@installingRegistration = null
|
||||
@onUpdateReady()
|
||||
return
|
||||
|
||||
onUpdateReady: ->
|
||||
@trigger 'updateready' if @notifyUpdate
|
||||
return
|
@ -1,4 +1,8 @@
|
||||
class @CookieStore
|
||||
class @CookiesStore
|
||||
# Intentionally called CookiesStore instead of CookieStore
|
||||
# Calling it CookieStore causes issues when the Experimental Web Platform features flag is enabled in Chrome
|
||||
# Related issue: https://github.com/freeCodeCamp/devdocs/issues/932
|
||||
|
||||
INT = /^\d+$/
|
||||
|
||||
@onBlocked: ->
|
@ -0,0 +1,64 @@
|
||||
defaultUrl = null
|
||||
currentSlug = null
|
||||
|
||||
imageCache = {}
|
||||
urlCache = {}
|
||||
|
||||
withImage = (url, action) ->
|
||||
if imageCache[url]
|
||||
action(imageCache[url])
|
||||
else
|
||||
img = new Image()
|
||||
img.crossOrigin = 'anonymous'
|
||||
img.src = url
|
||||
img.onload = () =>
|
||||
imageCache[url] = img
|
||||
action(img)
|
||||
|
||||
@setFaviconForDoc = (doc) ->
|
||||
return if currentSlug == doc.slug
|
||||
|
||||
favicon = $('link[rel="icon"]')
|
||||
|
||||
if defaultUrl == null
|
||||
defaultUrl = favicon.href
|
||||
|
||||
if urlCache[doc.slug]
|
||||
favicon.href = urlCache[doc.slug]
|
||||
currentSlug = doc.slug
|
||||
return
|
||||
|
||||
styles = window.getComputedStyle($("._icon-#{doc.slug.split('~')[0]}"), ':before')
|
||||
|
||||
bgUrl = app.config.favicon_spritesheet
|
||||
sourceSize = 16
|
||||
sourceX = Math.abs(parseInt(styles['background-position-x'].slice(0, -2)))
|
||||
sourceY = Math.abs(parseInt(styles['background-position-y'].slice(0, -2)))
|
||||
|
||||
withImage(bgUrl, (docImg) ->
|
||||
withImage(defaultUrl, (defaultImg) ->
|
||||
size = defaultImg.width
|
||||
|
||||
canvas = document.createElement('canvas')
|
||||
ctx = canvas.getContext('2d')
|
||||
|
||||
canvas.width = size
|
||||
canvas.height = size
|
||||
ctx.drawImage(defaultImg, 0, 0)
|
||||
|
||||
docIconPercentage = 65
|
||||
destinationCoords = size / 100 * (100 - docIconPercentage)
|
||||
destinationSize = size / 100 * docIconPercentage
|
||||
ctx.drawImage(docImg, sourceX, sourceY, sourceSize, sourceSize, destinationCoords, destinationCoords, destinationSize, destinationSize)
|
||||
|
||||
urlCache[doc.slug] = canvas.toDataURL()
|
||||
favicon.href = urlCache[doc.slug]
|
||||
|
||||
currentSlug = doc.slug
|
||||
)
|
||||
)
|
||||
|
||||
@resetFavicon = () ->
|
||||
if defaultUrl != null and currentSlug != null
|
||||
$('link[rel="icon"]').href = defaultUrl
|
||||
currentSlug = null
|
@ -1,28 +1,32 @@
|
||||
try {
|
||||
if (app.config.env == 'production') {
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
ga('create', 'UA-5544833-12', 'devdocs.io');
|
||||
page.track(function() {
|
||||
ga('send', 'pageview', {
|
||||
page: location.pathname + location.search + location.hash,
|
||||
dimension1: app.router.context && app.router.context.doc && app.router.context.doc.slug_without_version
|
||||
if (app.config.env === 'production') {
|
||||
if (Cookies.get('analyticsConsent') === '1') {
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
ga('create', 'UA-5544833-12', 'devdocs.io');
|
||||
page.track(function() {
|
||||
ga('send', 'pageview', {
|
||||
page: location.pathname + location.search + location.hash,
|
||||
dimension1: app.router.context && app.router.context.doc && app.router.context.doc.slug_without_version
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
page.track(function() {
|
||||
if (window._gauges)
|
||||
_gauges.push(['track']);
|
||||
else
|
||||
(function() {
|
||||
var _gauges=_gauges||[];!function(){var a=document.createElement("script");
|
||||
a.type="text/javascript",a.async=!0,a.id="gauges-tracker",
|
||||
a.setAttribute("data-site-id","51c15f82613f5d7819000067"),
|
||||
a.src="https://secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];
|
||||
b.parentNode.insertBefore(a,b)}();
|
||||
})();
|
||||
});
|
||||
page.track(function() {
|
||||
if (window._gauges)
|
||||
_gauges.push(['track']);
|
||||
else
|
||||
(function() {
|
||||
var _gauges=_gauges||[];!function(){var a=document.createElement("script");
|
||||
a.type="text/javascript",a.async=!0,a.id="gauges-tracker",
|
||||
a.setAttribute("data-site-id","51c15f82613f5d7819000067"),
|
||||
a.src="https://secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];
|
||||
b.parentNode.insertBefore(a,b)}();
|
||||
})();
|
||||
});
|
||||
} else {
|
||||
resetAnalytics();
|
||||
}
|
||||
}
|
||||
} catch(e) { }
|
||||
|
@ -1,182 +0,0 @@
|
||||
%svg-icon {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
pointer-events: none;
|
||||
fill: currentColor;
|
||||
}
|
||||
|
||||
%doc-icon {
|
||||
content: '';
|
||||
display: block;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
background-image: image-url('docs-1.png');
|
||||
background-size: 10rem 10rem;
|
||||
}
|
||||
|
||||
%doc-icon-2 { background-image: image-url('docs-2.png') !important; }
|
||||
|
||||
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
|
||||
%doc-icon { background-image: image-url('docs-1@2x.png'); }
|
||||
%doc-icon-2 { background-image: image-url('docs-2@2x.png') !important; }
|
||||
}
|
||||
|
||||
html._theme-dark {
|
||||
%darkIconFix {
|
||||
filter: invert(100%) grayscale(100%);
|
||||
-webkit-filter: invert(100%) grayscale(100%);
|
||||
}
|
||||
}
|
||||
|
||||
._icon-jest:before { background-position: 0 0; }
|
||||
._icon-liquid:before { background-position: -1rem 0; }
|
||||
._icon-openjdk:before { background-position: -2rem 0; }
|
||||
._icon-codeceptjs:before { background-position: -3rem 0; }
|
||||
._icon-codeception:before { background-position: -4rem 0; }
|
||||
._icon-sqlite:before { background-position: -5rem 0; @extend %darkIconFix !optional; }
|
||||
._icon-async:before { background-position: -6rem 0; @extend %darkIconFix !optional; }
|
||||
._icon-http:before { background-position: -7rem 0; @extend %darkIconFix !optional; }
|
||||
._icon-jquery:before { background-position: -8rem 0; @extend %darkIconFix !optional; }
|
||||
._icon-underscore:before { background-position: -9rem 0; @extend %darkIconFix !optional; }
|
||||
._icon-html:before { background-position: 0 -1rem; }
|
||||
._icon-css:before { background-position: -1rem -1rem; }
|
||||
._icon-dom:before { background-position: -2rem -1rem; }
|
||||
._icon-dom_events:before { background-position: -3rem -1rem; }
|
||||
._icon-javascript:before { background-position: -4rem -1rem; }
|
||||
._icon-backbone:before { background-position: -5rem -1rem; @extend %darkIconFix !optional; }
|
||||
._icon-node:before,
|
||||
._icon-node_lts:before { background-position: -6rem -1rem; }
|
||||
._icon-sass:before { background-position: -7rem -1rem; }
|
||||
._icon-less:before { background-position: -8rem -1rem; }
|
||||
._icon-angularjs:before { background-position: -9rem -1rem; }
|
||||
._icon-coffeescript:before { background-position: 0 -2rem; @extend %darkIconFix !optional; }
|
||||
._icon-ember:before { background-position: -1rem -2rem; }
|
||||
._icon-yarn:before { background-position: -2rem -2rem; }
|
||||
._icon-immutable:before { background-position: -3rem -2rem; @extend %darkIconFix !optional; }
|
||||
._icon-jqueryui:before { background-position: -4rem -2rem; }
|
||||
._icon-jquerymobile:before { background-position: -5rem -2rem; }
|
||||
._icon-lodash:before { background-position: -6rem -2rem; }
|
||||
._icon-php:before { background-position: -7rem -2rem; }
|
||||
._icon-ruby:before,
|
||||
._icon-minitest:before { background-position: -8rem -2rem; }
|
||||
._icon-rails:before { background-position: -9rem -2rem; }
|
||||
._icon-python:before,
|
||||
._icon-python2:before { background-position: 0 -3rem; }
|
||||
._icon-git:before { background-position: -1rem -3rem; }
|
||||
._icon-redis:before { background-position: -2rem -3rem; }
|
||||
._icon-postgresql:before { background-position: -3rem -3rem; }
|
||||
._icon-d3:before { background-position: -4rem -3rem; }
|
||||
._icon-knockout:before { background-position: -5rem -3rem; }
|
||||
._icon-moment:before { background-position: -6rem -3rem; @extend %darkIconFix !optional; }
|
||||
._icon-c:before { background-position: -7rem -3rem; }
|
||||
._icon-statsmodels:before { background-position: -8rem -3rem; }
|
||||
._icon-yii:before,
|
||||
._icon-yii1:before { background-position: -9rem -3rem; }
|
||||
._icon-cpp:before { background-position: 0 -4rem; }
|
||||
._icon-go:before { background-position: -1rem -4rem; }
|
||||
._icon-express:before { background-position: -2rem -4rem; }
|
||||
._icon-grunt:before { background-position: -3rem -4rem; }
|
||||
._icon-rust:before { background-position: -4rem -4rem; @extend %darkIconFix !optional; }
|
||||
._icon-laravel:before { background-position: -5rem -4rem; }
|
||||
._icon-haskell:before { background-position: -6rem -4rem; }
|
||||
._icon-requirejs:before { background-position: -7rem -4rem; }
|
||||
._icon-chai:before { background-position: -8rem -4rem; }
|
||||
._icon-sinon:before { background-position: -9rem -4rem; }
|
||||
._icon-cordova:before { background-position: 0 -5rem; }
|
||||
._icon-markdown:before { background-position: -1rem -5rem; @extend %darkIconFix !optional; }
|
||||
._icon-django:before { background-position: -2rem -5rem; }
|
||||
._icon-xslt_xpath:before { background-position: -3rem -5rem; }
|
||||
._icon-nginx:before,
|
||||
._icon-nginx_lua_module:before { background-position: -4rem -5rem; }
|
||||
._icon-svg:before { background-position: -5rem -5rem; }
|
||||
._icon-marionette:before { background-position: -6rem -5rem; }
|
||||
._icon-jsdoc:before,
|
||||
._icon-koa:before,
|
||||
._icon-graphite:before,
|
||||
._icon-mongoose:before { background-position: -7rem -5rem; }
|
||||
._icon-phpunit:before { background-position: -8rem -5rem; }
|
||||
._icon-nokogiri:before { background-position: -9rem -5rem; @extend %darkIconFix !optional; }
|
||||
._icon-rethinkdb:before { background-position: 0 -6rem; }
|
||||
._icon-react:before { background-position: -1rem -6rem; }
|
||||
._icon-socketio:before { background-position: -2rem -6rem; }
|
||||
._icon-modernizr:before { background-position: -3rem -6rem; }
|
||||
._icon-bower:before { background-position: -4rem -6rem; }
|
||||
._icon-fish:before { background-position: -5rem -6rem; @extend %darkIconFix !optional; }
|
||||
._icon-scikit_image:before { background-position: -6rem -6rem; }
|
||||
._icon-twig:before { background-position: -7rem -6rem; }
|
||||
._icon-pandas:before { background-position: -8rem -6rem; }
|
||||
._icon-scikit_learn:before { background-position: -9rem -6rem; }
|
||||
._icon-bottle:before { background-position: 0 -7rem; }
|
||||
._icon-docker:before { background-position: -1rem -7rem; }
|
||||
._icon-cakephp:before { background-position: -2rem -7rem; }
|
||||
._icon-lua:before { background-position: -3rem -7rem; @extend %darkIconFix !optional; }
|
||||
._icon-clojure:before { background-position: -4rem -7rem; }
|
||||
._icon-symfony:before { background-position: -5rem -7rem; }
|
||||
._icon-mocha:before { background-position: -6rem -7rem; }
|
||||
._icon-meteor:before { background-position: -7rem -7rem; @extend %darkIconFix !optional; }
|
||||
._icon-npm:before { background-position: -8rem -7rem; }
|
||||
._icon-apache_http_server:before { background-position: -9rem -7rem; }
|
||||
._icon-drupal:before { background-position: 0 -8rem; }
|
||||
._icon-webpack:before { background-position: -1rem -8rem; }
|
||||
._icon-phaser:before { background-position: -2rem -8rem; }
|
||||
._icon-vue:before { background-position: -3rem -8rem; }
|
||||
._icon-opentsdb:before { background-position: -4rem -8rem; }
|
||||
._icon-q:before { background-position: -5rem -8rem; }
|
||||
._icon-crystal:before { background-position: -6rem -8rem; @extend %darkIconFix !optional; }
|
||||
._icon-julia:before { background-position: -7rem -8rem; @extend %darkIconFix !optional; }
|
||||
._icon-redux:before { background-position: -8rem -8rem; @extend %darkIconFix !optional; }
|
||||
._icon-bootstrap:before { background-position: -9rem -8rem; }
|
||||
._icon-react_native:before { background-position: 0 -9rem; }
|
||||
._icon-phalcon:before { background-position: -1rem -9rem; }
|
||||
._icon-matplotlib:before { background-position: -2rem -9rem; }
|
||||
._icon-cmake:before { background-position: -3rem -9rem; }
|
||||
._icon-elixir:before { background-position: -4rem -9rem; @extend %darkIconFix !optional; }
|
||||
._icon-vagrant:before { background-position: -5rem -9rem; }
|
||||
._icon-dojo:before { background-position: -6rem -9rem; }
|
||||
._icon-flow:before { background-position: -7rem -9rem; }
|
||||
._icon-relay:before { background-position: -8rem -9rem; }
|
||||
._icon-phoenix:before { background-position: -9rem -9rem; }
|
||||
|
||||
._icon-tcl_tk:before { background-position: 0 0; @extend %doc-icon-2; }
|
||||
._icon-erlang:before { background-position: -1rem 0; @extend %doc-icon-2; }
|
||||
._icon-chef:before { background-position: -2rem 0; @extend %doc-icon-2; }
|
||||
._icon-ramda:before { background-position: -3rem 0; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
||||
._icon-codeigniter:before { background-position: -4rem 0; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
||||
._icon-influxdata:before { background-position: -5rem 0; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
||||
._icon-tensorflow:before { background-position: -6rem 0; @extend %doc-icon-2; }
|
||||
._icon-haxe:before { background-position: -7rem 0; @extend %doc-icon-2; }
|
||||
._icon-ansible:before { background-position: -8rem 0; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
||||
._icon-typescript:before { background-position: -9rem 0; @extend %doc-icon-2; }
|
||||
._icon-browser_support_tables:before { background-position: 0rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-gnu_fortran:before { background-position: -1rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-gcc:before { background-position: -2rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-perl:before { background-position: -3rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-apache_pig:before { background-position: -4rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-numpy:before { background-position: -5rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-kotlin:before { background-position: -6rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-padrino:before { background-position: -7rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-angular:before { background-position: -8rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-love:before { background-position: -9rem -1rem; @extend %doc-icon-2; }
|
||||
._icon-jasmine:before { background-position: 0 -2rem; @extend %doc-icon-2; }
|
||||
._icon-pug:before { background-position: -1rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-electron:before { background-position: -2rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-falcon:before { background-position: -3rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-godot:before { background-position: -4rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-nim:before { background-position: -5rem -2rem; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
||||
._icon-vulkan:before { background-position: -6rem -2rem; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
||||
._icon-d:before { background-position: -7rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-bluebird:before { background-position: -8rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-eslint:before { background-position: -9rem -2rem; @extend %doc-icon-2; }
|
||||
._icon-homebrew:before { background-position: 0 -3rem; @extend %doc-icon-2; }
|
||||
._icon-jekyll:before { background-position: -1rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-babel:before { background-position: -2rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-leaflet:before { background-position: -3rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-terraform:before { background-position: -4rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-pygame:before { background-position: -5rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-bash:before { background-position: -6rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-dart:before { background-position: -7rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-qt:before { background-position: -8rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-puppeteer:before { background-position: -9rem -3rem; @extend %doc-icon-2; }
|
||||
._icon-handlebars:before { background-position: 0 -4rem; @extend %doc-icon-2; @extend %darkIconFix !optional; }
|
@ -0,0 +1,43 @@
|
||||
<% manifest = JSON.parse(File.read('assets/images/sprites/docs.json')) %>
|
||||
|
||||
%svg-icon {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
pointer-events: none;
|
||||
fill: currentColor;
|
||||
}
|
||||
|
||||
%doc-icon {
|
||||
content: '';
|
||||
display: block;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
background-image: image-url('sprites/docs.png');
|
||||
background-size: <%= manifest['icons_per_row'] %>rem <%= manifest['icons_per_row'] %>rem;
|
||||
}
|
||||
|
||||
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
|
||||
%doc-icon { background-image: image-url('sprites/docs@2x.png'); }
|
||||
}
|
||||
|
||||
html._theme-dark {
|
||||
%darkIconFix {
|
||||
filter: invert(100%) grayscale(100%);
|
||||
-webkit-filter: invert(100%) grayscale(100%);
|
||||
}
|
||||
}
|
||||
|
||||
<%=
|
||||
items = []
|
||||
|
||||
manifest['items'].each do |item|
|
||||
rules = []
|
||||
rules << "background-position: -#{item['col']}rem -#{item['row']}rem;"
|
||||
rules << "@extend %darkIconFix !optional;" if item['dark_icon_fix']
|
||||
items << "._icon-#{item['type']}:before { #{rules.join(' ')} }"
|
||||
end
|
||||
|
||||
items.join('')
|
||||
%>
|
@ -0,0 +1,21 @@
|
||||
._cypress {
|
||||
@extend %simple;
|
||||
|
||||
.note {
|
||||
h1 {
|
||||
margin-left: inherit
|
||||
}
|
||||
|
||||
&.danger {
|
||||
@extend %note-red
|
||||
}
|
||||
|
||||
&.info {
|
||||
@extend %note-blue
|
||||
}
|
||||
|
||||
&.success {
|
||||
@extend %note-green
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
._scala {
|
||||
@extend %simple;
|
||||
.deprecated { @extend %label-red; }
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
._wordpress {
|
||||
@extend %simple;
|
||||
|
||||
.breadcrumbs {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.callout-warning {
|
||||
@extend %note, %note-red;
|
||||
}
|
||||
|
||||
.callout-alert {
|
||||
@extend %note, %note-orange;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
Adding a documentation may look like a daunting task but once you get the hang of it, it's actually quite simple. Don't hesitate to ask for help [in Gitter](https://gitter.im/FreeCodeCamp/DevDocs) if you ever get stuck.
|
||||
|
||||
**Note:** please read the [contributing guidelines](../.github/CONTRIBUTING.md) before submitting a new documentation.
|
||||
|
||||
1. Create a subclass of `Docs::UrlScraper` or `Docs::FileScraper` in the `lib/docs/scrapers/` directory. Its name should be the [PascalCase](http://api.rubyonrails.org/classes/String.html#method-i-camelize) equivalent of the filename (e.g. `my_doc` → `MyDoc`)
|
||||
2. Add the appropriate class attributes and filter options (see the [Scraper Reference](./scraper-reference.md) page).
|
||||
3. Check that the scraper is listed in `thor docs:list`.
|
||||
4. Create filters specific to the scraper in the `lib/docs/filters/[my_doc]/` directory and add them to the class's [filter stacks](./scraper-reference.md#filter-stacks). You may create any number of filters but will need at least the following two:
|
||||
* A [`CleanHtml`](./filter-reference.md#cleanhtmlfilter) filter whose task is to clean the HTML markup (e.g. adding `id` attributes to headings) and remove everything superfluous and/or nonessential.
|
||||
* An [`Entries`](./filter-reference.md#entriesfilter) filter whose task is to determine the pages' metadata (the list of entries, each with a name, type and path).
|
||||
The [Filter Reference](./filter-reference.md) page has all the details about filters.
|
||||
5. Using the `thor docs:page [my_doc] [path]` command, check that the scraper works properly. Files will appear in the `public/docs/[my_doc]/` directory (but not inside the app as the command doesn't touch the index). `path` in this case refers to either the remote path (if using `UrlScraper`) or the local path (if using `FileScraper`).
|
||||
6. Generate the full documentation using the `thor docs:generate [my_doc] --force` command. Additionally, you can use the `--verbose` option to see which files are being created/updated/deleted (useful to see what changed since the last run), and the `--debug` option to see which URLs are being requested and added to the queue (useful to pin down which page adds unwanted URLs to the queue).
|
||||
7. Start the server, open the app, enable the documentation, and see how everything plays out.
|
||||
8. Tweak the scraper/filters and repeat 5) and 6) until the pages and metadata are ok.
|
||||
9. To customize the pages' styling, create an SCSS file in the `assets/stylesheets/pages/` directory and import it in both `application.css.scss` AND `application-dark.css.scss`. Both the file and CSS class should be named `_[type]` where [type] is equal to the scraper's `type` attribute (documentations with the same type share the same custom CSS and JS). Setting the type to `simple` will apply the general styling rules in `assets/stylesheets/pages/_simple.scss`, which can be used for documentations where little to no CSS changes are needed.
|
||||
10. To add syntax highlighting or execute custom JavaScript on the pages, create a file in the `assets/javascripts/views/pages/` directory (take a look at the other files to see how it works).
|
||||
11. Add the documentation's icon in the `public/icons/docs/[my_doc]/` directory, in both 16x16 and 32x32-pixels formats. The icon spritesheet is automatically generated when you (re)start your local DevDocs instance.
|
||||
12. Add the documentation's copyright details to the list in `assets/javascripts/templates/pages/about_tmpl.coffee`. This is the data shown in the table on the [about](https://devdocs.io/about) page, and is ordered alphabetically. Simply copying an existing item, placing it in the right slot and updating the values to match the new scraper will do the job.
|
||||
13. Ensure `thor updates:check [my_doc]` shows the correct latest version.
|
||||
|
||||
If the documentation includes more than a few hundreds pages and is available for download, try to scrape it locally (e.g. using `FileScraper`). It'll make the development process much faster and avoids putting too much load on the source site. (It's not a problem if your scraper is coupled to your local setup, just explain how it works in your pull request.)
|
||||
|
||||
Finally, try to document your scraper and filters' behavior as much as possible using comments (e.g. why some URLs are ignored, HTML markup removed, metadata that way, etc.). It'll make updating the documentation much easier.
|
@ -0,0 +1,224 @@
|
||||
**Table of contents:**
|
||||
|
||||
* [Overview](#overview)
|
||||
* [Instance methods](#instance-methods)
|
||||
* [Core filters](#core-filters)
|
||||
* [Custom filters](#custom-filters)
|
||||
- [CleanHtmlFilter](#cleanhtmlfilter)
|
||||
- [EntriesFilter](#entriesfilter)
|
||||
|
||||
## Overview
|
||||
|
||||
Filters use the [HTML::Pipeline](https://github.com/jch/html-pipeline) library. They take an HTML string or [Nokogiri](http://nokogiri.org/) node as input, optionally perform modifications and/or extract information from it, and then outputs the result. Together they form a pipeline where each filter hands its output to the next filter's input. Every documentation page passes through this pipeline before being copied on the local filesystem.
|
||||
|
||||
Filters are subclasses of the [`Docs::Filter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/filter.rb) class and require a `call` method. A basic implementation looks like this:
|
||||
|
||||
```ruby
|
||||
module Docs
|
||||
class CustomFilter < Filter
|
||||
def call
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Filters which manipulate the Nokogiri node object (`doc` and related methods) are _HTML filters_ and must not manipulate the HTML string (`html`). Vice-versa, filters which manipulate the string representation of the document are _text filters_ and must not manipulate the Nokogiri node object. The two types are divided into two stacks within the scrapers. These stacks are then combined into a pipeline that calls the HTML filters before the text filters (more details [here](./scraper-reference.md#filter-stacks)). This is to avoid parsing the document multiple times.
|
||||
|
||||
The `call` method must return either `doc` or `html`, depending on the type of filter.
|
||||
|
||||
## Instance methods
|
||||
|
||||
* `doc` [Nokogiri::XML::Node]
|
||||
The Nokogiri representation of the container element.
|
||||
See [Nokogiri's API docs](http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node) for the list of available methods.
|
||||
|
||||
* `html` [String]
|
||||
The string representation of the container element.
|
||||
|
||||
* `context` [Hash] **(frozen)**
|
||||
The scraper's `options` along with a few additional keys: `:base_url`, `:root_url`, `:root_page` and `:url`.
|
||||
|
||||
* `result` [Hash]
|
||||
Used to store the page's metadata and pass back information to the scraper.
|
||||
Possible keys:
|
||||
|
||||
- `:path` — the page's normalized path
|
||||
- `:store_path` — the path where the page will be stored (equal to `:path` with `.html` at the end)
|
||||
- `:internal_urls` — the list of distinct internal URLs found within the page
|
||||
- `:entries` — the [`Entry`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/models/entry.rb) objects to add to the index
|
||||
|
||||
* `css`, `at_css`, `xpath`, `at_xpath`
|
||||
Shortcuts for `doc.css`, `doc.xpath`, etc.
|
||||
|
||||
* `base_url`, `current_url`, `root_url` [Docs::URL]
|
||||
Shortcuts for `context[:base_url]`, `context[:url]`, and `context[:root_url]` respectively.
|
||||
|
||||
* `root_path` [String]
|
||||
Shortcut for `context[:root_path]`.
|
||||
|
||||
* `subpath` [String]
|
||||
The sub-path from the base URL of the current URL.
|
||||
_Example: if `base_url` equals `example.com/docs` and `current_url` equals `example.com/docs/file?raw`, the returned value is `/file`._
|
||||
|
||||
* `slug` [String]
|
||||
The `subpath` removed of any leading slash or `.html` extension.
|
||||
_Example: if `subpath` equals `/dir/file.html`, the returned value is `dir/file`._
|
||||
|
||||
* `root_page?` [Boolean]
|
||||
Returns `true` if the current page is the root page.
|
||||
|
||||
* `initial_page?` [Boolean]
|
||||
Returns `true` if the current page is the root page or its subpath is one of the scraper's `initial_paths`.
|
||||
|
||||
## Core filters
|
||||
|
||||
* [`ContainerFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/container.rb) — changes the root node of the document (remove everything outside)
|
||||
* [`CleanHtmlFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_html.rb) — removes HTML comments, `<script>`, `<style>`, etc.
|
||||
* [`NormalizeUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/normalize_urls.rb) — replaces all URLs with their fully qualified counterpart
|
||||
* [`InternalUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/internal_urls.rb) — detects internal URLs (the ones to scrape) and replaces them with their unqualified, relative counterpart
|
||||
* [`NormalizePathsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/normalize_paths.rb) — makes the internal paths consistent (e.g. always end with `.html`)
|
||||
* [`CleanLocalUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_local_urls.rb) — removes links, iframes and images pointing to localhost (`FileScraper` only)
|
||||
* [`InnerHtmlFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/inner_html.rb) — converts the document to a string
|
||||
* [`CleanTextFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_text.rb) — removes empty nodes
|
||||
* [`AttributionFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/attribution.rb) — appends the license info and link to the original document
|
||||
* [`TitleFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/title.rb) — prepends the document with a title (disabled by default)
|
||||
* [`EntriesFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/entries.rb) — abstract filter for extracting the page's metadata
|
||||
|
||||
## Custom filters
|
||||
|
||||
Scrapers can have any number of custom filters but require at least the two described below.
|
||||
|
||||
**Note:** filters are located in the [`lib/docs/filters`](https://github.com/Thibaut/devdocs/tree/master/lib/docs/filters/) directory. The class's name must be the [CamelCase](http://api.rubyonrails.org/classes/String.html#method-i-camelize) equivalent of the filename.
|
||||
|
||||
### `CleanHtmlFilter`
|
||||
|
||||
The `CleanHtml` filter is tasked with cleaning the HTML markup where necessary and removing anything superfluous or nonessential. Only the core documentation should remain at the end.
|
||||
|
||||
Nokogiri's many jQuery-like methods make it easy to search and modify elements — see the [API docs](http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node).
|
||||
|
||||
Here's an example implementation that covers the most common use-cases:
|
||||
|
||||
```ruby
|
||||
module Docs
|
||||
class MyScraper
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
css('hr').remove
|
||||
css('#changelog').remove if root_page?
|
||||
|
||||
# Set id attributes on <h3> instead of an empty <a>
|
||||
css('h3').each do |node|
|
||||
node['id'] = node.at_css('a')['id']
|
||||
end
|
||||
|
||||
# Make proper table headers
|
||||
css('td.header').each do |node|
|
||||
node.name = 'th'
|
||||
end
|
||||
|
||||
# Remove code highlighting
|
||||
css('pre').each do |node|
|
||||
node.content = node.content
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
**Notes:**
|
||||
|
||||
* Empty elements will be automatically removed by the core `CleanTextFilter` later in the pipeline's execution.
|
||||
* Although the goal is to end up with a clean version of the page, try to keep the number of modifications to a minimum, so as to make the code easier to maintain. Custom CSS is the preferred way of normalizing the pages (except for hiding stuff which should always be done by removing the markup).
|
||||
* Try to document your filter's behavior as much as possible, particularly modifications that apply only to a subset of pages. It'll make updating the documentation easier.
|
||||
|
||||
### `EntriesFilter`
|
||||
|
||||
The `Entries` filter is responsible for extracting the page's metadata, represented by a set of _entries_, each with a name, type and path.
|
||||
|
||||
The following two models are used under the hood to represent the metadata:
|
||||
|
||||
* [`Entry(name, type, path)`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/models/entry.rb)
|
||||
* [`Type(name, slug, count)`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/models/type.rb)
|
||||
|
||||
Each scraper must implement its own `EntriesFilter` by subclassing the [`Docs::EntriesFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/entries.rb) class. The base class already implements the `call` method and includes four methods which the subclasses can override:
|
||||
|
||||
* `get_name` [String]
|
||||
The name of the default entry (aka. the page's name).
|
||||
It is usually guessed from the `slug` (documented above) or by searching the HTML markup.
|
||||
**Default:** modified version of `slug` (underscores are replaced with spaces and forward slashes with dots)
|
||||
|
||||
* `get_type` [String]
|
||||
The type of the default entry (aka. the page's type).
|
||||
Entries without a type can be searched for but won't be listed in the app's sidebar (unless no other entries have a type).
|
||||
**Default:** `nil`
|
||||
|
||||
* `include_default_entry?` [Boolean]
|
||||
Whether to include the default entry.
|
||||
Used when a page consists of multiple entries (returned by `additional_entries`) but doesn't have a name/type of its own, or to remove a page from the index (if it has no additional entries), in which case it won't be copied on the local filesystem and any link to it in the other pages will be broken (as explained on the [Scraper Reference](./scraper-reference.md) page, this is used to keep the `:skip` / `:skip_patterns` options to a maintainable size, or if the page includes links that can't reached from anywhere else).
|
||||
**Default:** `true`
|
||||
|
||||
* `additional_entries` [Array]
|
||||
The list of additional entries.
|
||||
Each entry is represented by an Array of three attributes: its name, fragment identifier, and type. The fragment identifier refers to the `id` attribute of the HTML element (usually a heading) that the entry relates to. It is combined with the page's path to become the entry's path. If absent or `nil`, the page's path is used. If the type is absent or `nil`, the default `type` is used.
|
||||
Example: `[ ['One'], ['Two', 'id'], ['Three', nil, 'type'] ]` adds three additional entries, the first one named "One" with the default path and type, the second one named "Two" with the URL fragment "#id" and the default type, and the third one named "Three" with the default path and the type "type".
|
||||
The list is usually constructed by running through the markup. Exceptions can also be hard-coded for specific pages.
|
||||
**Default:** `[]`
|
||||
|
||||
The following accessors are also available, but must not be overridden:
|
||||
|
||||
* `name` [String]
|
||||
Memoized version of `get_name` (`nil` for the root page).
|
||||
|
||||
* `type` [String]
|
||||
Memoized version of `get_type` (`nil` for the root page).
|
||||
|
||||
**Notes:**
|
||||
|
||||
* Leading and trailing whitespace is automatically removed from names and types.
|
||||
* Names must be unique across the documentation and as short as possible (ideally less than 30 characters). Whenever possible, methods should be differentiated from properties by appending `()`, and instance methods should be differentiated from class methods using the `Class#method` or `object.method` conventions.
|
||||
* You can call `name` from `get_type` or `type` from `get_name` but doing both will cause a stack overflow (i.e. you can infer the name from the type or the type from the name, but you can't do both at the same time). Don't call `get_name` or `get_type` directly as their value isn't memoized.
|
||||
* The root page has no name and no type (both are `nil`). `get_name` and `get_type` won't get called with the page (but `additional_entries` will).
|
||||
* `Docs::EntriesFilter` is an _HTML filter_. It must be added to the scraper's `html_filters` stack.
|
||||
* Try to document the code as much as possible, particularly the special cases. It'll make updating the documentation easier.
|
||||
|
||||
**Example:**
|
||||
|
||||
```ruby
|
||||
module Docs
|
||||
class MyScraper
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_name
|
||||
node = at_css('h1')
|
||||
result = node.content.strip
|
||||
result << ' event' if type == 'Events'
|
||||
result << '()' if node['class'].try(:include?, 'function')
|
||||
result
|
||||
end
|
||||
|
||||
def get_type
|
||||
object, method = *slug.split('/')
|
||||
method ? object : 'Miscellaneous'
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
return [] if root_page?
|
||||
|
||||
css('h2').map do |node|
|
||||
[node.content, node['id']]
|
||||
end
|
||||
end
|
||||
|
||||
def include_default_entry?
|
||||
!at_css('.obsolete')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
return [[Home]]
|
@ -0,0 +1,227 @@
|
||||
**Table of contents:**
|
||||
|
||||
* [Overview](#overview)
|
||||
* [Configuration](#configuration)
|
||||
- [Attributes](#attributes)
|
||||
- [Filter stacks](#filter-stacks)
|
||||
- [Filter options](#filter-options)
|
||||
|
||||
## Overview
|
||||
|
||||
Starting from a root URL, scrapers recursively follow links that match a set of rules, passing each valid response through a chain of filters before writing the file on the local filesystem. They also create an index of the pages' metadata (determined by one filter), which is dumped into a JSON file at the end.
|
||||
|
||||
Scrapers rely on the following libraries:
|
||||
|
||||
* [Typhoeus](https://github.com/typhoeus/typhoeus) for making HTTP requests
|
||||
* [HTML::Pipeline](https://github.com/jch/html-pipeline) for applying filters
|
||||
* [Nokogiri](http://nokogiri.org/) for parsing HTML
|
||||
|
||||
There are currently two kinds of scrapers: [`UrlScraper`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/scrapers/url_scraper.rb) which downloads files via HTTP and [`FileScraper`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/scrapers/file_scraper.rb) which reads them from the local filesystem. They function almost identically (both use URLs), except that `FileScraper` substitutes the base URL with a local path before reading a file. `FileScraper` uses the placeholder `localhost` base URL by default and includes a filter to remove any URL pointing to it at the end.
|
||||
|
||||
To be processed, a response must meet the following requirements:
|
||||
|
||||
* 200 status code
|
||||
* HTML content type
|
||||
* effective URL (after redirection) contained in the base URL (explained below)
|
||||
|
||||
(`FileScraper` only checks if the file exists and is not empty.)
|
||||
|
||||
Each URL is requested only once (case-insensitive).
|
||||
|
||||
## Configuration
|
||||
|
||||
Configuration is done via class attributes and divided into three main categories:
|
||||
|
||||
* [Attributes](#attributes) — essential information such as name, version, URL, etc.
|
||||
* [Filter stacks](#filter-stacks) — the list of filters that will be applied to each page.
|
||||
* [Filter options](#filter-options) — the options passed to said filters.
|
||||
|
||||
**Note:** scrapers are located in the [`lib/docs/scrapers`](https://github.com/Thibaut/devdocs/tree/master/lib/docs/scrapers/) directory. The class's name must be the [CamelCase](http://api.rubyonrails.org/classes/String.html#method-i-camelize) equivalent of the filename.
|
||||
|
||||
### Attributes
|
||||
|
||||
* `name` [String]
|
||||
Must be unique.
|
||||
Defaults to the class's name.
|
||||
|
||||
* `slug` [String]
|
||||
Must be unique, lowercase, and not include dashes (underscores are ok).
|
||||
Defaults to `name` lowercased.
|
||||
|
||||
* `type` [String] **(required, inherited)**
|
||||
Defines the CSS class name (`_[type]`) and custom JavaScript class (`app.views.[Type]Page`) that will be added/loaded on each page. Documentations sharing a similar structure (e.g. generated with the same tool or originating from the same website) should use the same `type` to avoid duplicating the CSS and JS.
|
||||
Must include lowercase letters only.
|
||||
|
||||
* `release` [String] **(required)**
|
||||
The version of the software at the time the scraper was last run. This is only informational and doesn't affect the scraper's behavior.
|
||||
|
||||
* `base_url` [String] **(required in `UrlScraper`)**
|
||||
The documents' location. Only URLs _inside_ the `base_url` will be scraped. "inside" more or less means "starting with" except that `/docs` is outside `/doc` (but `/doc/` is inside).
|
||||
Defaults to `localhost` in `FileScraper`. _(Note: any iframe, image, or skipped link pointing to localhost will be removed by the `CleanLocalUrls` filter; the value should be overridden if the documents are available online.)_
|
||||
Unless `root_path` is set, the root/initial URL is equal to `base_url`.
|
||||
|
||||
* `root_path` [String] **(inherited)**
|
||||
The path from the `base_url` of the root URL.
|
||||
|
||||
* `initial_paths` [Array] **(inherited)**
|
||||
A list of paths (from the `base_url`) to add to the initial queue. Useful for scraping isolated documents.
|
||||
Defaults to `[]`. _(Note: the `root_path` is added to the array at runtime.)_
|
||||
|
||||
* `dir` [String] **(required, `FileScraper` only)**
|
||||
The absolute path where the files are located on the local filesystem.
|
||||
_Note: `FileScraper` works exactly like `UrlScraper` (manipulating the same kind of URLs) except that it substitutes `base_url` with `dir` in order to read files instead of making HTTP requests._
|
||||
|
||||
* `params` [Hash] **(inherited, `UrlScraper` only)**
|
||||
Query string parameters to append to every URL. (e.g. `{ format: 'raw' }` → `?format=raw`)
|
||||
Defaults to `{}`.
|
||||
|
||||
* `abstract` [Boolean]
|
||||
Make the scraper abstract / not runnable. Used for sharing behavior with other scraper classes (e.g. all MDN scrapers inherit from the abstract [`Mdn`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/scrapers/mdn/mdn.rb) class).
|
||||
Defaults to `false`.
|
||||
|
||||
### Filter stacks
|
||||
|
||||
Each scraper has two [filter](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/filter.rb) [stacks](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/filter_stack.rb): `html_filters` and `text_filters`. They are combined into a pipeline (using the [HTML::Pipeline](https://github.com/jch/html-pipeline) library) which causes each filter to hand its output to the next filter's input.
|
||||
|
||||
HTML filters are executed first and manipulate a parsed version of the document (a [Nokogiri](http://nokogiri.org/Nokogiri/XML/Node.html) node object), whereas text filters manipulate the document as a string. This separation avoids parsing the document multiple times.
|
||||
|
||||
Filter stacks are like sorted sets. They can modified using the following methods:
|
||||
|
||||
```ruby
|
||||
push(*names) # append one or more filters at the end
|
||||
insert_before(index, *names) # insert one filter before another (index can be a name)
|
||||
insert_after(index, *names) # insert one filter after another (index can be a name)
|
||||
replace(index, name) # replace one filter with another (index can be a name)
|
||||
```
|
||||
|
||||
"names" are `require` paths relative to `Docs` (e.g. `jquery/clean_html` → `Docs::Jquery::CleanHtml`).
|
||||
|
||||
Default `html_filters`:
|
||||
|
||||
* [`ContainerFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/container.rb) — changes the root node of the document (remove everything outside)
|
||||
* [`CleanHtmlFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_html.rb) — removes HTML comments, `<script>`, `<style>`, etc.
|
||||
* [`NormalizeUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/normalize_urls.rb) — replaces all URLs with their fully qualified counterpart
|
||||
* [`InternalUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/internal_urls.rb) — detects internal URLs (the ones to scrape) and replaces them with their unqualified, relative counterpart
|
||||
* [`NormalizePathsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/normalize_paths.rb) — makes the internal paths consistent (e.g. always end with `.html`)
|
||||
* [`CleanLocalUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_local_urls.rb) — removes links, iframes and images pointing to localhost (`FileScraper` only)
|
||||
|
||||
Default `text_filters`:
|
||||
|
||||
* [`InnerHtmlFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/inner_html.rb) — converts the document to a string
|
||||
* [`CleanTextFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_text.rb) — removes empty nodes
|
||||
* [`AttributionFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/attribution.rb) — appends the license info and link to the original document
|
||||
|
||||
Additionally:
|
||||
|
||||
* [`TitleFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/title.rb) is a core HTML filter, disabled by default, which prepends the document with a title (`<h1>`).
|
||||
* [`EntriesFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/entries.rb) is an abstract HTML filter that each scraper must implement and responsible for extracting the page's metadata.
|
||||
|
||||
### Filter options
|
||||
|
||||
The filter options are stored in the `options` Hash. The Hash is inheritable (a recursive copy) and empty by default.
|
||||
|
||||
More information about how filters work is available on the [Filter Reference](./filter-reference.md) page.
|
||||
|
||||
* [`ContainerFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/container.rb)
|
||||
|
||||
- `:container` [String or Proc]
|
||||
A CSS selector of the container element. Everything outside of it will be removed and become unavailable to the other filters. If more than one element match the selector, the first one inside the DOM is used. If no elements match the selector, an error is raised.
|
||||
If the value is a Proc, it is called for each page with the filter instance as argument, and should return a selector or `nil`.
|
||||
The default container is the `<body>` element.
|
||||
_Note: links outside of the container element will not be followed by the scraper. To remove links that should be followed, use a [`CleanHtml`](./filter-reference.md#cleanhtmlfilter) filter later in the stack._
|
||||
|
||||
* [`NormalizeUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/normalize_urls.rb)
|
||||
The following options are used to modify URLs in the pages. They are useful to remove duplicates (when the same page is accessible from multiple URLs) and fix websites that have a bunch of redirections in place (when URLs that should be scraped, aren't, because they are behind a redirection which is outside of the `base_url` — see the MDN scrapers for examples of this).
|
||||
|
||||
- `:replace_urls` [Hash]
|
||||
Replaces all instances of a URL with another.
|
||||
Format: `{ 'original_url' => 'new_url' }`
|
||||
- `:replace_paths` [Hash]
|
||||
Replaces all instances of a sub-path (path from the `base_url`) with another.
|
||||
Format: `{ 'original_path' => 'new_path' }`
|
||||
- `:fix_urls` [Proc]
|
||||
Called with each URL. If the returned value is `nil`, the URL isn't modified. Otherwise the returned value is used as replacement.
|
||||
|
||||
_Note: before these rules are applied, all URLs are converted to their fully qualified counterpart (http://...)._
|
||||
|
||||
* [`InternalUrlsFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/internal_urls.rb)
|
||||
|
||||
Internal URLs are the ones _inside_ the scraper's `base_url` ("inside" more or less means "starting with", except that `/docs` is outside `/doc`). They will be scraped unless excluded by one of the following rules. All internal URLs are converted to relative URLs inside the pages.
|
||||
|
||||
- `:skip_links` [Boolean or Proc]
|
||||
If `false`, does not convert or follow any internal URL (creating a single-page documentation).
|
||||
If the value is a Proc, it is called for each page with the filter instance as argument.
|
||||
- `:follow_links` [Proc]
|
||||
Called for page with the filter instance as argument. If the returned value is `false`, does not add internal URLs to the queue.
|
||||
- `:trailing_slash` [Boolean]
|
||||
If `true`, adds a trailing slash to all internal URLs. If `false`, removes it.
|
||||
This is another option used to remove duplicate pages.
|
||||
- `:skip` [Array]
|
||||
Ignores internal URLs whose sub-paths (path from the `base_url`) are in the Array (case-insensitive).
|
||||
- `:skip_patterns` [Array]
|
||||
Ignores internal URLs whose sub-paths match any Regexp in the Array.
|
||||
- `:only` [Array]
|
||||
Ignores internal URLs whose sub-paths aren't in the Array (case-insensitive) and don't match any Regexp in `:only_patterns`.
|
||||
- `:only_patterns` [Array]
|
||||
Ignores internal URLs whose sub-paths don't match any Regexp in the Array and aren't in `:only`.
|
||||
|
||||
If the scraper has a `root_path`, the empty and `/` paths are automatically skipped.
|
||||
If `:only` or `:only_patterns` is set, the root path is automatically added to `:only`.
|
||||
|
||||
_Note: pages can be excluded from the index based on their content using the [`Entries`](./filter-reference.md#entriesfilter) filter. However, their URLs will still be converted to relative in the other pages and trying to open them will return a 404 error. Although not ideal, this is often better than having to maintain a long list of `:skip` URLs._
|
||||
|
||||
* [`AttributionFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/attribution.rb)
|
||||
|
||||
- `:attribution` [String] **(required)**
|
||||
An HTML string with the copyright and license information. See the other scrapers for examples.
|
||||
|
||||
* [`TitleFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/title.rb)
|
||||
|
||||
- `:title` [String or Boolean or Proc]
|
||||
Unless the value is `false`, adds a title to every page.
|
||||
If the value is `nil`, the title is the name of the page as determined by the [`Entries`](./filter-reference.md#entriesfilter) filter. Otherwise the title is the String or the value returned by the Proc (called for each page, with the filter instance as argument). If the Proc returns `nil` or `false`, no title is added.
|
||||
- `:root_title` [String or Boolean]
|
||||
Overrides the `:title` option for the root page only.
|
||||
|
||||
_Note: this filter is disabled by default._
|
||||
|
||||
## Keeping scrapers up-to-date
|
||||
|
||||
In order to keep scrapers up-to-date the `get_latest_version(opts)` method should be overridden. If `self.release` is defined, this should return the latest version of the documentation. If `self.release` is not defined, it should return the Epoch time when the documentation was last modified. If the documentation will never change, simply return `1.0.0`. The result of this method is periodically reported in a "Documentation versions report" issue which helps maintainers keep track of outdated documentations.
|
||||
|
||||
To make life easier, there are a few utility methods that you can use in `get_latest_version`:
|
||||
* `fetch(url, opts)`
|
||||
|
||||
Makes a GET request to the url and returns the response body.
|
||||
|
||||
Example: [lib/docs/scrapers/bash.rb](../lib/docs/scrapers/bash.rb)
|
||||
* `fetch_doc(url, opts)`
|
||||
|
||||
Makes a GET request to the url and returns the HTML body converted to a Nokogiri document.
|
||||
|
||||
Example: [lib/docs/scrapers/git.rb](../lib/docs/scrapers/git.rb)
|
||||
* `fetch_json(url, opts)`
|
||||
|
||||
Makes a GET request to the url and returns the JSON body converted to a dictionary.
|
||||
|
||||
Example: [lib/docs/scrapers/mdn/mdn.rb](../lib/docs/scrapers/mdn/mdn.rb)
|
||||
* `get_npm_version(package, opts)`
|
||||
|
||||
Returns the latest version of the given npm package.
|
||||
|
||||
Example: [lib/docs/scrapers/bower.rb](../lib/docs/scrapers/bower.rb)
|
||||
* `get_latest_github_release(owner, repo, opts)`
|
||||
|
||||
Returns the tag name of the latest GitHub release of the given repository. If the tag name is preceded by a "v", the "v" will be removed.
|
||||
|
||||
Example: [lib/docs/scrapers/jsdoc.rb](../lib/docs/scrapers/jsdoc.rb)
|
||||
* `get_github_tags(owner, repo, opts)`
|
||||
|
||||
Returns the list of tags on the given repository ([format](https://developer.github.com/v3/repos/#list-tags)).
|
||||
|
||||
Example: [lib/docs/scrapers/liquid.rb](../lib/docs/scrapers/liquid.rb)
|
||||
* `get_github_file_contents(owner, repo, path, opts)`
|
||||
|
||||
Returns the contents of the requested file in the default branch of the given repository.
|
||||
|
||||
Example: [lib/docs/scrapers/minitest.rb](../lib/docs/scrapers/minitest.rb)
|
@ -0,0 +1,35 @@
|
||||
module Docs
|
||||
class Composer
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
# Remove unneeded elements
|
||||
css('#searchbar, .toc, .fork-and-edit, .anchor').remove
|
||||
|
||||
# Fix the home page titles
|
||||
if subpath == ''
|
||||
css('h1').each do |node|
|
||||
node.name = 'h2'
|
||||
end
|
||||
|
||||
# Add a main title before the first subtitle
|
||||
at_css('h2').before('<h1>Composer</h1>')
|
||||
end
|
||||
|
||||
# Code blocks
|
||||
css('pre').each do |node|
|
||||
code = node.at_css('code[class]')
|
||||
|
||||
unless code.nil?
|
||||
node['data-language'] = 'javascript' if code['class'].include?('javascript')
|
||||
node['data-language'] = 'php' if code['class'].include?('php')
|
||||
end
|
||||
|
||||
node.content = node.content.strip
|
||||
node.remove_attribute('class')
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,36 @@
|
||||
module Docs
|
||||
class Composer
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_name
|
||||
title = at_css('h1').content
|
||||
title = "#{Integer(subpath[1]) + 1}. #{title}" if type == 'Book'
|
||||
title
|
||||
end
|
||||
|
||||
def get_type
|
||||
return 'Articles' if subpath.start_with?('articles/')
|
||||
'Book'
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
entries = []
|
||||
|
||||
if subpath == '04-schema.md' # JSON Schema
|
||||
css('h3').each do |node|
|
||||
name = node.content.strip
|
||||
name.remove!(' (root-only)')
|
||||
entries << [name, node['id'], 'JSON Schema']
|
||||
end
|
||||
end
|
||||
|
||||
if subpath == '06-config.md' # Composer config
|
||||
css('h2').each do |node|
|
||||
entries << [node.content.strip, node['id'], 'Configuration Options']
|
||||
end
|
||||
end
|
||||
|
||||
entries
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Docs
|
||||
class Cypress
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
article_div = at_css('#article > div')
|
||||
@doc = article_div unless article_div.nil?
|
||||
|
||||
header = at_css('h1.article-title')
|
||||
doc.prepend_child(header) unless header.nil?
|
||||
|
||||
css('.article-edit-link').remove
|
||||
css('.article-footer').remove
|
||||
css('.article-footer-updated').remove
|
||||
|
||||
css('pre').each do |node|
|
||||
node.content = node.content
|
||||
node['data-language'] = 'javascript'
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Docs
|
||||
class Cypress
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
SECTIONS = %w[
|
||||
commands
|
||||
core-concepts
|
||||
cypress-api
|
||||
events
|
||||
getting-started
|
||||
guides
|
||||
overview
|
||||
plugins
|
||||
references
|
||||
utilities
|
||||
].freeze
|
||||
|
||||
def get_name
|
||||
at_css('h1.article-title').content.strip
|
||||
end
|
||||
|
||||
def get_type
|
||||
path = context[:url].path
|
||||
|
||||
SECTIONS.each do |section|
|
||||
if path.match?("/#{section}/")
|
||||
return section.split('-').map(&:capitalize).join(' ')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,27 @@
|
||||
module Docs
|
||||
class SaltStack
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
if root_page?
|
||||
doc.inner_html = '<h1>SaltStack</h1>'
|
||||
return doc
|
||||
end
|
||||
|
||||
css('.headerlink').remove
|
||||
|
||||
css('div[class^="highlight-"]').each do |node|
|
||||
node.name = 'pre'
|
||||
node['data-language'] = node['class'].scan(/highlight-([a-z]+)/i)[0][0]
|
||||
node.content = node.content.strip
|
||||
end
|
||||
|
||||
css('.function > dt').each do |node|
|
||||
node.name = 'h3'
|
||||
node.content = node.content
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,38 @@
|
||||
module Docs
|
||||
class SaltStack
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
SALT_REF_RGX = /salt\.([^\.]+)\.([^\s]+)/
|
||||
|
||||
def get_name
|
||||
header = at_css('h1').content
|
||||
|
||||
ref_match = SALT_REF_RGX.match(header)
|
||||
if ref_match
|
||||
ns, mod = ref_match.captures
|
||||
"#{ns}.#{mod}"
|
||||
else
|
||||
header
|
||||
end
|
||||
end
|
||||
|
||||
def get_type
|
||||
slug.split('/', 3)[1]
|
||||
end
|
||||
|
||||
def include_default_entry?
|
||||
slug.split('/').last.start_with? 'salt'
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
entries = []
|
||||
|
||||
css('.function > h3').each do |node|
|
||||
name = node.content.remove('salt.').split('(')[0] + '()'
|
||||
entries << [name, node['id']]
|
||||
end
|
||||
|
||||
entries
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,109 @@
|
||||
module Docs
|
||||
class Scala
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
@doc = at_css('#content')
|
||||
|
||||
always
|
||||
add_title
|
||||
|
||||
doc
|
||||
end
|
||||
|
||||
def always
|
||||
# Remove deprecated sections
|
||||
css('.members').each do |members|
|
||||
header = members.at_css('h3')
|
||||
members.remove if header.text.downcase.include? 'deprecate'
|
||||
end
|
||||
|
||||
css('#mbrsel, #footer').remove
|
||||
|
||||
css('.diagram-container').remove
|
||||
css('.toggleContainer > .toggle').each do |node|
|
||||
title = node.at_css('span')
|
||||
next if title.nil?
|
||||
|
||||
content = node.at_css('.hiddenContent')
|
||||
next if content.nil?
|
||||
|
||||
title.name = 'dt'
|
||||
|
||||
content.remove_attribute('class')
|
||||
content.remove_attribute('style')
|
||||
content.name = 'dd'
|
||||
|
||||
attributes = at_css('.attributes')
|
||||
unless attributes.nil?
|
||||
title.parent = attributes
|
||||
content.parent = attributes
|
||||
end
|
||||
end
|
||||
|
||||
signature = at_css('#signature')
|
||||
signature.replace "<h2 id=\"signature\">#{signature.inner_html}</h2>"
|
||||
|
||||
css('div.members > h3').each do |node|
|
||||
node.name = 'h2'
|
||||
end
|
||||
|
||||
css('div.members > ol').each do |list|
|
||||
list.css('li').each do |li|
|
||||
h3 = doc.document.create_element 'h3'
|
||||
h3['id'] = li['name'].rpartition('#').last unless li['name'].nil?
|
||||
|
||||
li.prepend_child h3
|
||||
li.css('.shortcomment').remove
|
||||
|
||||
modifier = li.at_css('.modifier_kind')
|
||||
modifier.parent = h3 unless modifier.nil?
|
||||
|
||||
kind = li.at_css('.modifier_kind .kind')
|
||||
kind.content = kind.content + ' ' unless kind.nil?
|
||||
|
||||
symbol = li.at_css('.symbol')
|
||||
symbol.parent = h3 unless symbol.nil?
|
||||
|
||||
li.swap li.children
|
||||
end
|
||||
|
||||
list.swap list.children
|
||||
end
|
||||
|
||||
css('.fullcomment pre, .fullcommenttop pre').each do |pre|
|
||||
pre['data-language'] = 'scala'
|
||||
pre.content = pre.content
|
||||
end
|
||||
|
||||
# Sections of the documentation which do not seem useful
|
||||
%w(#inheritedMembers #groupedMembers .permalink .hiddenContent .material-icons).each do |selector|
|
||||
css(selector).remove
|
||||
end
|
||||
|
||||
# Things that are not shown on the site, like deprecated members
|
||||
css('li[visbl=prt]').remove
|
||||
end
|
||||
|
||||
def add_title
|
||||
css('.permalink').remove
|
||||
|
||||
definition = at_css('#definition')
|
||||
return if definition.nil?
|
||||
|
||||
type_full_name = {a: 'Annotation', c: 'Class', t: 'Trait', o: 'Object', p: 'Package'}
|
||||
type = type_full_name[definition.at_css('.big-circle').text.to_sym]
|
||||
name = CGI.escapeHTML definition.at_css('h1').text
|
||||
|
||||
package = definition.at_css('#owner').text rescue ''
|
||||
package = package + '.' unless name.empty? || package.empty?
|
||||
|
||||
other = definition.at_css('.morelinks').dup
|
||||
other_content = other ? "<h3>#{other.to_html}</h3>" : ''
|
||||
|
||||
title_content = root_page? ? 'Package root' : "#{type} #{package}#{name}".strip
|
||||
title = "<h1>#{title_content}</h1>"
|
||||
definition.replace title + other_content
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,103 @@
|
||||
module Docs
|
||||
class Scala
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
REPLACEMENTS = {
|
||||
'$eq' => '=',
|
||||
'$colon' => ':',
|
||||
'$less' => '<',
|
||||
}
|
||||
|
||||
def get_name
|
||||
if is_package?
|
||||
symbol = at_css('#definition h1')
|
||||
symbol ? symbol.text.gsub(/\W+/, '') : "package"
|
||||
else
|
||||
name = slug.split('/').last
|
||||
|
||||
# Some objects have inner objects, show ParentObject$.ChildObject$ instead of ParentObject$$ChildObject$
|
||||
name = name.gsub('$$', '$.')
|
||||
|
||||
REPLACEMENTS.each do |key, value|
|
||||
name = name.gsub(key, value)
|
||||
end
|
||||
|
||||
# If a dollar sign is used as separator between two characters, replace it with a dot
|
||||
name.gsub(/([^$.])\$([^$.])/, '\1.\2')
|
||||
end
|
||||
end
|
||||
|
||||
def get_type
|
||||
# if this entry is for a package, we group the package under the parent package
|
||||
if is_package?
|
||||
parent_package
|
||||
# otherwise, group it under the regular package name
|
||||
else
|
||||
package_name
|
||||
end
|
||||
end
|
||||
|
||||
def include_default_entry?
|
||||
true
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
entries = []
|
||||
|
||||
full_name = "#{type}.#{name}".remove('$')
|
||||
css(".members li[name^=\"#{full_name}\"]").each do |node|
|
||||
# Ignore packages
|
||||
kind = node.at_css('.modifier_kind > .kind')
|
||||
next if !kind.nil? && kind.content == 'package'
|
||||
|
||||
# Ignore deprecated members
|
||||
next unless node.at_css('.symbol > .name.deprecated').nil?
|
||||
|
||||
id = node['name'].rpartition('#').last
|
||||
member_name = node.at_css('.name')
|
||||
|
||||
# Ignore members only existing of hashtags, we can't link to that
|
||||
next if member_name.nil? || member_name.content.strip.remove('#').blank?
|
||||
|
||||
member = "#{name}.#{member_name.content}()"
|
||||
entries << [member, id]
|
||||
end
|
||||
|
||||
entries
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# For the package name, we use the slug rather than parsing the package
|
||||
# name from the HTML because companion object classes may be broken out into
|
||||
# their own entries (by the source documentation). When that happens,
|
||||
# we want to group these classes (like `scala.reflect.api.Annotations.Annotation`)
|
||||
# under the package name, and not the fully-qualfied name which would
|
||||
# include the companion object.
|
||||
def package_name
|
||||
name = package_drop_last(slug_parts)
|
||||
name.empty? ? '_root_' : name
|
||||
end
|
||||
|
||||
def parent_package
|
||||
parent = package_drop_last(package_name.split('.'))
|
||||
parent.empty? ? '_root_' : parent
|
||||
end
|
||||
|
||||
def package_drop_last(parts)
|
||||
parts[0...-1].join('.')
|
||||
end
|
||||
|
||||
def slug_parts
|
||||
slug.split('/')
|
||||
end
|
||||
|
||||
def owner
|
||||
at_css('#owner')
|
||||
end
|
||||
|
||||
def is_package?
|
||||
slug.ends_with?('index') || slug.ends_with?('package')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
module Docs
|
||||
class VueRouter
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
@doc = at_css('.content')
|
||||
|
||||
# Remove unneeded elements
|
||||
css('.bit-sponsor, .header-anchor').remove
|
||||
|
||||
css('.custom-block').each do |node|
|
||||
node.name = 'blockquote'
|
||||
|
||||
title = node.at_css('.custom-block-title')
|
||||
title.name = 'strong' unless title.nil?
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,71 @@
|
||||
module Docs
|
||||
class VueRouter
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_name
|
||||
name = at_css('h1').content
|
||||
name.remove! '# '
|
||||
name
|
||||
end
|
||||
|
||||
def get_type
|
||||
return 'Other Guides' if subpath.start_with?('guide/advanced')
|
||||
return 'Basic Guides' if subpath.start_with?('guide') || subpath.start_with?('installation')
|
||||
'API Reference'
|
||||
end
|
||||
|
||||
def include_default_entry?
|
||||
name != 'API Reference'
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
return [] unless subpath.start_with?('api')
|
||||
|
||||
entries = [
|
||||
['<router-link>', 'router-link', 'API Reference'],
|
||||
['<router-view>', 'router-view', 'API Reference'],
|
||||
['$route', 'the-route-object', 'API Reference'],
|
||||
['Component Injections', 'component-injections', 'API Reference']
|
||||
]
|
||||
|
||||
css('h3').each do |node|
|
||||
entry_name = node.content.strip
|
||||
|
||||
# Get the previous h2 title
|
||||
title = node
|
||||
title = title.previous_element until title.name == 'h2'
|
||||
title = title.content.strip
|
||||
title.remove! '# '
|
||||
|
||||
entry_name.remove! '# '
|
||||
|
||||
case title
|
||||
when 'Router Construction Options'
|
||||
entry_name = "RouterOptions.#{entry_name}"
|
||||
when '<router-view> Props'
|
||||
entry_name = "<router-view> `#{entry_name}` prop"
|
||||
when '<router-link> Props'
|
||||
entry_name = "<router-link> `#{entry_name}` prop"
|
||||
when 'Router Instance Methods'
|
||||
entry_name = "#{entry_name}()"
|
||||
end
|
||||
|
||||
entry_name = entry_name.split(' API ')[0] if entry_name.start_with?('v-slot')
|
||||
|
||||
unless title == "Component Injections" || node['id'] == 'route-object-properties'
|
||||
entries << [entry_name, node['id'], 'API Reference']
|
||||
end
|
||||
end
|
||||
|
||||
css('#route-object-properties + ul > li > p:first-child > strong').each do |node|
|
||||
entry_name = node.content.strip
|
||||
id = "route-object-#{entry_name.remove('$route.')}"
|
||||
|
||||
node['id'] = id
|
||||
entries << [entry_name, node['id'], 'API Reference']
|
||||
end
|
||||
|
||||
entries
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,39 @@
|
||||
module Docs
|
||||
class Wordpress
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
if root_page?
|
||||
doc.inner_html = '<h1>WordPress</h1>'
|
||||
return doc
|
||||
end
|
||||
|
||||
article = at_css('article[id^="post-"]')
|
||||
@doc = at_css('article[id^="post-"]') unless article.nil?
|
||||
|
||||
css('hr', '.screen-reader-text', '.table-of-contents',
|
||||
'.anchor', '.toc-jump', '.source-code-links', '.user-notes',
|
||||
'.show-more', '.hide-more').remove
|
||||
|
||||
br = /<br\s?\/?>/i
|
||||
|
||||
header = at_css('h1')
|
||||
header.content = header.content.strip
|
||||
doc.prepend_child header
|
||||
|
||||
# Add PHP code highlighting
|
||||
css('pre').each do |node|
|
||||
node['data-language'] = 'php'
|
||||
end
|
||||
|
||||
css('.source-code-container').each do |node|
|
||||
node.name = 'pre'
|
||||
node.inner_html = node.inner_html.gsub(br, "\n")
|
||||
node.content = node.content.strip
|
||||
node['data-language'] = 'php'
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
module Docs
|
||||
class Wordpress
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_name
|
||||
at_css('.breadcrumbs .trail-end').content
|
||||
end
|
||||
|
||||
def get_type
|
||||
if subpath.starts_with?('classes')
|
||||
'Classes'
|
||||
elsif subpath.starts_with?('hooks')
|
||||
'Hooks'
|
||||
elsif subpath.starts_with?('functions')
|
||||
'Functions'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue