What if I don't update a documentation?
@@ -41,10 +41,15 @@ app.templates.offlinePage = (docs) -> """
"""
canICloseTheTab = ->
- if app.AppCache.isEnabled()
+ if app.ServiceWorker.isEnabled()
""" Yes! Even offline, you can open a new tab, go to devdocs.io , and everything will work as if you were online (provided you installed all the documentations you want to use beforehand). """
else
- """ No. AppCache isn't available in your browser (or is disabled), so loading devdocs.io offline won't work.
+ reason = "aren't available in your browser (or are disabled)"
+
+ if app.config.env != 'production'
+ reason = "are disabled in your development instance of DevDocs (enable them by setting the ENABLE_SERVICE_WORKER
environment variable to true
)"
+
+ """ No. Service Workers #{reason}, so loading devdocs.io offline won't work.
The current tab will continue to function even when you go offline (provided you installed all the documentations beforehand). """
app.templates.offlineDoc = (doc, status) ->
diff --git a/assets/javascripts/templates/pages/root_tmpl.coffee.erb b/assets/javascripts/templates/pages/root_tmpl.coffee.erb
index 7adce7fd..714e0e20 100644
--- a/assets/javascripts/templates/pages/root_tmpl.coffee.erb
+++ b/assets/javascripts/templates/pages/root_tmpl.coffee.erb
@@ -8,7 +8,7 @@ app.templates.intro = """
Thanks for downloading DevDocs. Here are a few things you should know:
Your local version of DevDocs won't self-update. Unless you're modifying the code,
- I recommend using the hosted version at devdocs.io .
+ we recommend using the hosted version at devdocs.io .
Run thor docs:list
to see all available documentations.
Run thor docs:download <name>
to download documentations.
Run thor docs:download --installed
to update all downloaded documentations.
@@ -39,7 +39,7 @@ app.templates.intro = """
DevDocs works offline , on mobile, and can be installed on Chrome .
For the latest news, follow @DevDocs .
DevDocs is free and open source .
-
+
And if you're new to coding, check out freeCodeCamp's open source curriculum .
Happy coding!
diff --git a/assets/javascripts/templates/pages/settings_tmpl.coffee b/assets/javascripts/templates/pages/settings_tmpl.coffee
index 1d439edb..94afe3df 100644
--- a/assets/javascripts/templates/pages/settings_tmpl.coffee
+++ b/assets/javascripts/templates/pages/settings_tmpl.coffee
@@ -15,6 +15,14 @@ app.templates.settingsPage = (settings) -> """
Automatically hide and show the sidebar
Tip: drag the edge of the sidebar to resize it.
+
+ Automatically download documentation for offline use
+ Only enable this when bandwidth isn't a concern to you.
+
+
+ Enable tracking cookies
+ With this checked, we enable Google Analytics and Gauges to collect anonymous traffic information.
+
diff --git a/assets/javascripts/tracking.js b/assets/javascripts/tracking.js
index ca05b218..a68ca493 100644
--- a/assets/javascripts/tracking.js
+++ b/assets/javascripts/tracking.js
@@ -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) { }
diff --git a/assets/javascripts/views/content/content.coffee b/assets/javascripts/views/content/content.coffee
index 8c5ba874..4e01733e 100644
--- a/assets/javascripts/views/content/content.coffee
+++ b/assets/javascripts/views/content/content.coffee
@@ -153,6 +153,9 @@ class app.views.Content extends app.View
return
afterRoute: (route, context) =>
+ if route != 'entry' and route != 'type'
+ resetFavicon()
+
switch route
when 'root'
@show @rootPage
diff --git a/assets/javascripts/views/content/entry_page.coffee b/assets/javascripts/views/content/entry_page.coffee
index beae4d77..f6f06511 100644
--- a/assets/javascripts/views/content/entry_page.coffee
+++ b/assets/javascripts/views/content/entry_page.coffee
@@ -40,6 +40,7 @@ class app.views.EntryPage extends app.View
if app.disabledDocs.findBy 'slug', @entry.doc.slug
@hiddenView = new app.views.HiddenPage @el, @entry
+ setFaviconForDoc(@entry.doc)
@delay @polyfillMathML
@trigger 'loaded'
return
@@ -123,7 +124,7 @@ class app.views.EntryPage extends app.View
@render @tmpl('pageLoadError')
@resetClass()
@addClass @constructor.errorClass
- app.appCache?.update()
+ app.serviceWorker?.update()
return
cache: ->
diff --git a/assets/javascripts/views/content/settings_page.coffee b/assets/javascripts/views/content/settings_page.coffee
index e39b17df..9ca606c6 100644
--- a/assets/javascripts/views/content/settings_page.coffee
+++ b/assets/javascripts/views/content/settings_page.coffee
@@ -1,7 +1,4 @@
class app.views.SettingsPage extends app.View
- LAYOUTS = ['_max-width', '_sidebar-hidden', '_native-scrollbars']
- SIDEBAR_HIDDEN_LAYOUT = '_sidebar-hidden'
-
@className: '_static'
@events:
@@ -17,31 +14,31 @@ class app.views.SettingsPage extends app.View
settings.dark = app.settings.get('dark')
settings.smoothScroll = !app.settings.get('fastScroll')
settings.arrowScroll = app.settings.get('arrowScroll')
- settings[layout] = app.settings.hasLayout(layout) for layout in LAYOUTS
+ settings.autoInstall = app.settings.get('autoInstall')
+ settings.analyticsConsent = app.settings.get('analyticsConsent')
+ settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS
settings
getTitle: ->
'Preferences'
toggleDark: (enable) ->
- html = document.documentElement
- html.classList.toggle('_theme-default')
- html.classList.toggle('_theme-dark')
app.settings.set('dark', !!enable)
- app.appCache?.updateInBackground()
return
toggleLayout: (layout, enable) ->
- document.body.classList[if enable then 'add' else 'remove'](layout) unless layout is SIDEBAR_HIDDEN_LAYOUT
- document.body.classList[if $.overlayScrollbarsEnabled() then 'add' else 'remove']('_overlay-scrollbars')
app.settings.setLayout(layout, enable)
- app.appCache?.updateInBackground()
return
toggleSmoothScroll: (enable) ->
app.settings.set('fastScroll', !enable)
return
+ toggleAnalyticsConsent: (enable) ->
+ app.settings.set('analyticsConsent', if enable then '1' else '0')
+ resetAnalytics() unless enable
+ return
+
toggle: (name, enable) ->
app.settings.set(name, enable)
return
@@ -85,6 +82,8 @@ class app.views.SettingsPage extends app.View
@toggleSmoothScroll input.checked
when 'import'
@import input.files[0], input
+ when 'analyticsConsent'
+ @toggleAnalyticsConsent input.checked
else
@toggle input.name, input.checked
return
diff --git a/assets/javascripts/views/content/type_page.coffee b/assets/javascripts/views/content/type_page.coffee
index 147fa7ed..ef360c14 100644
--- a/assets/javascripts/views/content/type_page.coffee
+++ b/assets/javascripts/views/content/type_page.coffee
@@ -9,6 +9,7 @@ class app.views.TypePage extends app.View
render: (@type) ->
@html @tmpl('typePage', @type)
+ setFaviconForDoc(@type.doc)
return
getTitle: ->
diff --git a/assets/javascripts/views/layout/document.coffee b/assets/javascripts/views/layout/document.coffee
index 02b98c7a..597dfe37 100644
--- a/assets/javascripts/views/layout/document.coffee
+++ b/assets/javascripts/views/layout/document.coffee
@@ -75,9 +75,11 @@ class app.views.Document extends app.View
return unless target.hasAttribute('data-behavior')
$.stopEvent(event)
switch target.getAttribute('data-behavior')
- when 'back' then history.back()
- when 'reload' then window.location.reload()
- when 'reboot' then app.reboot()
- when 'hard-reload' then app.reload()
- when 'reset' then app.reset() if confirm('Are you sure you want to reset DevDocs?')
+ when 'back' then history.back()
+ when 'reload' then window.location.reload()
+ when 'reboot' then app.reboot()
+ when 'hard-reload' then app.reload()
+ when 'reset' then app.reset() if confirm('Are you sure you want to reset DevDocs?')
+ when 'accept-analytics' then Cookies.set('analyticsConsent', '1') && app.reboot()
+ when 'decline-analytics' then Cookies.set('analyticsConsent', '0') && app.reboot()
return
diff --git a/assets/javascripts/views/layout/resizer.coffee b/assets/javascripts/views/layout/resizer.coffee
index 86bb46f5..5584bfbe 100644
--- a/assets/javascripts/views/layout/resizer.coffee
+++ b/assets/javascripts/views/layout/resizer.coffee
@@ -11,9 +11,6 @@ class app.views.Resizer extends app.View
init: ->
@el.setAttribute('draggable', 'true')
@appendTo $('._app')
-
- @style = $('style[data-resizer]')
- @size = @style.getAttribute('data-size')
return
MIN = 260
@@ -24,15 +21,11 @@ class app.views.Resizer extends app.View
return unless value > 0
value = Math.min(Math.max(Math.round(value), MIN), MAX)
newSize = "#{value}px"
- @style.innerHTML = @style.innerHTML.replace(new RegExp(@size, 'g'), newSize)
- @size = newSize
- if save
- app.settings.setSize(value)
- app.appCache?.updateInBackground()
+ document.documentElement.style.setProperty('--sidebarWidth', newSize)
+ app.settings.setSize(value) if save
return
onDragStart: (event) =>
- @style.removeAttribute('disabled')
event.dataTransfer.effectAllowed = 'link'
event.dataTransfer.setData('Text', '')
$.on(window, 'dragover', @onDrag)
diff --git a/assets/javascripts/views/layout/settings.coffee b/assets/javascripts/views/layout/settings.coffee
index 7888118a..6941b9cd 100644
--- a/assets/javascripts/views/layout/settings.coffee
+++ b/assets/javascripts/views/layout/settings.coffee
@@ -25,7 +25,6 @@ class app.views.Settings extends app.View
if super
@render()
document.body.classList.remove(SIDEBAR_HIDDEN_LAYOUT)
- app.appCache?.on 'progress', @onAppCacheProgress
return
deactivate: ->
@@ -33,7 +32,6 @@ class app.views.Settings extends app.View
@resetClass()
@docPicker.detach()
document.body.classList.add(SIDEBAR_HIDDEN_LAYOUT) if app.settings.hasLayout(SIDEBAR_HIDDEN_LAYOUT)
- app.appCache?.off 'progress', @onAppCacheProgress
return
render: ->
@@ -52,7 +50,7 @@ class app.views.Settings extends app.View
docs = @docPicker.getSelectedDocs()
app.settings.setDocs(docs)
- @saveBtn.textContent = if app.appCache then 'Downloading\u2026' else 'Saving\u2026'
+ @saveBtn.textContent = 'Saving\u2026'
disabledDocs = new app.collections.Docs(doc for doc in app.docs.all() when docs.indexOf(doc.slug) is -1)
disabledDocs.uninstall ->
app.db.migrate()
@@ -83,9 +81,3 @@ class app.views.Settings extends app.View
$.stopEvent(event)
app.router.show '/'
return
-
- onAppCacheProgress: (event) =>
- if event.lengthComputable
- percentage = Math.round event.loaded * 100 / event.total
- @saveBtn.textContent = "Downloading\u2026 (#{percentage}%)"
- return
diff --git a/assets/javascripts/views/search/search.coffee b/assets/javascripts/views/search/search.coffee
index 8fab885c..7d05f0a0 100644
--- a/assets/javascripts/views/search/search.coffee
+++ b/assets/javascripts/views/search/search.coffee
@@ -30,6 +30,9 @@ class app.views.Search extends app.View
.on 'results', @onResults
.on 'end', @onEnd
+ @scope
+ .on 'change', @onScopeChange
+
app.on 'ready', @onReady
$.on window, 'hashchange', @searchUrl
$.on window, 'focus', @onWindowFocus
@@ -138,6 +141,11 @@ class app.views.Search extends app.View
$.stopEvent(event)
return
+ onScopeChange: =>
+ @value = ''
+ @onInput()
+ return
+
afterRoute: (name, context) =>
return if app.shortcuts.eventInProgress?.name is 'escape'
@reset(true) if not context.init and app.router.isIndex()
diff --git a/assets/javascripts/views/search/search_scope.coffee b/assets/javascripts/views/search/search_scope.coffee
index 24de57ce..52ff753a 100644
--- a/assets/javascripts/views/search/search_scope.coffee
+++ b/assets/javascripts/views/search/search_scope.coffee
@@ -6,7 +6,9 @@ class app.views.SearchScope extends app.View
tag: '._search-tag'
@events:
+ click: 'onClick'
keydown: 'onKeydown'
+ textInput: 'onTextInput'
@routes:
after: 'afterRoute'
@@ -87,17 +89,33 @@ class app.views.SearchScope extends app.View
@trigger 'change', null, previousDoc
return
+ doScopeSearch: (event) =>
+ @search @input.value[0...@input.selectionStart]
+ $.stopEvent(event) if @doc
+ return
+
+ onClick: (event) =>
+ if event.target is @tag
+ @reset()
+ $.stopEvent(event)
+ return
+
onKeydown: (event) =>
if event.which is 8 # backspace
- if @doc and not @input.value
- $.stopEvent(event)
+ if @doc and @input.selectionEnd is 0
@reset()
- else if not @doc and @input.value
+ $.stopEvent(event)
+ else if not @doc and @input.value and not $.isChromeForAndroid()
return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
if event.which is 9 or # tab
(event.which is 32 and app.isMobile()) # space
- @search @input.value[0...@input.selectionStart]
- $.stopEvent(event) if @doc
+ @doScopeSearch(event)
+ return
+
+ onTextInput: (event) =>
+ return unless $.isChromeForAndroid()
+ if not @doc and @input.value and event.data == ' '
+ @doScopeSearch(event)
return
extractHashValue: ->
diff --git a/assets/javascripts/views/sidebar/sidebar.coffee b/assets/javascripts/views/sidebar/sidebar.coffee
index c8dc52a6..f3ae3bd4 100644
--- a/assets/javascripts/views/sidebar/sidebar.coffee
+++ b/assets/javascripts/views/sidebar/sidebar.coffee
@@ -28,7 +28,7 @@ class app.views.Sidebar extends app.View
app.on 'ready', @onReady
- $.on document.documentElement, 'mouseleave', (event) => @display() if event.clientX < 10
+ $.on document.documentElement, 'mouseleave', (event) => @display() unless event.clientX <= 0
$.on document.documentElement, 'mouseenter', => @resetDisplay(forceNoHover: false)
return
diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss
index 2a64e5c9..85d1134f 100644
--- a/assets/stylesheets/application.css.scss
+++ b/assets/stylesheets/application.css.scss
@@ -1,7 +1,6 @@
-//= depend_on docs-1.png
-//= depend_on docs-1@2x.png
-//= depend_on docs-2.png
-//= depend_on docs-2@2x.png
+//= depend_on sprites/docs.png
+//= depend_on sprites/docs@2x.png
+//= depend_on sprites/docs.json
/*!
* Copyright 2013-2019 Thibaut Courouble and other contributors
diff --git a/assets/stylesheets/components/_header.scss b/assets/stylesheets/components/_header.scss
index 5bae8901..e74830aa 100644
--- a/assets/stylesheets/components/_header.scss
+++ b/assets/stylesheets/components/_header.scss
@@ -215,5 +215,6 @@
color: var(--textColorLight);
background: var(--searchTagBackground);
border-radius: 2px;
+ cursor: pointer;
@extend %truncate-text;
}
diff --git a/assets/stylesheets/components/_notif.scss b/assets/stylesheets/components/_notif.scss
index dd23c43a..f0880fdd 100644
--- a/assets/stylesheets/components/_notif.scss
+++ b/assets/stylesheets/components/_notif.scss
@@ -134,3 +134,7 @@
._notif-info { color: var(--textColorLight); }
}
+
+._notif-right {
+ float: right;
+}
diff --git a/assets/stylesheets/global/_icons.scss b/assets/stylesheets/global/_icons.scss
deleted file mode 100644
index e7a805f4..00000000
--- a/assets/stylesheets/global/_icons.scss
+++ /dev/null
@@ -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; }
diff --git a/assets/stylesheets/global/_icons.scss.erb b/assets/stylesheets/global/_icons.scss.erb
new file mode 100644
index 00000000..b2b22c22
--- /dev/null
+++ b/assets/stylesheets/global/_icons.scss.erb
@@ -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('')
+ %>
diff --git a/docs/adding-docs.md b/docs/adding-docs.md
index 03c6b87a..9984a15c 100644
--- a/docs/adding-docs.md
+++ b/docs/adding-docs.md
@@ -1,6 +1,6 @@
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](https://github.com/Thibaut/devdocs/blob/master/.github/CONTRIBUTING.md) before submitting a new documentation.
+**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).
@@ -13,9 +13,11 @@ Adding a documentation may look like a daunting task but once you get the hang o
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). _(Note: feel free to submit a pull request without custom CSS/JS)_
+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. It'll be added to the icon sprite after your pull request is merged.
+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.)
diff --git a/docs/Filter-Reference.md b/docs/filter-reference.md
similarity index 100%
rename from docs/Filter-Reference.md
rename to docs/filter-reference.md
diff --git a/docs/maintainers.md b/docs/maintainers.md
index d994a0fd..da7e910e 100644
--- a/docs/maintainers.md
+++ b/docs/maintainers.md
@@ -4,7 +4,7 @@ This document is intended for [DevDocs maintainers](#list-of-maintainers).
## Merging pull requests
-- Unless the change is trivial or in an area that you are familiar with, PRs should be approved by at least two maintainers before being merged.
+- PRs should be approved by at least one maintainer before being merged.
- PRs that add or update documentations should always be merged locally, and the app deployed, before the merge is pushed to GitHub.
@@ -21,8 +21,7 @@ The process for updating docs is as follow:
- Commit the changes (protip: use the `thor docs:commit` command documented below).
- Optional: do more updates.
- Run `thor docs:upload` (documented below).
-- [Deploy the app](#deploying-devdocs) and verify that everything works in production.
-- Push to GitHub.
+- Push to GitHub to [deploy the app](#deploying-devdocs) and verify that everything works in production.
- Run `thor docs:clean` (documented below).
Note: changes to `public/docs/docs.json` should never be committed. This file reflects which documentations have been downloaded or generated locally, which is always none on a fresh `git clone`.
@@ -82,21 +81,22 @@ In addition to the [publicly-documented commands](https://github.com/freeCodeCam
## Deploying DevDocs
-Once docs have been uploaded via `thor docs:upload` (if applicable), deploying DevDocs is as simple as running `git push heroku master`. See [Heroku's documentation](https://devcenter.heroku.com/articles/git) for more information.
+Once docs have been uploaded via `thor docs:upload` (if applicable), you can push to the DevDocs master branch (or merge the PR containing the updates). If the Travis build succeeds, the Heroku application will be deployed automatically.
-- If you're deploying documentation updates, verify that the documentations work properly once the deploy is done (you will need to reload [devdocs.io](https://devdocs.io/) a couple times for the application cache to update and the new version to load).
+- If you're deploying documentation updates, verify that the documentations work properly once the deploy is done. Keep in mind that you'll need to wait a few seconds for the service worker to finish caching the new assets. You should see a "DevDocs has been updated" notification appear when the caching is done, after which you need to refresh the page to see the changes.
- If you're deploying frontend changes, monitor [Sentry](https://sentry.io/devdocs/devdocs-js/) for new JS errors once the deploy is done.
- If you're deploying server changes, monitor New Relic (accessible through [the Heroku dashboard](https://dashboard.heroku.com/apps/devdocs)) for Ruby exceptions and throughput or response time changes once the deploy is done.
-If any issue arises, run `heroku rollback` to rollback to the previous of the app (this can also be done via Heroku's UI). Note that this will not revert changes made to documentation files that were uploaded via `thor docs:upload`. Try and fix the issue as quickly as possible, then re-deploy the app. Reach out to other maintainers if you need help.
+If any issue arises, run `heroku rollback` to rollback to the previous version of the app (this can also be done via Heroku's UI). Note that this will not revert changes made to documentation files that were uploaded via `thor docs:upload`. Try and fix the issue as quickly as possible, then re-deploy the app. Reach out to other maintainers if you need help.
If this is your first deploy, make sure another maintainer is around to assist.
## List of maintainers
-- [Beau Carnes](https://github.com/beaucarnes)
- [Jed Fox](https://github.com/j-f1)
- [Jasper van Merle](https://github.com/jmerle)
+- [Ahmad Abdolsaheb](https://github.com/ahmadabdolsaheb)
+- [Mrugesh Mohapatra](https://github.com/raisedadead)
- [Thibaut Courouble](https://github.com/thibaut)
Interested in helping maintain DevDocs? Come talk to us on [Gitter](https://gitter.im/FreeCodeCamp/DevDocs) :)
diff --git a/docs/Scraper-Reference.md b/docs/scraper-reference.md
similarity index 86%
rename from docs/Scraper-Reference.md
rename to docs/scraper-reference.md
index d9fe8b4a..c2872388 100644
--- a/docs/Scraper-Reference.md
+++ b/docs/scraper-reference.md
@@ -184,3 +184,44 @@ More information about how filters work is available on the [Filter Reference](.
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)
diff --git a/lib/app.rb b/lib/app.rb
index 32cac31b..a1ace892 100644
--- a/lib/app.rb
+++ b/lib/app.rb
@@ -37,6 +37,9 @@ class App < Sinatra::Application
set :csp, false
+ require 'docs'
+ Docs.generate_manifest
+
Dir[docs_path, root.join(assets_prefix, '*/')].each do |path|
sprockets.append_path(path)
end
@@ -50,6 +53,11 @@ class App < Sinatra::Application
end
configure :test, :development do
+ require 'thor'
+ load 'tasks/sprites.thor'
+
+ SpritesCLI.new.invoke(:generate)
+
require 'active_support/per_thread_registry'
require 'active_support/cache'
sprockets.cache = ActiveSupport::Cache.lookup_store :file_store, root.join('tmp', 'cache', 'assets', environment.to_s)
@@ -192,35 +200,45 @@ class App < Sinatra::Application
request.query_string.empty? ? nil : "?#{request.query_string}"
end
- def manifest_asset_urls
- @@manifest_asset_urls ||= [
+ def service_worker_asset_urls
+ @@service_worker_asset_urls ||= [
javascript_path('application', asset_host: false),
stylesheet_path('application'),
- image_path('docs-1.png'),
- image_path('docs-1@2x.png'),
- image_path('docs-2.png'),
- image_path('docs-2@2x.png'),
- asset_path('docs.js')
- ]
+ image_path('sprites/docs.png'),
+ image_path('sprites/docs@2x.png'),
+ asset_path('docs.js'),
+ App.production? ? nil : javascript_path('debug'),
+ ].compact
end
- def app_size
- @app_size ||= memoized_cookies['size'].nil? ? '20rem' : "#{memoized_cookies['size']}px"
- end
+ # Returns a cache name for the service worker to use which changes if any of the assets changes
+ # When a manifest exist, this name is only created once based on the asset manifest because it never changes without a server restart
+ # If a manifest does not exist, it is created every time this method is called because the assets can change while the server is running
+ def service_worker_cache_name
+ if File.exist?(App.assets_manifest_path)
+ if defined?(@@service_worker_cache_name)
+ return @@service_worker_cache_name
+ end
- def app_layout
- memoized_cookies['layout']
- end
+ digest = Sprockets::Manifest
+ .new(nil, App.assets_manifest_path)
+ .files
+ .values
+ .map {|file| file["digest"]}
+ .join
- def app_theme
- @app_theme ||= memoized_cookies['dark'].nil? ? 'default' : 'dark'
- end
+ return @@service_worker_cache_name ||= Digest::MD5.hexdigest(digest)
+ else
+ paths = App.sprockets
+ .each_file
+ .to_a
+ .reject {|file| file.start_with?(App.docs_path)}
- def dark_theme?
- app_theme == 'dark'
+ return App.sprockets.pack_hexdigest(App.sprockets.files_digest(paths))
+ end
end
- def redirect_via_js(path) # courtesy of HTML5 App Cache
+ def redirect_via_js(path)
response.set_cookie :initial_path, value: path, expires: Time.now + 15, path: '/'
redirect '/', 302
end
@@ -243,15 +261,15 @@ class App < Sinatra::Application
end
end
- get '/manifest.appcache' do
- content_type 'text/cache-manifest'
+ get '/service-worker.js' do
+ content_type 'application/javascript'
expires 0, :'no-cache'
- erb :manifest
+ erb :'service-worker.js'
end
get '/' do
return redirect "/#q=#{params[:q]}" if params[:q]
- return redirect '/' unless request.query_string.empty? # courtesy of HTML5 App Cache
+ return redirect '/' unless request.query_string.empty?
response.headers['Content-Security-Policy'] = settings.csp if settings.csp
erb :index
end
diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb
index cb1cd209..da21daf8 100644
--- a/lib/docs/core/doc.rb
+++ b/lib/docs/core/doc.rb
@@ -152,7 +152,6 @@ module Docs
end
end
-
def initialize
raise NotImplementedError, "#{self.class} is an abstract class and cannot be instantiated." if self.class.abstract
end
@@ -164,5 +163,104 @@ module Docs
def build_pages(&block)
raise NotImplementedError
end
+
+ def get_scraper_version(opts)
+ if self.class.method_defined?(:options) and !options[:release].nil?
+ options[:release]
+ else
+ # If options[:release] does not exist, we return the Epoch timestamp of when the doc was last modified in DevDocs production
+ json = fetch_json('https://devdocs.io/docs.json', opts)
+ items = json.select {|item| item['name'] == self.class.name}
+ items = items.map {|item| item['mtime']}
+ items.max
+ end
+ end
+
+ # Should return the latest version of this documentation
+ # If options[:release] is defined, it should be in the same format
+ # If options[:release] is not defined, it should return the Epoch timestamp of when the documentation was last updated
+ # If the docs will never change, simply return '1.0.0'
+ def get_latest_version(opts)
+ raise NotImplementedError
+ end
+
+ # Returns whether or not this scraper is outdated.
+ #
+ # The default implementation assumes the documentation uses a semver(-like) approach when it comes to versions.
+ # Patch updates are ignored because there are usually little to no documentation changes in bug-fix-only releases.
+ #
+ # Scrapers of documentations that do not use this versioning approach should override this method.
+ #
+ # Examples of the default implementation:
+ # 1 -> 2 = outdated
+ # 1.1 -> 1.2 = outdated
+ # 1.1.1 -> 1.1.2 = not outdated
+ def is_outdated(scraper_version, latest_version)
+ scraper_parts = scraper_version.to_s.split(/\./).map(&:to_i)
+ latest_parts = latest_version.to_s.split(/\./).map(&:to_i)
+
+ # Only check the first two parts, the third part is for patch updates
+ [0, 1].each do |i|
+ break if i >= scraper_parts.length or i >= latest_parts.length
+ return true if latest_parts[i] > scraper_parts[i]
+ return false if latest_parts[i] < scraper_parts[i]
+ end
+
+ false
+ end
+
+ private
+
+ #
+ # Utility methods for get_latest_version
+ #
+
+ def fetch(url, opts)
+ headers = {}
+
+ if opts.key?(:github_token) and url.start_with?('https://api.github.com/')
+ headers['Authorization'] = "token #{opts[:github_token]}"
+ end
+
+ opts[:logger].debug("Fetching #{url}")
+ response = Request.run(url, { connecttimeout: 15, headers: headers })
+
+ if response.success?
+ response.body
+ else
+ reason = response.timed_out? ? "Timed out while connecting to #{url}" : "Couldn't fetch #{url} (response code #{response.code})"
+ opts[:logger].error(reason)
+ raise reason
+ end
+ end
+
+ def fetch_doc(url, opts)
+ body = fetch(url, opts)
+ Nokogiri::HTML.parse(body, nil, 'UTF-8')
+ end
+
+ def fetch_json(url, opts)
+ JSON.parse fetch(url, opts)
+ end
+
+ def get_npm_version(package, opts)
+ json = fetch_json("https://registry.npmjs.com/#{package}", opts)
+ json['dist-tags']['latest']
+ end
+
+ def get_latest_github_release(owner, repo, opts)
+ release = fetch_json("https://api.github.com/repos/#{owner}/#{repo}/releases/latest", opts)
+ tag_name = release['tag_name']
+ tag_name.start_with?('v') ? tag_name[1..-1] : tag_name
+ end
+
+ def get_github_tags(owner, repo, opts)
+ fetch_json("https://api.github.com/repos/#{owner}/#{repo}/tags", opts)
+ end
+
+ def get_github_file_contents(owner, repo, path, opts)
+ json = fetch_json("https://api.github.com/repos/#{owner}/#{repo}/contents/#{path}", opts)
+ Base64.decode64(json['content'])
+ end
end
end
diff --git a/lib/docs/core/scrapers/file_scraper.rb b/lib/docs/core/scrapers/file_scraper.rb
index 9d354631..72a99b99 100644
--- a/lib/docs/core/scrapers/file_scraper.rb
+++ b/lib/docs/core/scrapers/file_scraper.rb
@@ -29,7 +29,7 @@ module Docs
def request_one(url)
assert_source_directory_exists
- Response.new read_file(url_to_path(url)), URL.parse(url)
+ Response.new read_file(File.join(source_directory, url_to_path(url))), URL.parse(url)
end
def request_all(urls)
@@ -50,7 +50,7 @@ module Docs
end
def read_file(path)
- File.read(File.join(source_directory, path))
+ File.read(path)
rescue
instrument 'warn.doc', msg: "Failed to open file: #{path}"
nil
diff --git a/lib/docs/filters/elixir/clean_html.rb b/lib/docs/filters/elixir/clean_html.rb
index 7ff3a86a..cf703389 100644
--- a/lib/docs/filters/elixir/clean_html.rb
+++ b/lib/docs/filters/elixir/clean_html.rb
@@ -57,6 +57,11 @@ module Docs
node.parent.after(node)
end
+ css('.signature').each do |node|
+ non_text_children = node.xpath('node()[not(self::text())]')
+ non_text_children.to_a.reverse.each { |child| node.parent.add_next_sibling(child) }
+ end
+
css('pre').each do |node|
node['data-language'] = 'elixir'
node.content = node.content
diff --git a/lib/docs/scrapers/angular.rb b/lib/docs/scrapers/angular.rb
index c318ce25..3365ec67 100644
--- a/lib/docs/scrapers/angular.rb
+++ b/lib/docs/scrapers/angular.rb
@@ -155,6 +155,10 @@ module Docs
end
end
+ def get_latest_version(opts)
+ get_npm_version('@angular/core', opts)
+ end
+
private
def parse(response)
diff --git a/lib/docs/scrapers/angularjs.rb b/lib/docs/scrapers/angularjs.rb
index b8ff08b9..9d663e35 100644
--- a/lib/docs/scrapers/angularjs.rb
+++ b/lib/docs/scrapers/angularjs.rb
@@ -69,5 +69,9 @@ module Docs
self.release = '1.2.32'
self.base_url = "https://code.angularjs.org/#{release}/docs/partials/"
end
+
+ def get_latest_version(opts)
+ get_npm_version('angular', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/ansible.rb b/lib/docs/scrapers/ansible.rb
index 2d62909a..b2363d4d 100644
--- a/lib/docs/scrapers/ansible.rb
+++ b/lib/docs/scrapers/ansible.rb
@@ -87,5 +87,10 @@ module Docs
quickstart.html
list_of_all_modules.html)
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.ansible.com/ansible/latest/index.html', opts)
+ doc.at_css('.DocSiteProduct-CurrentVersion').content.strip
+ end
end
end
diff --git a/lib/docs/scrapers/apache.rb b/lib/docs/scrapers/apache.rb
index 9ee82f12..1301b574 100644
--- a/lib/docs/scrapers/apache.rb
+++ b/lib/docs/scrapers/apache.rb
@@ -33,5 +33,10 @@ module Docs
© 2018 The Apache Software Foundation
Licensed under the Apache License, Version 2.0.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://httpd.apache.org/docs/', opts)
+ doc.at_css('#apcontents > ul a')['href'][0...-1]
+ end
end
end
diff --git a/lib/docs/scrapers/apache_pig.rb b/lib/docs/scrapers/apache_pig.rb
index 65897a78..f35085e6 100644
--- a/lib/docs/scrapers/apache_pig.rb
+++ b/lib/docs/scrapers/apache_pig.rb
@@ -43,5 +43,10 @@ module Docs
self.base_url = "https://pig.apache.org/docs/r#{release}/"
end
+ def get_latest_version(opts)
+ doc = fetch_doc('https://pig.apache.org/', opts)
+ item = doc.at_css('div[id="menu_1.2"] > .menuitem:last-child')
+ item.content.strip.sub(/Release /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/async.rb b/lib/docs/scrapers/async.rb
index 40022f19..61615b54 100644
--- a/lib/docs/scrapers/async.rb
+++ b/lib/docs/scrapers/async.rb
@@ -17,5 +17,10 @@ module Docs
© 2010–2018 Caolan McMahon
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://caolan.github.io/async/v3/', opts)
+ doc.at_css('#version-dropdown > a').content.strip[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/babel.rb b/lib/docs/scrapers/babel.rb
index c9e40212..c8d716f1 100644
--- a/lib/docs/scrapers/babel.rb
+++ b/lib/docs/scrapers/babel.rb
@@ -22,5 +22,10 @@ module Docs
stub '' do
'
'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://babeljs.io/docs/en/', opts)
+ doc.at_css('a[href="/versions"] > h3').content
+ end
end
end
diff --git a/lib/docs/scrapers/backbone.rb b/lib/docs/scrapers/backbone.rb
index b72b1084..2b33505e 100644
--- a/lib/docs/scrapers/backbone.rb
+++ b/lib/docs/scrapers/backbone.rb
@@ -20,5 +20,10 @@ module Docs
© 2010–2016 Jeremy Ashkenas, DocumentCloud
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://backbonejs.org/', opts)
+ doc.at_css('.version').content[1...-1]
+ end
end
end
diff --git a/lib/docs/scrapers/bash.rb b/lib/docs/scrapers/bash.rb
index feb0ddce..ba4135ec 100644
--- a/lib/docs/scrapers/bash.rb
+++ b/lib/docs/scrapers/bash.rb
@@ -1,7 +1,7 @@
module Docs
class Bash < UrlScraper
self.type = 'bash'
- self.release = '4.4'
+ self.release = '5.0'
self.base_url = 'https://www.gnu.org/software/bash/manual'
self.root_path = '/html_node/index.html'
self.links = {
@@ -17,5 +17,10 @@ module Docs
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
Licensed under the GNU Free Documentation License.
HTML
+
+ def get_latest_version(opts)
+ body = fetch('https://www.gnu.org/software/bash/manual/html_node/index.html', opts)
+ body.scan(/, Version ([0-9.]+)/)[0][0][0...-1]
+ end
end
end
diff --git a/lib/docs/scrapers/bluebird.rb b/lib/docs/scrapers/bluebird.rb
index e5cd6b59..8f38120a 100644
--- a/lib/docs/scrapers/bluebird.rb
+++ b/lib/docs/scrapers/bluebird.rb
@@ -18,5 +18,9 @@ module Docs
© 2013–2017 Petka Antonov
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('bluebird', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/bootstrap.rb b/lib/docs/scrapers/bootstrap.rb
index 7b2406b8..8571462e 100644
--- a/lib/docs/scrapers/bootstrap.rb
+++ b/lib/docs/scrapers/bootstrap.rb
@@ -34,5 +34,10 @@ module Docs
options[:only] = %w(getting-started/ css/ components/ javascript/)
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://getbootstrap.com/', opts)
+ doc.at_css('#bd-versions').content.strip[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/bottle.rb b/lib/docs/scrapers/bottle.rb
index 25ad7f6e..d0397ec7 100644
--- a/lib/docs/scrapers/bottle.rb
+++ b/lib/docs/scrapers/bottle.rb
@@ -27,5 +27,11 @@ module Docs
self.release = '0.11.7'
self.base_url = "https://bottlepy.org/docs/#{self.version}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://bottlepy.org/docs/stable/', opts)
+ label = doc.at_css('.sphinxsidebarwrapper > ul > li > b')
+ label.content.sub(/Bottle /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/bower.rb b/lib/docs/scrapers/bower.rb
index b032f1d3..aab2a1e9 100644
--- a/lib/docs/scrapers/bower.rb
+++ b/lib/docs/scrapers/bower.rb
@@ -19,5 +19,9 @@ module Docs
© 2018 Bower contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('bower', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/c.rb b/lib/docs/scrapers/c.rb
index f9289617..ec99f704 100644
--- a/lib/docs/scrapers/c.rb
+++ b/lib/docs/scrapers/c.rb
@@ -26,6 +26,13 @@ module Docs
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
HTML
+ def get_latest_version(opts)
+ doc = fetch_doc('https://en.cppreference.com/w/Cppreference:Archives', opts)
+ link = doc.at_css('a[title^="File:"]')
+ date = link.content.scan(/(\d+)\./)[0][0]
+ DateTime.strptime(date, '%Y%m%d').to_time.to_i
+ end
+
private
def file_path_for(*)
diff --git a/lib/docs/scrapers/cakephp.rb b/lib/docs/scrapers/cakephp.rb
index 08dbead0..6291b4ab 100644
--- a/lib/docs/scrapers/cakephp.rb
+++ b/lib/docs/scrapers/cakephp.rb
@@ -71,6 +71,11 @@ module Docs
self.base_url = 'https://api.cakephp.org/2.7/'
end
+ def get_latest_version(opts)
+ doc = fetch_doc('https://api.cakephp.org/3.7/', opts)
+ doc.at_css('.version-picker .dropdown-toggle').content.strip
+ end
+
private
def parse(response)
diff --git a/lib/docs/scrapers/chai.rb b/lib/docs/scrapers/chai.rb
index 9d8aa4d2..759f7540 100644
--- a/lib/docs/scrapers/chai.rb
+++ b/lib/docs/scrapers/chai.rb
@@ -23,5 +23,9 @@ module Docs
© 2016 Chai.js Assertion Library
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('chai', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/chef.rb b/lib/docs/scrapers/chef.rb
index 2fd32a83..f0b7d6b0 100644
--- a/lib/docs/scrapers/chef.rb
+++ b/lib/docs/scrapers/chef.rb
@@ -47,5 +47,10 @@ module Docs
options[:only_patterns] = [/\A#{client_path}\//, /\A#{server_path}\//]
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://downloads.chef.io/chef', opts)
+ doc.at_css('h1.product-heading > span').content.strip
+ end
end
end
diff --git a/lib/docs/scrapers/clojure.rb b/lib/docs/scrapers/clojure.rb
index 6389f566..83147ad7 100644
--- a/lib/docs/scrapers/clojure.rb
+++ b/lib/docs/scrapers/clojure.rb
@@ -37,5 +37,10 @@ module Docs
self.release = '1.7 (legacy)'
self.base_url = 'https://clojure.github.io/clojure/branch-clojure-1.7.0/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://clojure.github.io/clojure/index.html', opts)
+ doc.at_css('#header-version').content[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/cmake.rb b/lib/docs/scrapers/cmake.rb
index c455e4fd..7548a4a9 100644
--- a/lib/docs/scrapers/cmake.rb
+++ b/lib/docs/scrapers/cmake.rb
@@ -59,5 +59,11 @@ module Docs
self.release = '3.5.2'
self.base_url = 'https://cmake.org/cmake/help/v3.5/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://cmake.org/documentation/', opts)
+ link = doc.at_css('.entry-content ul > li > strong > a > big')
+ link.content.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/codeception.rb b/lib/docs/scrapers/codeception.rb
index 919f146d..caafc9cf 100644
--- a/lib/docs/scrapers/codeception.rb
+++ b/lib/docs/scrapers/codeception.rb
@@ -18,5 +18,10 @@ module Docs
© 2011 Michael Bodnarchuk and contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://codeception.com/changelog', opts)
+ doc.at_css('#page > h4').content
+ end
end
end
diff --git a/lib/docs/scrapers/codeceptjs.rb b/lib/docs/scrapers/codeceptjs.rb
index 13189340..34d9b855 100644
--- a/lib/docs/scrapers/codeceptjs.rb
+++ b/lib/docs/scrapers/codeceptjs.rb
@@ -21,5 +21,9 @@ module Docs
© 2015 DavertMik <davert@codegyre.com> (http://codegyre.com)
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('codeceptjs', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/codeigniter.rb b/lib/docs/scrapers/codeigniter.rb
index 573f9b8c..05258d9a 100644
--- a/lib/docs/scrapers/codeigniter.rb
+++ b/lib/docs/scrapers/codeigniter.rb
@@ -38,5 +38,11 @@ module Docs
version '3' do
self.release = '3.1.8'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://codeigniter.com/user_guide/changelog.html', opts)
+ header = doc.at_css('#change-log h2')
+ header.content.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/coffeescript.rb b/lib/docs/scrapers/coffeescript.rb
index 23e9557f..695f3697 100644
--- a/lib/docs/scrapers/coffeescript.rb
+++ b/lib/docs/scrapers/coffeescript.rb
@@ -30,5 +30,9 @@ module Docs
options[:container] = '.container'
end
+
+ def get_latest_version(opts)
+ get_npm_version('coffeescript', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/cordova.rb b/lib/docs/scrapers/cordova.rb
index f74c72ff..65cf7f60 100644
--- a/lib/docs/scrapers/cordova.rb
+++ b/lib/docs/scrapers/cordova.rb
@@ -42,5 +42,15 @@ module Docs
self.release = '6.5.0'
self.base_url = 'https://cordova.apache.org/docs/en/6.x/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://cordova.apache.org/docs/en/latest/', opts)
+
+ label = doc.at_css('#versionDropdown').content.strip
+ version = label.scan(/([0-9.]+)/)[0][0]
+ version = version[0...-1] if version.end_with?('.')
+
+ version
+ end
end
end
diff --git a/lib/docs/scrapers/cpp.rb b/lib/docs/scrapers/cpp.rb
index 374f6883..f96ee8f1 100644
--- a/lib/docs/scrapers/cpp.rb
+++ b/lib/docs/scrapers/cpp.rb
@@ -34,6 +34,14 @@ module Docs
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
HTML
+ # Same as get_latest_version in lib/docs/scrapers/c.rb
+ def get_latest_version(opts)
+ doc = fetch_doc('https://en.cppreference.com/w/Cppreference:Archives', opts)
+ link = doc.at_css('a[title^="File:"]')
+ date = link.content.scan(/(\d+)\./)[0][0]
+ DateTime.strptime(date, '%Y%m%d').to_time.to_i
+ end
+
private
def file_path_for(*)
diff --git a/lib/docs/scrapers/crystal.rb b/lib/docs/scrapers/crystal.rb
index 29061a1d..14537c7f 100644
--- a/lib/docs/scrapers/crystal.rb
+++ b/lib/docs/scrapers/crystal.rb
@@ -34,5 +34,10 @@ module Docs
HTML
end
}
+
+ def get_latest_version(opts)
+ body = fetch('https://crystal-lang.org/api', opts)
+ body.scan(/Crystal Docs ([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/d.rb b/lib/docs/scrapers/d.rb
index 6126380e..e1475b45 100644
--- a/lib/docs/scrapers/d.rb
+++ b/lib/docs/scrapers/d.rb
@@ -26,5 +26,10 @@ module Docs
def initial_urls
%w(https://dlang.org/phobos/index.html https://dlang.org/spec/intro.html)
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://dlang.org/changelog/', opts)
+ doc.at_css('#content > ul > li:nth-child(2) > a')['id']
+ end
end
end
diff --git a/lib/docs/scrapers/d3.rb b/lib/docs/scrapers/d3.rb
index 26b27ca5..e26c1f3d 100644
--- a/lib/docs/scrapers/d3.rb
+++ b/lib/docs/scrapers/d3.rb
@@ -58,5 +58,9 @@ module Docs
options[:root_title] = 'D3.js'
options[:only_patterns] = [/\.md\z/]
end
+
+ def get_latest_version(opts)
+ get_npm_version('d3', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/dart.rb b/lib/docs/scrapers/dart.rb
index c345c22f..322bfe2a 100644
--- a/lib/docs/scrapers/dart.rb
+++ b/lib/docs/scrapers/dart.rb
@@ -31,5 +31,11 @@ module Docs
self.release = '1.24.3'
self.base_url = "https://api.dartlang.org/stable/#{release}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://api.dartlang.org/', opts)
+ label = doc.at_css('footer > span').content.strip
+ label.sub(/Dart /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/django.rb b/lib/docs/scrapers/django.rb
index 45273540..6d48c6d7 100644
--- a/lib/docs/scrapers/django.rb
+++ b/lib/docs/scrapers/django.rb
@@ -63,5 +63,10 @@ module Docs
self.release = '1.8.18'
self.base_url = 'https://docs.djangoproject.com/en/1.8/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.djangoproject.com/', opts)
+ doc.at_css('#doc-versions > li.current > span > strong').content
+ end
end
end
diff --git a/lib/docs/scrapers/docker.rb b/lib/docs/scrapers/docker.rb
index 92494f8a..3ef60aab 100644
--- a/lib/docs/scrapers/docker.rb
+++ b/lib/docs/scrapers/docker.rb
@@ -137,5 +137,11 @@ module Docs
options[:container] = '#docs'
options[:only_patterns] << /\Aswarm\//
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.docker.com/', opts)
+ label = doc.at_css('.nav-container button.dropdown-toggle').content.strip
+ label.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/dojo.rb b/lib/docs/scrapers/dojo.rb
index 937ed21a..79898916 100644
--- a/lib/docs/scrapers/dojo.rb
+++ b/lib/docs/scrapers/dojo.rb
@@ -36,6 +36,11 @@ module Docs
urls.map { |url| "#{url} " }.join
end
+ def get_latest_version(opts)
+ doc = fetch_doc('https://dojotoolkit.org/api/', opts)
+ doc.at_css('#versionSelector > option[selected]').content
+ end
+
private
def get_url_list(json, set = Set.new)
diff --git a/lib/docs/scrapers/drupal.rb b/lib/docs/scrapers/drupal.rb
index 5710eb36..3798caec 100644
--- a/lib/docs/scrapers/drupal.rb
+++ b/lib/docs/scrapers/drupal.rb
@@ -98,5 +98,10 @@ module Docs
/\A[\w\-\.]+\.php\/7\.x\z/
]
end
+
+ def get_latest_version(opts)
+ json = fetch_json('https://packagist.org/packages/drupal/drupal.json', opts)
+ json['package']['versions'].keys.find {|version| !version.end_with?('-dev')}
+ end
end
end
diff --git a/lib/docs/scrapers/electron.rb b/lib/docs/scrapers/electron.rb
index 3cb399f0..8e635f49 100644
--- a/lib/docs/scrapers/electron.rb
+++ b/lib/docs/scrapers/electron.rb
@@ -22,5 +22,10 @@ module Docs
© 2013–2018 GitHub Inc.
Licensed under the MIT license.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://electronjs.org/docs', opts)
+ doc.at_css('.docs-version').content
+ end
end
end
diff --git a/lib/docs/scrapers/elixir.rb b/lib/docs/scrapers/elixir.rb
index 10d5aac1..f3cc94b2 100644
--- a/lib/docs/scrapers/elixir.rb
+++ b/lib/docs/scrapers/elixir.rb
@@ -33,8 +33,34 @@ module Docs
"https://elixir-lang.org/getting-started/introduction.html" ]
end
+ version '1.9' do
+ self.release = '1.9.1'
+ self.base_urls = [
+ "https://hexdocs.pm/elixir/#{release}/",
+ "https://hexdocs.pm/eex/#{release}/",
+ "https://hexdocs.pm/ex_unit/#{release}/",
+ "https://hexdocs.pm/iex/#{release}/",
+ "https://hexdocs.pm/logger/#{release}/",
+ "https://hexdocs.pm/mix/#{release}/",
+ 'https://elixir-lang.org/getting-started/'
+ ]
+ end
+
+ version '1.8' do
+ self.release = '1.8.2'
+ self.base_urls = [
+ "https://hexdocs.pm/elixir/#{release}/",
+ "https://hexdocs.pm/eex/#{release}/",
+ "https://hexdocs.pm/ex_unit/#{release}/",
+ "https://hexdocs.pm/iex/#{release}/",
+ "https://hexdocs.pm/logger/#{release}/",
+ "https://hexdocs.pm/mix/#{release}/",
+ 'https://elixir-lang.org/getting-started/'
+ ]
+ end
+
version '1.7' do
- self.release = '1.7.3'
+ self.release = '1.7.4'
self.base_urls = [
"https://hexdocs.pm/elixir/#{release}/",
"https://hexdocs.pm/eex/#{release}/",
@@ -47,7 +73,7 @@ module Docs
end
version '1.6' do
- self.release = '1.6.5'
+ self.release = '1.6.6'
self.base_urls = [
"https://hexdocs.pm/elixir/#{release}/",
"https://hexdocs.pm/eex/#{release}/",
@@ -97,5 +123,10 @@ module Docs
'https://elixir-lang.org/getting-started/'
]
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://hexdocs.pm/elixir/api-reference.html', opts)
+ doc.at_css('h2.sidebar-projectVersion').content.strip[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/ember.rb b/lib/docs/scrapers/ember.rb
index 3db20c94..6f853bb9 100644
--- a/lib/docs/scrapers/ember.rb
+++ b/lib/docs/scrapers/ember.rb
@@ -56,5 +56,10 @@ module Docs
https://emberjs.com/api/ember-data/2.14/classes/DS
)
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://emberjs.com/api/ember/release', opts)
+ doc.at_css('.sidebar > .select-container .ember-power-select-selected-item').content.strip
+ end
end
end
diff --git a/lib/docs/scrapers/erlang.rb b/lib/docs/scrapers/erlang.rb
index d6aa2a0b..14a87cf5 100644
--- a/lib/docs/scrapers/erlang.rb
+++ b/lib/docs/scrapers/erlang.rb
@@ -55,5 +55,10 @@ module Docs
version '18' do
self.release = '18.3'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://www.erlang.org/downloads', opts)
+ doc.at_css('.col-lg-3 > ul > li').content.strip.sub(/OTP /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/eslint.rb b/lib/docs/scrapers/eslint.rb
index 8b4c9a2e..c213eacc 100644
--- a/lib/docs/scrapers/eslint.rb
+++ b/lib/docs/scrapers/eslint.rb
@@ -20,5 +20,9 @@ module Docs
© JS Foundation and other contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('eslint', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/express.rb b/lib/docs/scrapers/express.rb
index 0fb4ed14..990019fb 100644
--- a/lib/docs/scrapers/express.rb
+++ b/lib/docs/scrapers/express.rb
@@ -28,5 +28,9 @@ module Docs
© 2017 StrongLoop, IBM, and other expressjs.com contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v3.0.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('express', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/falcon.rb b/lib/docs/scrapers/falcon.rb
index 5bfd8efc..8ba69150 100644
--- a/lib/docs/scrapers/falcon.rb
+++ b/lib/docs/scrapers/falcon.rb
@@ -33,5 +33,10 @@ module Docs
self.release = '1.2.0'
self.base_url = "https://falcon.readthedocs.io/en/#{self.release}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://falcon.readthedocs.io/en/stable/changes/index.html', opts)
+ doc.at_css('#changelogs ul > li > a').content
+ end
end
end
diff --git a/lib/docs/scrapers/fish.rb b/lib/docs/scrapers/fish.rb
index 5ccfa71c..c9a98802 100644
--- a/lib/docs/scrapers/fish.rb
+++ b/lib/docs/scrapers/fish.rb
@@ -46,5 +46,10 @@ module Docs
self.release = '2.2.0'
self.base_url = "https://fishshell.com/docs/#{version}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://fishshell.com/docs/current/index.html', opts)
+ doc.at_css('#toc-index').content.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/flow.rb b/lib/docs/scrapers/flow.rb
index 16ea70dd..b3b5a02f 100644
--- a/lib/docs/scrapers/flow.rb
+++ b/lib/docs/scrapers/flow.rb
@@ -18,5 +18,9 @@ module Docs
© 2013–present Facebook Inc.
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('flow-bin', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/git.rb b/lib/docs/scrapers/git.rb
index 26b2da95..9de5cb0d 100644
--- a/lib/docs/scrapers/git.rb
+++ b/lib/docs/scrapers/git.rb
@@ -19,5 +19,10 @@ module Docs
© 2005–2018 Linus Torvalds and others
Licensed under the GNU General Public License version 2.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://git-scm.com/', opts)
+ doc.at_css('.version').content.strip
+ end
end
end
diff --git a/lib/docs/scrapers/gnu/gcc.rb b/lib/docs/scrapers/gnu/gcc.rb
index be3bb54e..565706d9 100644
--- a/lib/docs/scrapers/gnu/gcc.rb
+++ b/lib/docs/scrapers/gnu/gcc.rb
@@ -99,5 +99,11 @@ module Docs
options[:replace_paths] = CPP_PATHS
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://gcc.gnu.org/onlinedocs/', opts)
+ label = doc.at_css('ul > li > ul > li > a').content.strip
+ label.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/gnu/gnu_fortran.rb b/lib/docs/scrapers/gnu/gnu_fortran.rb
index 2610178e..dd18827c 100644
--- a/lib/docs/scrapers/gnu/gnu_fortran.rb
+++ b/lib/docs/scrapers/gnu/gnu_fortran.rb
@@ -25,5 +25,11 @@ module Docs
self.release = '4.9.3'
self.base_url = "https://gcc.gnu.org/onlinedocs/gcc-#{release}/gfortran/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://gcc.gnu.org/onlinedocs/', opts)
+ label = doc.at_css('ul > li > ul > li > a').content.strip
+ label.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/go.rb b/lib/docs/scrapers/go.rb
index 7b233317..27b46652 100644
--- a/lib/docs/scrapers/go.rb
+++ b/lib/docs/scrapers/go.rb
@@ -24,6 +24,11 @@ module Docs
Licensed under the Creative Commons Attribution License 3.0.
HTML
+ def get_latest_version(opts)
+ doc = fetch_doc('https://golang.org/project/', opts)
+ doc.at_css('#page ul > li > a').text[3..-1]
+ end
+
private
def parse(response) # Hook here because Nokogori removes whitespace from textareas
diff --git a/lib/docs/scrapers/godot.rb b/lib/docs/scrapers/godot.rb
index 7e7da9a6..06c330b2 100644
--- a/lib/docs/scrapers/godot.rb
+++ b/lib/docs/scrapers/godot.rb
@@ -37,5 +37,10 @@ module Docs
self.release = '2.1'
self.base_url = "http://docs.godotengine.org/en/#{self.version}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.godotengine.org/', opts)
+ doc.at_css('.version').content.strip
+ end
end
end
diff --git a/lib/docs/scrapers/graphite.rb b/lib/docs/scrapers/graphite.rb
index 49ade898..83e9314a 100644
--- a/lib/docs/scrapers/graphite.rb
+++ b/lib/docs/scrapers/graphite.rb
@@ -17,5 +17,10 @@ module Docs
© 2011–2016 The Graphite Project
Licensed under the Apache License, Version 2.0.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://graphite.readthedocs.io/en/latest/releases.html', opts)
+ doc.at_css('#release-notes li > a').content
+ end
end
end
diff --git a/lib/docs/scrapers/grunt.rb b/lib/docs/scrapers/grunt.rb
index 2201c043..469d10a0 100644
--- a/lib/docs/scrapers/grunt.rb
+++ b/lib/docs/scrapers/grunt.rb
@@ -26,5 +26,9 @@ module Docs
© GruntJS Team
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('grunt-cli', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/handlebars.rb b/lib/docs/scrapers/handlebars.rb
index 22935d21..046cdf0f 100644
--- a/lib/docs/scrapers/handlebars.rb
+++ b/lib/docs/scrapers/handlebars.rb
@@ -19,5 +19,9 @@ module Docs
© 2011–2017 by Yehuda Katz
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('handlebars', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/haskell.rb b/lib/docs/scrapers/haskell.rb
index 442339b3..fb118851 100755
--- a/lib/docs/scrapers/haskell.rb
+++ b/lib/docs/scrapers/haskell.rb
@@ -10,7 +10,7 @@ module Docs
html_filters.push 'haskell/entries', 'haskell/clean_html'
- options[:container] = ->(filter) { filter.subpath.start_with?('users_guide') ? '.body' : '#content' }
+ options[:container] = ->(filter) {filter.subpath.start_with?('users_guide') ? '.body' : '#content'}
options[:only_patterns] = [/\Alibraries\//, /\Ausers_guide\//]
options[:skip_patterns] = [
@@ -68,5 +68,12 @@ module Docs
options[:only_patterns] = [/\Alibraries\//]
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://downloads.haskell.org/~ghc/latest/docs/html/', opts)
+ links = doc.css('a').to_a
+ versions = links.map {|link| link['href'].scan(/ghc-([0-9.]+)/)}
+ versions.find {|version| !version.empty?}[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/haxe.rb b/lib/docs/scrapers/haxe.rb
index 33f20b93..2dbab01a 100644
--- a/lib/docs/scrapers/haxe.rb
+++ b/lib/docs/scrapers/haxe.rb
@@ -66,5 +66,11 @@ module Docs
version 'Python' do
self.base_url = 'https://api.haxe.org/python/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://api.haxe.org/', opts)
+ label = doc.at_css('.container.main-content h1 > small').content
+ label.sub(/version /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/homebrew.rb b/lib/docs/scrapers/homebrew.rb
index fba79ec0..9dd1581a 100644
--- a/lib/docs/scrapers/homebrew.rb
+++ b/lib/docs/scrapers/homebrew.rb
@@ -19,5 +19,9 @@ module Docs
© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('Homebrew', 'brew', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/http.rb b/lib/docs/scrapers/http.rb
index 60f15f75..90e6f5c1 100644
--- a/lib/docs/scrapers/http.rb
+++ b/lib/docs/scrapers/http.rb
@@ -7,6 +7,8 @@ module Docs
html_filters.push 'http/clean_html', 'http/entries', 'title'
+ options[:mdn_tag] = 'HTTP'
+
options[:root_title] = 'HTTP'
options[:title] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? false : filter.default_title }
options[:container] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? '.content' : nil }
diff --git a/lib/docs/scrapers/immutable.rb b/lib/docs/scrapers/immutable.rb
index fa7fb81b..8b1b47a2 100644
--- a/lib/docs/scrapers/immutable.rb
+++ b/lib/docs/scrapers/immutable.rb
@@ -54,5 +54,9 @@ module Docs
JS
capybara.html
end
+
+ def get_latest_version(opts)
+ get_npm_version('immutable', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/influxdata.rb b/lib/docs/scrapers/influxdata.rb
index 6c83b66b..db160f9c 100644
--- a/lib/docs/scrapers/influxdata.rb
+++ b/lib/docs/scrapers/influxdata.rb
@@ -46,5 +46,11 @@ module Docs
© 2015 InfluxData, Inc.
Licensed under the MIT license.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.influxdata.com/influxdb/', opts)
+ label = doc.at_css('.navbar--current-product').content.strip
+ label.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/jasmine.rb b/lib/docs/scrapers/jasmine.rb
index 82f3c9cf..b1971ecd 100644
--- a/lib/docs/scrapers/jasmine.rb
+++ b/lib/docs/scrapers/jasmine.rb
@@ -17,5 +17,9 @@ module Docs
© 2008–2017 Pivotal Labs
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('jasmine', 'jasmine', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/jekyll.rb b/lib/docs/scrapers/jekyll.rb
index 1faaa9de..500eee10 100644
--- a/lib/docs/scrapers/jekyll.rb
+++ b/lib/docs/scrapers/jekyll.rb
@@ -28,5 +28,10 @@ module Docs
© 2008–2018 Tom Preston-Werner and Jekyll contributors
Licensed under the MIT license.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://jekyllrb.com/docs/', opts)
+ doc.at_css('.meta a').content[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/jest.rb b/lib/docs/scrapers/jest.rb
index f4ce944f..a495d939 100644
--- a/lib/docs/scrapers/jest.rb
+++ b/lib/docs/scrapers/jest.rb
@@ -17,5 +17,10 @@ module Docs
© 2014–present Facebook Inc.
Licensed under the BSD License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://jestjs.io/docs/en/getting-started', opts)
+ doc.at_css('header > a > h3').content
+ end
end
end
diff --git a/lib/docs/scrapers/jquery/jquery_core.rb b/lib/docs/scrapers/jquery/jquery_core.rb
index 20aca0dc..a0c8b97a 100644
--- a/lib/docs/scrapers/jquery/jquery_core.rb
+++ b/lib/docs/scrapers/jquery/jquery_core.rb
@@ -22,5 +22,9 @@ module Docs
/Selectors\/odd/i,
/index/i
]
+
+ def get_latest_version(opts)
+ get_npm_version('jquery', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/jquery/jquery_mobile.rb b/lib/docs/scrapers/jquery/jquery_mobile.rb
index 8e5abf1c..5b856a95 100644
--- a/lib/docs/scrapers/jquery/jquery_mobile.rb
+++ b/lib/docs/scrapers/jquery/jquery_mobile.rb
@@ -16,5 +16,10 @@ module Docs
options[:fix_urls] = ->(url) do
url.sub! 'http://api.jquerymobile.com/', 'https://api.jquerymobile.com/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://jquerymobile.com/', opts)
+ doc.at_css('.download-box > .download-option:last-child > span').content.sub(/Version /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/jquery/jquery_ui.rb b/lib/docs/scrapers/jquery/jquery_ui.rb
index 0c90fc1a..021d1d22 100644
--- a/lib/docs/scrapers/jquery/jquery_ui.rb
+++ b/lib/docs/scrapers/jquery/jquery_ui.rb
@@ -15,5 +15,9 @@ module Docs
options[:fix_urls] = ->(url) do
url.sub! 'http://api.jqueryui.com/', 'https://api.jqueryui.com/'
end
+
+ def get_latest_version(opts)
+ get_npm_version('jquery-ui', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/jsdoc.rb b/lib/docs/scrapers/jsdoc.rb
index bb3781ca..df27e578 100644
--- a/lib/docs/scrapers/jsdoc.rb
+++ b/lib/docs/scrapers/jsdoc.rb
@@ -21,5 +21,9 @@ module Docs
© 2011–2017 the contributors to the JSDoc 3 documentation project
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('jsdoc3', 'jsdoc', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/julia.rb b/lib/docs/scrapers/julia.rb
index 5bc16b77..c9c96da6 100644
--- a/lib/docs/scrapers/julia.rb
+++ b/lib/docs/scrapers/julia.rb
@@ -49,5 +49,9 @@ module Docs
html_filters.push 'julia/entries_sphinx', 'julia/clean_html_sphinx', 'sphinx/clean_html'
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('JuliaLang', 'julia', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/knockout.rb b/lib/docs/scrapers/knockout.rb
index 663f7847..efad86f0 100644
--- a/lib/docs/scrapers/knockout.rb
+++ b/lib/docs/scrapers/knockout.rb
@@ -33,5 +33,9 @@ module Docs
© Steven Sanderson, the Knockout.js team, and other contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('knockout', 'knockout', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/koa.rb b/lib/docs/scrapers/koa.rb
index 3ce79cac..cac14920 100644
--- a/lib/docs/scrapers/koa.rb
+++ b/lib/docs/scrapers/koa.rb
@@ -34,5 +34,9 @@ module Docs
© 2018 Koa contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('koa', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/kotlin.rb b/lib/docs/scrapers/kotlin.rb
index 415393d1..5055b65e 100644
--- a/lib/docs/scrapers/kotlin.rb
+++ b/lib/docs/scrapers/kotlin.rb
@@ -28,5 +28,9 @@ module Docs
© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('JetBrains', 'kotlin', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/laravel.rb b/lib/docs/scrapers/laravel.rb
index 5c88ae0f..e45b0bed 100644
--- a/lib/docs/scrapers/laravel.rb
+++ b/lib/docs/scrapers/laravel.rb
@@ -133,5 +133,9 @@ module Docs
url
end
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('laravel', 'laravel', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/leaflet.rb b/lib/docs/scrapers/leaflet.rb
index c8e2071c..38e497e7 100644
--- a/lib/docs/scrapers/leaflet.rb
+++ b/lib/docs/scrapers/leaflet.rb
@@ -39,5 +39,10 @@ module Docs
self.base_url = "https://leafletjs.com/reference-#{release}.html"
end
+ def get_latest_version(opts)
+ doc = fetch_doc('https://leafletjs.com/index.html', opts)
+ link = doc.css('ul > li > a').to_a.select {|node| node.content == 'Docs'}.first
+ link['href'].scan(/reference-([0-9.]+)\.html/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/less.rb b/lib/docs/scrapers/less.rb
index a0947e1a..b19bbe17 100644
--- a/lib/docs/scrapers/less.rb
+++ b/lib/docs/scrapers/less.rb
@@ -21,5 +21,11 @@ module Docs
© 2009–2016 The Core Less Team
Licensed under the Creative Commons Attribution License 3.0.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://lesscss.org/features/', opts)
+ label = doc.at_css('.footer-links > li').content
+ label.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/liquid.rb b/lib/docs/scrapers/liquid.rb
index 9ebc4041..b8e40d59 100644
--- a/lib/docs/scrapers/liquid.rb
+++ b/lib/docs/scrapers/liquid.rb
@@ -19,5 +19,10 @@ module Docs
© 2005, 2006 Tobias Luetke
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ tags = get_github_tags('Shopify', 'liquid', opts)
+ tags[0]['name'][1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/lodash.rb b/lib/docs/scrapers/lodash.rb
index 0461f7b7..bce625e6 100644
--- a/lib/docs/scrapers/lodash.rb
+++ b/lib/docs/scrapers/lodash.rb
@@ -32,5 +32,10 @@ module Docs
self.release = '2.4.2'
self.base_url = "https://lodash.com/docs/#{release}"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://lodash.com/docs/', opts)
+ doc.at_css('#version > option[selected]').content
+ end
end
end
diff --git a/lib/docs/scrapers/love.rb b/lib/docs/scrapers/love.rb
index 7f23bded..887b796f 100644
--- a/lib/docs/scrapers/love.rb
+++ b/lib/docs/scrapers/love.rb
@@ -39,5 +39,10 @@ module Docs
© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://love2d.org/wiki/Version_History', opts)
+ doc.at_css('#mw-content-text table a').content
+ end
end
end
diff --git a/lib/docs/scrapers/lua.rb b/lib/docs/scrapers/lua.rb
index 40a5c007..e3608918 100644
--- a/lib/docs/scrapers/lua.rb
+++ b/lib/docs/scrapers/lua.rb
@@ -26,5 +26,10 @@ module Docs
self.release = '5.1.5'
self.base_url = 'https://www.lua.org/manual/5.1/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://www.lua.org/manual/', opts)
+ doc.at_css('p.menubar > a').content
+ end
end
end
diff --git a/lib/docs/scrapers/marionette.rb b/lib/docs/scrapers/marionette.rb
index fea6617f..fd1eab8e 100644
--- a/lib/docs/scrapers/marionette.rb
+++ b/lib/docs/scrapers/marionette.rb
@@ -38,5 +38,9 @@ module Docs
html_filters.push 'marionette/entries_v2'
end
+
+ def get_latest_version(opts)
+ get_npm_version('backbone.marionette', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/markdown.rb b/lib/docs/scrapers/markdown.rb
index 87e9c957..b837c692 100644
--- a/lib/docs/scrapers/markdown.rb
+++ b/lib/docs/scrapers/markdown.rb
@@ -13,5 +13,9 @@ module Docs
© 2004 John Gruber
Licensed under the BSD License.
HTML
+
+ def get_latest_version(opts)
+ '1.0.0'
+ end
end
end
diff --git a/lib/docs/scrapers/matplotlib.rb b/lib/docs/scrapers/matplotlib.rb
index ddd1f9de..eeecea71 100644
--- a/lib/docs/scrapers/matplotlib.rb
+++ b/lib/docs/scrapers/matplotlib.rb
@@ -64,5 +64,9 @@ module Docs
"https://matplotlib.org/#{release}/mpl_toolkits/axes_grid/api/"
]
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('matplotlib', 'matplotlib', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/mdn/css.rb b/lib/docs/scrapers/mdn/css.rb
index 4c44f1f1..abb69b3a 100644
--- a/lib/docs/scrapers/mdn/css.rb
+++ b/lib/docs/scrapers/mdn/css.rb
@@ -6,6 +6,8 @@ module Docs
html_filters.push 'css/clean_html', 'css/entries', 'title'
+ options[:mdn_tag] = 'CSS'
+
options[:root_title] = 'CSS'
options[:skip] = %w(/CSS3 /Media/Visual /paged_media /Media/TV /Media/Tactile)
diff --git a/lib/docs/scrapers/mdn/dom.rb b/lib/docs/scrapers/mdn/dom.rb
index bbf95b20..a2202929 100644
--- a/lib/docs/scrapers/mdn/dom.rb
+++ b/lib/docs/scrapers/mdn/dom.rb
@@ -8,6 +8,8 @@ module Docs
html_filters.push 'dom/clean_html', 'dom/entries', 'title'
+ options[:mdn_tag] = 'XSLT_Reference'
+
options[:root_title] = 'DOM'
options[:skip] = %w(
diff --git a/lib/docs/scrapers/mdn/dom_events.rb b/lib/docs/scrapers/mdn/dom_events.rb
index fcbdc08f..258fbcd4 100644
--- a/lib/docs/scrapers/mdn/dom_events.rb
+++ b/lib/docs/scrapers/mdn/dom_events.rb
@@ -9,6 +9,8 @@ module Docs
html_filters.insert_after 'clean_html', 'dom_events/clean_html'
html_filters.push 'dom_events/entries', 'title'
+ options[:mdn_tag] = 'events'
+
options[:root_title] = 'DOM Events'
options[:skip] = %w(/MozOrientation)
diff --git a/lib/docs/scrapers/mdn/html.rb b/lib/docs/scrapers/mdn/html.rb
index 4b28cefd..f38432f1 100644
--- a/lib/docs/scrapers/mdn/html.rb
+++ b/lib/docs/scrapers/mdn/html.rb
@@ -7,6 +7,8 @@ module Docs
html_filters.push 'html/clean_html', 'html/entries', 'title'
+ options[:mdn_tag] = 'HTML'
+
options[:root_title] = 'HTML'
options[:title] = ->(filter) do
diff --git a/lib/docs/scrapers/mdn/javascript.rb b/lib/docs/scrapers/mdn/javascript.rb
index 935df61c..cea55fc8 100644
--- a/lib/docs/scrapers/mdn/javascript.rb
+++ b/lib/docs/scrapers/mdn/javascript.rb
@@ -8,6 +8,8 @@ module Docs
html_filters.push 'javascript/clean_html', 'javascript/entries', 'title'
+ options[:mdn_tag] = 'JavaScript'
+
options[:root_title] = 'JavaScript'
# Don't want
diff --git a/lib/docs/scrapers/mdn/mdn.rb b/lib/docs/scrapers/mdn/mdn.rb
index 2ebd38aa..defb4533 100644
--- a/lib/docs/scrapers/mdn/mdn.rb
+++ b/lib/docs/scrapers/mdn/mdn.rb
@@ -21,6 +21,11 @@ module Docs
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
HTML
+ def get_latest_version(opts)
+ json = fetch_json("https://developer.mozilla.org/en-US/docs/feeds/json/tag/#{options[:mdn_tag]}", opts)
+ DateTime.parse(json[0]['pubdate']).to_time.to_i
+ end
+
private
def process_response?(response)
diff --git a/lib/docs/scrapers/mdn/svg.rb b/lib/docs/scrapers/mdn/svg.rb
index db9de7a1..66baf60d 100644
--- a/lib/docs/scrapers/mdn/svg.rb
+++ b/lib/docs/scrapers/mdn/svg.rb
@@ -8,6 +8,8 @@ module Docs
html_filters.push 'svg/clean_html', 'svg/entries', 'title'
+ options[:mdn_tag] = 'XSLT_Reference'
+
options[:root_title] = 'SVG'
options[:title] = ->(filter) do
diff --git a/lib/docs/scrapers/mdn/xslt_xpath.rb b/lib/docs/scrapers/mdn/xslt_xpath.rb
index 5d812dd4..9bf01c01 100644
--- a/lib/docs/scrapers/mdn/xslt_xpath.rb
+++ b/lib/docs/scrapers/mdn/xslt_xpath.rb
@@ -8,6 +8,8 @@ module Docs
html_filters.push 'xslt_xpath/clean_html', 'xslt_xpath/entries', 'title'
+ options[:mdn_tag] = 'XSLT_Reference'
+
options[:root_title] = 'XSLT'
options[:only_patterns] = [/\A\/XSLT/, /\A\/XPath/]
diff --git a/lib/docs/scrapers/meteor.rb b/lib/docs/scrapers/meteor.rb
index b38d5dc2..a758d154 100644
--- a/lib/docs/scrapers/meteor.rb
+++ b/lib/docs/scrapers/meteor.rb
@@ -45,5 +45,10 @@ module Docs
self.base_urls = ['https://guide.meteor.com/v1.3/', "https://docs.meteor.com/v#{self.release}/"]
options[:fix_urls] = nil
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.meteor.com/#/full/', opts)
+ doc.at_css('select.version-select > option').content
+ end
end
end
diff --git a/lib/docs/scrapers/mocha.rb b/lib/docs/scrapers/mocha.rb
index 8ab9bdc8..04945425 100644
--- a/lib/docs/scrapers/mocha.rb
+++ b/lib/docs/scrapers/mocha.rb
@@ -18,5 +18,9 @@ module Docs
© 2011–2018 JS Foundation and contributors
Licensed under the Creative Commons Attribution 4.0 International License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('mocha', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/modernizr.rb b/lib/docs/scrapers/modernizr.rb
index 96c82153..01ad49a7 100644
--- a/lib/docs/scrapers/modernizr.rb
+++ b/lib/docs/scrapers/modernizr.rb
@@ -15,5 +15,9 @@ module Docs
© 2009–2017 The Modernizr team
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('modernizr', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/moment.rb b/lib/docs/scrapers/moment.rb
index 88df0d14..5b7491ea 100644
--- a/lib/docs/scrapers/moment.rb
+++ b/lib/docs/scrapers/moment.rb
@@ -22,5 +22,10 @@ module Docs
© JS Foundation and other contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://momentjs.com/', opts)
+ doc.at_css('.hero-title > h1 > span').content
+ end
end
end
diff --git a/lib/docs/scrapers/mongoose.rb b/lib/docs/scrapers/mongoose.rb
index 71ee04d2..fbd4ca92 100644
--- a/lib/docs/scrapers/mongoose.rb
+++ b/lib/docs/scrapers/mongoose.rb
@@ -26,5 +26,11 @@ module Docs
© 2010 LearnBoost
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://mongoosejs.com/docs/', opts)
+ label = doc.at_css('.pure-menu-link').content.strip
+ label.sub(/Version /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/nginx.rb b/lib/docs/scrapers/nginx.rb
index 5a3dbf1e..5354b8bd 100644
--- a/lib/docs/scrapers/nginx.rb
+++ b/lib/docs/scrapers/nginx.rb
@@ -25,5 +25,11 @@ module Docs
© 2011-2018 Nginx, Inc.
Licensed under the BSD License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://nginx.org/en/download.html', opts)
+ table = doc.at_css('#content > table').inner_html
+ table.scan(/nginx-([0-9.]+))[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/nginx_lua_module.rb b/lib/docs/scrapers/nginx_lua_module.rb
index f4943f62..9fcbab00 100644
--- a/lib/docs/scrapers/nginx_lua_module.rb
+++ b/lib/docs/scrapers/nginx_lua_module.rb
@@ -4,6 +4,9 @@ module Docs
self.slug = 'nginx_lua_module'
self.release = '0.10.13'
self.base_url = "https://github.com/openresty/lua-nginx-module/tree/v#{self.release}/"
+ self.links = {
+ code: 'https://github.com/openresty/lua-nginx-module'
+ }
html_filters.push 'nginx_lua_module/clean_html', 'nginx_lua_module/entries', 'title'
@@ -15,5 +18,11 @@ module Docs
© 2009–2018 Yichun "agentzh" Zhang (章亦春), OpenResty Inc.
Licensed under the BSD License.
HTML
+
+ def get_latest_version(opts)
+ tags = get_github_tags('openresty', 'lua-nginx-module', opts)
+ tag = tags.find {|tag| !tag['name'].include?('rc')}
+ tag['name'][1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/nim.rb b/lib/docs/scrapers/nim.rb
index cce16f1c..a927605d 100644
--- a/lib/docs/scrapers/nim.rb
+++ b/lib/docs/scrapers/nim.rb
@@ -17,5 +17,10 @@ module Docs
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://nim-lang.org/docs/overview.html', opts)
+ doc.at_css('.container > .docinfo > tbody > tr:last-child > td').content.strip
+ end
end
end
diff --git a/lib/docs/scrapers/node.rb b/lib/docs/scrapers/node.rb
index 66c6a456..0e5ee8fa 100644
--- a/lib/docs/scrapers/node.rb
+++ b/lib/docs/scrapers/node.rb
@@ -46,5 +46,10 @@ module Docs
self.release = '4.9.1'
self.base_url = 'https://nodejs.org/dist/latest-v4.x/docs/api/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://nodejs.org/en/', opts)
+ doc.at_css('#home-intro > .home-downloadblock:last-of-type > a')['data-version'][1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/nokogiri2.rb b/lib/docs/scrapers/nokogiri2.rb
index 084ad2fb..7c28ca92 100644
--- a/lib/docs/scrapers/nokogiri2.rb
+++ b/lib/docs/scrapers/nokogiri2.rb
@@ -19,5 +19,9 @@ module Docs
Patrick Mahoney, Yoko Harada, Akinori Musha, John Shahid, Lars Kanis
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('sparklemotion', 'nokogiri', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/npm.rb b/lib/docs/scrapers/npm.rb
index 2c854e6e..3f868a3c 100644
--- a/lib/docs/scrapers/npm.rb
+++ b/lib/docs/scrapers/npm.rb
@@ -29,5 +29,9 @@ module Docs
Licensed under the npm License.
npm is a trademark of npm, Inc.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('npm', 'cli', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/numpy.rb b/lib/docs/scrapers/numpy.rb
index 1327fc02..84de6cab 100644
--- a/lib/docs/scrapers/numpy.rb
+++ b/lib/docs/scrapers/numpy.rb
@@ -49,5 +49,9 @@ module Docs
self.release = '1.10.4'
self.base_url = "https://docs.scipy.org/doc/numpy-#{self.release}/reference/"
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('numpy', 'numpy', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/openjdk.rb b/lib/docs/scrapers/openjdk.rb
index 944ac416..c26bce4c 100644
--- a/lib/docs/scrapers/openjdk.rb
+++ b/lib/docs/scrapers/openjdk.rb
@@ -86,5 +86,25 @@ module Docs
def read_file(path)
File.read(path).force_encoding('iso-8859-1').encode('utf-8') rescue nil
end
+
+ def get_latest_version(opts)
+ latest_version = 8
+ current_attempt = latest_version
+ attempts = 0
+
+ while attempts < 3
+ current_attempt += 1
+
+ doc = fetch_doc("https://packages.debian.org/sid/openjdk-#{current_attempt}-doc", opts)
+ if doc.at_css('.perror').nil?
+ latest_version = current_attempt
+ attempts = 0
+ else
+ attempts += 1
+ end
+ end
+
+ latest_version
+ end
end
end
diff --git a/lib/docs/scrapers/opentsdb.rb b/lib/docs/scrapers/opentsdb.rb
index 0372e331..6eec407c 100644
--- a/lib/docs/scrapers/opentsdb.rb
+++ b/lib/docs/scrapers/opentsdb.rb
@@ -18,5 +18,9 @@ module Docs
© 2010–2016 The OpenTSDB Authors
Licensed under the GNU LGPLv2.1+ and GPLv3+ licenses.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('OpenTSDB', 'opentsdb', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/padrino.rb b/lib/docs/scrapers/padrino.rb
index 218f1731..d34b7db5 100644
--- a/lib/docs/scrapers/padrino.rb
+++ b/lib/docs/scrapers/padrino.rb
@@ -23,5 +23,9 @@ module Docs
stub 'index2' do
request_one(url_for('index')).body
end
+
+ def get_latest_version(opts)
+ get_github_tags('padrino', 'padrino-framework', opts)[0]['name']
+ end
end
end
diff --git a/lib/docs/scrapers/pandas.rb b/lib/docs/scrapers/pandas.rb
index 1355a012..a8c2ea51 100644
--- a/lib/docs/scrapers/pandas.rb
+++ b/lib/docs/scrapers/pandas.rb
@@ -49,5 +49,11 @@ module Docs
self.release = '0.18.1'
self.base_url = "http://pandas.pydata.org/pandas-docs/version/#{self.release}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://pandas.pydata.org/pandas-docs/stable/', opts)
+ label = doc.at_css('.body > .section > p').content
+ label.scan(/Version: ([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/perl.rb b/lib/docs/scrapers/perl.rb
index 142ceaa5..ebf0a653 100644
--- a/lib/docs/scrapers/perl.rb
+++ b/lib/docs/scrapers/perl.rb
@@ -43,5 +43,11 @@ module Docs
self.release = '5.20.2'
self.base_url = "https://perldoc.perl.org/#{self.release}/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://perldoc.perl.org/', opts)
+ header = doc.at_css('h2.h1').content
+ header.scan(/Perl ([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/phalcon.rb b/lib/docs/scrapers/phalcon.rb
index c2cb9242..c6ca63f2 100644
--- a/lib/docs/scrapers/phalcon.rb
+++ b/lib/docs/scrapers/phalcon.rb
@@ -29,5 +29,10 @@ module Docs
self.release = '2.0.13'
self.base_url = 'https://docs.phalconphp.com/en/2.0.0/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.phalconphp.com/', opts)
+ doc.at_css('.header__lang.expand > div > ul > li > a').content
+ end
end
end
diff --git a/lib/docs/scrapers/phaser.rb b/lib/docs/scrapers/phaser.rb
index 5ae371c1..bd5f411c 100644
--- a/lib/docs/scrapers/phaser.rb
+++ b/lib/docs/scrapers/phaser.rb
@@ -25,5 +25,9 @@ module Docs
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('photonstorm', 'phaser', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/phoenix.rb b/lib/docs/scrapers/phoenix.rb
index 26b0144f..2ad053e2 100644
--- a/lib/docs/scrapers/phoenix.rb
+++ b/lib/docs/scrapers/phoenix.rb
@@ -46,5 +46,10 @@ module Docs
HTML
end
}
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://hexdocs.pm/phoenix/Phoenix.html', opts)
+ doc.at_css('.sidebar-projectVersion').content.strip[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/php.rb b/lib/docs/scrapers/php.rb
index d4a66b5b..181d8b67 100644
--- a/lib/docs/scrapers/php.rb
+++ b/lib/docs/scrapers/php.rb
@@ -66,5 +66,11 @@ module Docs
© 1997–2018 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://secure.php.net/manual/en/doc.changelog.php', opts)
+ label = doc.at_css('tbody.gen-changelog > tr > td').content
+ label.split(',').last.strip
+ end
end
end
diff --git a/lib/docs/scrapers/phpunit.rb b/lib/docs/scrapers/phpunit.rb
index 665ca4c7..5f2cbfea 100644
--- a/lib/docs/scrapers/phpunit.rb
+++ b/lib/docs/scrapers/phpunit.rb
@@ -37,5 +37,11 @@ module Docs
self.release = '4.8'
self.base_url = "https://phpunit.de/manual/#{release}/en/"
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://phpunit.readthedocs.io/', opts)
+ label = doc.at_css('.rst-current-version').content.strip
+ label.scan(/v: ([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/postgresql.rb b/lib/docs/scrapers/postgresql.rb
index 109685ba..cc7a85c8 100644
--- a/lib/docs/scrapers/postgresql.rb
+++ b/lib/docs/scrapers/postgresql.rb
@@ -80,5 +80,11 @@ module Docs
html_filters.insert_before 'postgresql/extract_metadata', 'postgresql/normalize_class_names'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://www.postgresql.org/docs/current/index.html', opts)
+ label = doc.at_css('#pgContentWrap h1.title').content
+ label.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/pug.rb b/lib/docs/scrapers/pug.rb
index 76949529..79a1b0a8 100644
--- a/lib/docs/scrapers/pug.rb
+++ b/lib/docs/scrapers/pug.rb
@@ -18,6 +18,10 @@ module Docs
Licensed under the MIT license.
HTML
+ def get_latest_version(opts)
+ get_npm_version('pug', opts)
+ end
+
private
def parse(response) # Hook here because Nokogori removes whitespace from textareas
diff --git a/lib/docs/scrapers/puppeteer.rb b/lib/docs/scrapers/puppeteer.rb
index 2e26c180..043380d5 100644
--- a/lib/docs/scrapers/puppeteer.rb
+++ b/lib/docs/scrapers/puppeteer.rb
@@ -14,5 +14,10 @@ module Docs
© 2017 Google Inc
Licensed under the Apache License 2.0.
HTML
+
+ def get_latest_version(opts)
+ contents = get_github_file_contents('GoogleChrome', 'puppeteer', 'README.md', opts)
+ contents.scan(/\/v([0-9.]+)\/docs\/api\.md/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/pygame.rb b/lib/docs/scrapers/pygame.rb
index 9da3148d..94c3d508 100644
--- a/lib/docs/scrapers/pygame.rb
+++ b/lib/docs/scrapers/pygame.rb
@@ -2,6 +2,7 @@ module Docs
class Pygame < UrlScraper
self.type = 'simple'
self.release = '1.9.4'
+ self.base_url = 'https://www.pygame.org/docs/'
self.root_path = 'py-modindex.html'
self.links = {
home: 'https://www.pygame.org/',
@@ -16,5 +17,9 @@ module Docs
© Pygame Developpers.
Licensed under the GNU LGPL License version 2.1.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('pygame', 'pygame', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/python.rb b/lib/docs/scrapers/python.rb
index aa4336d9..c7905591 100644
--- a/lib/docs/scrapers/python.rb
+++ b/lib/docs/scrapers/python.rb
@@ -50,5 +50,10 @@ module Docs
html_filters.push 'python/entries_v2', 'sphinx/clean_html', 'python/clean_html'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://docs.python.org/', opts)
+ doc.at_css('.version_switcher_placeholder').content
+ end
end
end
diff --git a/lib/docs/scrapers/q.rb b/lib/docs/scrapers/q.rb
index bb66c156..a4c449c0 100644
--- a/lib/docs/scrapers/q.rb
+++ b/lib/docs/scrapers/q.rb
@@ -19,5 +19,9 @@ module Docs
© 2009–2017 Kristopher Michael Kowal
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('q', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/qt.rb b/lib/docs/scrapers/qt.rb
index 412eca6d..a1098b20 100644
--- a/lib/docs/scrapers/qt.rb
+++ b/lib/docs/scrapers/qt.rb
@@ -117,5 +117,10 @@ module Docs
self.release = '5.6'
self.base_url = 'https://doc.qt.io/qt-5.6/'
end
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://doc.qt.io/qt-5/index.html', opts)
+ doc.at_css('.mainContent h1.title').content.sub(/Qt /, '')
+ end
end
end
diff --git a/lib/docs/scrapers/ramda.rb b/lib/docs/scrapers/ramda.rb
index 09ff46c8..0b86e365 100644
--- a/lib/docs/scrapers/ramda.rb
+++ b/lib/docs/scrapers/ramda.rb
@@ -15,6 +15,11 @@ module Docs
© 2013–2016 Scott Sauyet and Michael Hurley
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://ramdajs.com/docs/', opts)
+ doc.at_css('.navbar-brand > .version').content[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/rdoc/minitest.rb b/lib/docs/scrapers/rdoc/minitest.rb
index 761da1de..2a4249fc 100644
--- a/lib/docs/scrapers/rdoc/minitest.rb
+++ b/lib/docs/scrapers/rdoc/minitest.rb
@@ -21,5 +21,10 @@ module Docs
© Ryan Davis, seattle.rb
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ contents = get_github_file_contents('seattlerb', 'minitest', 'History.rdoc', opts)
+ contents.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/rdoc/rails.rb b/lib/docs/scrapers/rdoc/rails.rb
index 6bdce34a..0dec42a9 100644
--- a/lib/docs/scrapers/rdoc/rails.rb
+++ b/lib/docs/scrapers/rdoc/rails.rb
@@ -93,5 +93,9 @@ module Docs
version '4.1' do
self.release = '4.1.16'
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('rails', 'rails', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/rdoc/ruby.rb b/lib/docs/scrapers/rdoc/ruby.rb
index dd296765..bc064660 100644
--- a/lib/docs/scrapers/rdoc/ruby.rb
+++ b/lib/docs/scrapers/rdoc/ruby.rb
@@ -84,5 +84,16 @@ module Docs
version '2.2' do
self.release = '2.2.10'
end
+
+ def get_latest_version(opts)
+ tags = get_github_tags('ruby', 'ruby', opts)
+ tags.each do |tag|
+ version = tag['name'].gsub(/_/, '.')[1..-1]
+
+ if !/^([0-9.]+)$/.match(version).nil? && version.count('.') == 2
+ return version
+ end
+ end
+ end
end
end
diff --git a/lib/docs/scrapers/react.rb b/lib/docs/scrapers/react.rb
index 704f3189..3c41ea5a 100644
--- a/lib/docs/scrapers/react.rb
+++ b/lib/docs/scrapers/react.rb
@@ -30,5 +30,10 @@ module Docs
© 2013–present Facebook Inc.
Licensed under the Creative Commons Attribution 4.0 International Public License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://reactjs.org/docs/getting-started.html', opts)
+ doc.at_css('a[href="/versions"]').content.strip[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/react_native.rb b/lib/docs/scrapers/react_native.rb
index d1f94001..fe87e492 100644
--- a/lib/docs/scrapers/react_native.rb
+++ b/lib/docs/scrapers/react_native.rb
@@ -30,5 +30,10 @@ module Docs
© 2015–2018 Facebook Inc.
Licensed under the Creative Commons Attribution 4.0 International Public License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://facebook.github.io/react-native/docs/getting-started.html', opts)
+ doc.at_css('header > a > h3').content
+ end
end
end
diff --git a/lib/docs/scrapers/redis.rb b/lib/docs/scrapers/redis.rb
index 201dbb47..81440a82 100644
--- a/lib/docs/scrapers/redis.rb
+++ b/lib/docs/scrapers/redis.rb
@@ -19,5 +19,11 @@ module Docs
© 2009–2018 Salvatore Sanfilippo
Licensed under the Creative Commons Attribution-ShareAlike License 4.0.
HTML
+
+ def get_latest_version(opts)
+ body = fetch('http://download.redis.io/redis-stable/00-RELEASENOTES', opts)
+ body = body.lines[1..-1].join
+ body.scan(/Redis ([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/redux.rb b/lib/docs/scrapers/redux.rb
index cd7369ba..14f8e8b4 100644
--- a/lib/docs/scrapers/redux.rb
+++ b/lib/docs/scrapers/redux.rb
@@ -20,5 +20,9 @@ module Docs
stub '' do
request_one('http://redux.js.org/index.html').body
end
+
+ def get_latest_version(opts)
+ get_npm_version('redux', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/relay.rb b/lib/docs/scrapers/relay.rb
index a020e9d7..807d6e1d 100644
--- a/lib/docs/scrapers/relay.rb
+++ b/lib/docs/scrapers/relay.rb
@@ -18,5 +18,10 @@ module Docs
© 2013–present Facebook Inc.
Licensed under the BSD License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('http://facebook.github.io/relay/en/', opts)
+ doc.at_css('header > a > h3').content[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/requirejs.rb b/lib/docs/scrapers/requirejs.rb
index 200f1f2d..80ecc722 100644
--- a/lib/docs/scrapers/requirejs.rb
+++ b/lib/docs/scrapers/requirejs.rb
@@ -30,5 +30,9 @@ module Docs
© jQuery Foundation and other contributors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('requirejs', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/rethinkdb.rb b/lib/docs/scrapers/rethinkdb.rb
index 023bbe77..35d8d334 100644
--- a/lib/docs/scrapers/rethinkdb.rb
+++ b/lib/docs/scrapers/rethinkdb.rb
@@ -58,6 +58,10 @@ module Docs
CODE
end
+ def get_latest_version(opts)
+ get_latest_github_release('rethinkdb', 'rethinkdb', opts)
+ end
+
private
def process_response?(response)
diff --git a/lib/docs/scrapers/rust.rb b/lib/docs/scrapers/rust.rb
index 1677e138..635afc1c 100644
--- a/lib/docs/scrapers/rust.rb
+++ b/lib/docs/scrapers/rust.rb
@@ -39,6 +39,12 @@ module Docs
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
HTML
+ def get_latest_version(opts)
+ doc = fetch_doc('https://www.rust-lang.org/', opts)
+ label = doc.at_css('.button-download + p > a').content
+ label.sub(/Version /, '')
+ end
+
private
REDIRECT_RGX = /http-equiv="refresh"/i
diff --git a/lib/docs/scrapers/sass.rb b/lib/docs/scrapers/sass.rb
index 244a88e7..c9774cdf 100644
--- a/lib/docs/scrapers/sass.rb
+++ b/lib/docs/scrapers/sass.rb
@@ -23,5 +23,9 @@ module Docs
© 2006–2016 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('sass', 'libsass', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/scikit_image.rb b/lib/docs/scrapers/scikit_image.rb
index 2a60aaec..a5959581 100644
--- a/lib/docs/scrapers/scikit_image.rb
+++ b/lib/docs/scrapers/scikit_image.rb
@@ -20,5 +20,10 @@ module Docs
© 2011 the scikit-image team
Licensed under the BSD 3-clause License.
HTML
+
+ def get_latest_version(opts)
+ tags = get_github_tags('scikit-image', 'scikit-image', opts)
+ tags[0]['name'][1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/scikit_learn.rb b/lib/docs/scrapers/scikit_learn.rb
index fe6a8665..973c9d7e 100644
--- a/lib/docs/scrapers/scikit_learn.rb
+++ b/lib/docs/scrapers/scikit_learn.rb
@@ -25,5 +25,9 @@ module Docs
Licensed under the 3-clause BSD License.
HTML
+ def get_latest_version(opts)
+ doc = fetch_doc('https://scikit-learn.org/stable/documentation.html', opts)
+ doc.at_css('.body h1').content.scan(/([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/sinon.rb b/lib/docs/scrapers/sinon.rb
index 9e81cba9..632348dc 100644
--- a/lib/docs/scrapers/sinon.rb
+++ b/lib/docs/scrapers/sinon.rb
@@ -52,5 +52,10 @@ module Docs
self.release = '1.17.7'
self.base_url = "https://sinonjs.org/releases/v#{release}/"
end
+
+ def get_latest_version(opts)
+ body = fetch('https://sinonjs.org/', opts)
+ body.scan(/\/releases\/v([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/socketio.rb b/lib/docs/scrapers/socketio.rb
index 427098c4..e9bc264a 100644
--- a/lib/docs/scrapers/socketio.rb
+++ b/lib/docs/scrapers/socketio.rb
@@ -20,5 +20,9 @@ module Docs
© 2014–2015 Automattic
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ get_npm_version('socket.io', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/sqlite.rb b/lib/docs/scrapers/sqlite.rb
index 790acf83..d3a5fa6b 100644
--- a/lib/docs/scrapers/sqlite.rb
+++ b/lib/docs/scrapers/sqlite.rb
@@ -41,6 +41,11 @@ module Docs
options[:attribution] = 'SQLite is in the Public Domain.'
+ def get_latest_version(opts)
+ doc = fetch_doc('https://sqlite.org/chronology.html', opts)
+ doc.at_css('#chrontab > tbody > tr > td:last-child > a').content
+ end
+
private
def parse(response)
diff --git a/lib/docs/scrapers/statsmodels.rb b/lib/docs/scrapers/statsmodels.rb
index 255bde6c..3e8a357c 100644
--- a/lib/docs/scrapers/statsmodels.rb
+++ b/lib/docs/scrapers/statsmodels.rb
@@ -21,5 +21,9 @@ module Docs
Licensed under the 3-clause BSD License.
HTML
+ def get_latest_version(opts)
+ doc = fetch_doc('http://www.statsmodels.org/stable/', opts)
+ doc.at_css('.sphinxsidebarwrapper h3 + p > b').content[1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/support_tables.rb b/lib/docs/scrapers/support_tables.rb
index 9a550c1e..d04072da 100644
--- a/lib/docs/scrapers/support_tables.rb
+++ b/lib/docs/scrapers/support_tables.rb
@@ -178,5 +178,11 @@ module Docs
HTML
+
+ def get_latest_version(opts)
+ body = fetch('https://feeds.feedburner.com/WhenCanIUse?format=xml', opts)
+ timestamp = body.scan(/([^<]+)<\/updated>/)[0][0]
+ DateTime.parse(timestamp).to_time.to_i
+ end
end
end
diff --git a/lib/docs/scrapers/symfony.rb b/lib/docs/scrapers/symfony.rb
index f5e4285a..4bdde054 100644
--- a/lib/docs/scrapers/symfony.rb
+++ b/lib/docs/scrapers/symfony.rb
@@ -70,5 +70,9 @@ module Docs
self.release = '2.7.35'
self.base_url = "https://api.symfony.com/#{version}/"
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('symfony', 'symfony', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/tcl_tk.rb b/lib/docs/scrapers/tcl_tk.rb
index 1e4b2567..bca840c6 100644
--- a/lib/docs/scrapers/tcl_tk.rb
+++ b/lib/docs/scrapers/tcl_tk.rb
@@ -25,5 +25,10 @@ module Docs
options[:attribution] = <<-HTML
Licensed under Tcl/Tk terms
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://www.tcl.tk/man/tcl/contents.htm', opts)
+ doc.at_css('h2').content.scan(/Tk([0-9.]+)/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/tensorflow.rb b/lib/docs/scrapers/tensorflow.rb
index 0296299f..9638b516 100644
--- a/lib/docs/scrapers/tensorflow.rb
+++ b/lib/docs/scrapers/tensorflow.rb
@@ -56,6 +56,10 @@ module Docs
/\Aextend/]
end
+ def get_latest_version(opts)
+ get_latest_github_release('tensorflow', 'tensorflow', opts)
+ end
+
private
def parse(response)
diff --git a/lib/docs/scrapers/terraform.rb b/lib/docs/scrapers/terraform.rb
index ab12775d..0965ad06 100644
--- a/lib/docs/scrapers/terraform.rb
+++ b/lib/docs/scrapers/terraform.rb
@@ -18,5 +18,10 @@ module Docs
© 2018 HashiCorp
Licensed under the MPL 2.0 License.
HTML
+
+ def get_latest_version(opts)
+ contents = get_github_file_contents('hashicorp', 'terraform-website', 'content/config.rb', opts)
+ contents.scan(/version\s+=\s+"([0-9.]+)"/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/twig.rb b/lib/docs/scrapers/twig.rb
index 4781dcb2..e52ff6bd 100755
--- a/lib/docs/scrapers/twig.rb
+++ b/lib/docs/scrapers/twig.rb
@@ -28,5 +28,10 @@ module Docs
self.release = '1.34.3'
self.base_url = 'https://twig.symfony.com/doc/1.x/'
end
+
+ def get_latest_version(opts)
+ tags = get_github_tags('twigphp', 'Twig', opts)
+ tags[0]['name'][1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/typescript.rb b/lib/docs/scrapers/typescript.rb
index 1117314a..777f5dd6 100644
--- a/lib/docs/scrapers/typescript.rb
+++ b/lib/docs/scrapers/typescript.rb
@@ -24,6 +24,10 @@ module Docs
© Microsoft and other contributors
Licensed under the Apache License, Version 2.0.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('Microsoft', 'TypeScript', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/underscore.rb b/lib/docs/scrapers/underscore.rb
index 004a09e9..a09b4acb 100644
--- a/lib/docs/scrapers/underscore.rb
+++ b/lib/docs/scrapers/underscore.rb
@@ -20,5 +20,10 @@ module Docs
© 2009–2018 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
Licensed under the MIT License.
HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://underscorejs.org/', opts)
+ doc.at_css('.version').content[1...-1]
+ end
end
end
diff --git a/lib/docs/scrapers/vagrant.rb b/lib/docs/scrapers/vagrant.rb
index 955746aa..7400fc8c 100644
--- a/lib/docs/scrapers/vagrant.rb
+++ b/lib/docs/scrapers/vagrant.rb
@@ -18,5 +18,10 @@ module Docs
© 2010–2018 Mitchell Hashimoto
Licensed under the MPL 2.0 License.
HTML
+
+ def get_latest_version(opts)
+ contents = get_github_file_contents('hashicorp', 'vagrant', 'website/config.rb', opts)
+ contents.scan(/version\s+=\s+"([0-9.]+)"/)[0][0]
+ end
end
end
diff --git a/lib/docs/scrapers/vue.rb b/lib/docs/scrapers/vue.rb
index f92991f2..333ade1d 100644
--- a/lib/docs/scrapers/vue.rb
+++ b/lib/docs/scrapers/vue.rb
@@ -32,5 +32,9 @@ module Docs
self.root_path = '/guide/index.html'
self.initial_paths = %w(/api/index.html)
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('vuejs', 'vue', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/vulkan.rb b/lib/docs/scrapers/vulkan.rb
index e1fa4b4b..da5d696d 100644
--- a/lib/docs/scrapers/vulkan.rb
+++ b/lib/docs/scrapers/vulkan.rb
@@ -20,5 +20,10 @@ module Docs
Licensed under the Creative Commons Attribution 4.0 International License.
Vulkan and the Vulkan logo are registered trademarks of the Khronos Group Inc.
HTML
+
+ def get_latest_version(opts)
+ tags = get_github_tags('KhronosGroup', 'Vulkan-Docs', opts)
+ tags[0]['name'][1..-1]
+ end
end
end
diff --git a/lib/docs/scrapers/webpack.rb b/lib/docs/scrapers/webpack.rb
index 255c1bb4..7af2cf11 100644
--- a/lib/docs/scrapers/webpack.rb
+++ b/lib/docs/scrapers/webpack.rb
@@ -68,5 +68,9 @@ module Docs
Licensed under the MIT License.
HTML
end
+
+ def get_latest_version(opts)
+ get_npm_version('webpack', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb
index 825a749f..c45695af 100644
--- a/lib/docs/scrapers/yarn.rb
+++ b/lib/docs/scrapers/yarn.rb
@@ -20,5 +20,9 @@ module Docs
© 2016–present Yarn Contributors
Licensed under the BSD License.
HTML
+
+ def get_latest_version(opts)
+ get_latest_github_release('yarnpkg', 'yarn', opts)
+ end
end
end
diff --git a/lib/docs/scrapers/yii.rb b/lib/docs/scrapers/yii.rb
index d99d3ac7..eaabdbf0 100755
--- a/lib/docs/scrapers/yii.rb
+++ b/lib/docs/scrapers/yii.rb
@@ -34,5 +34,9 @@ module Docs
options[:container] = '.grid_9'
end
+
+ def get_latest_version(opts)
+ get_latest_github_release('yiisoft', 'yii2', opts)
+ end
end
end
diff --git a/lib/tasks/assets.thor b/lib/tasks/assets.thor
index c3a4caf5..e9de1b6f 100644
--- a/lib/tasks/assets.thor
+++ b/lib/tasks/assets.thor
@@ -14,6 +14,9 @@ class AssetsCLI < Thor
option :keep, type: :numeric, default: 0, desc: 'Number of old assets to keep'
option :verbose, type: :boolean
def compile
+ load 'tasks/sprites.thor'
+ invoke 'sprites:generate', [], :remove_public_icons => true, :verbose => options[:verbose]
+
manifest.compile App.assets_compile
manifest.clean(options[:keep]) if options[:clean]
end
diff --git a/lib/tasks/sprites.thor b/lib/tasks/sprites.thor
new file mode 100644
index 00000000..1c0d3600
--- /dev/null
+++ b/lib/tasks/sprites.thor
@@ -0,0 +1,213 @@
+class SpritesCLI < Thor
+ def self.to_s
+ 'Sprites'
+ end
+
+ def initialize(*args)
+ require 'docs'
+ require 'chunky_png'
+ require 'fileutils'
+ super
+ end
+
+ desc 'generate [--remove-public-icons] [--verbose]', 'Generate the documentation icon spritesheets'
+ option :remove_public_icons, type: :boolean, desc: 'Remove public/icons after generating the spritesheets'
+ option :verbose, type: :boolean
+ def generate
+ items = get_items
+ items_with_icons = items.select {|item| item[:has_icons]}
+ items_without_icons = items.select {|item| !item[:has_icons]}
+ icons_per_row = Math.sqrt(items_with_icons.length).ceil
+
+ bg_color = get_sidebar_background
+
+ items_with_icons.each_with_index do |item, index|
+ item[:row] = (index / icons_per_row).floor
+ item[:col] = index - item[:row] * icons_per_row
+
+ item[:icon_16] = get_icon(item[:path_16], 16)
+ item[:icon_32] = get_icon(item[:path_32], 32)
+
+ item[:dark_icon_fix] = needs_dark_icon_fix(item[:icon_32], bg_color)
+ end
+
+ return unless items_with_icons.length > 0
+
+ log_details(items_with_icons, icons_per_row)
+
+ generate_spritesheet(16, items_with_icons, 'assets/images/sprites/docs.png') {|item| item[:icon_16]}
+ generate_spritesheet(32, items_with_icons, 'assets/images/sprites/docs@2x.png') {|item| item[:icon_32]}
+
+ # Add Mongoose's icon details to docs without custom icons
+ default_item = items_with_icons.find {|item| item[:type] == 'mongoose'}
+ items_without_icons.each do |item|
+ item[:row] = default_item[:row]
+ item[:col] = default_item[:col]
+ item[:dark_icon_fix] = default_item[:dark_icon_fix]
+ end
+
+ save_manifest(items, icons_per_row, 'assets/images/sprites/docs.json')
+
+ if options[:remove_public_icons]
+ logger.info('Removing public/icons')
+ FileUtils.rm_rf('public/icons')
+ end
+ end
+
+ private
+
+ def get_items
+ items = Docs.all.map do |doc|
+ base_path = "public/icons/docs/#{doc.slug}"
+ {
+ :type => doc.slug,
+ :path_16 => "#{base_path}/16.png",
+ :path_32 => "#{base_path}/16@2x.png"
+ }
+ end
+
+ # Checking paths against an array of possible paths is faster than 200+ File.exist? calls
+ files = Dir.glob('public/icons/docs/**/*.png')
+
+ items.each do |item|
+ item[:has_icons] = files.include?(item[:path_16]) && files.include?(item[:path_32])
+ end
+ end
+
+ def get_icon(path, max_size)
+ icon = ChunkyPNG::Image.from_file(path)
+
+ # Check if the icon is too big
+ # If it is, resize the image without changing the aspect ratio
+ if icon.width > max_size || icon.height > max_size
+ ratio = icon.width.to_f / icon.height
+ new_width = (icon.width >= icon.height ? max_size : max_size * ratio).floor
+ new_height = (icon.width >= icon.height ? max_size / ratio : max_size).floor
+
+ logger.warn("Icon #{path} is too big: max size is #{max_size} x #{max_size}, icon is #{icon.width} x #{icon.height}, resizing to #{new_width} x #{new_height}")
+
+ icon.resample_nearest_neighbor!(new_width, new_height)
+ end
+
+ icon
+ end
+
+ def get_sidebar_background
+ # This is a hacky way to get the background color of the sidebar
+ # Unfortunately, it's not possible to get the value of a SCSS variable from a Thor task
+ # Because hard-coding the value is even worse, we extract it using some regex
+ path = 'assets/stylesheets/global/_variables-dark.scss'
+ regex = /--sidebarBackground:\s+([^;]+);/
+ ChunkyPNG::Color.parse(File.read(path)[regex, 1])
+ end
+
+ def needs_dark_icon_fix(icon, bg_color)
+ # Determine whether the icon needs to be grayscaled if the user has enabled the dark theme
+ # The logic is roughly based on https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast
+ contrast = icon.pixels.select {|pixel| ChunkyPNG::Color.a(pixel) > 0}.map do |pixel|
+ get_contrast(bg_color, pixel)
+ end
+
+ avg = contrast.reduce(:+) / contrast.size.to_f
+ avg < 3.5
+ end
+
+ def get_contrast(base, other)
+ # Calculating the contrast ratio as described in the WCAG 2.0:
+ # https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
+ l1 = get_luminance(base) + 0.05
+ l2 = get_luminance(other) + 0.05
+ ratio = l1 / l2
+ l2 > l1 ? 1 / ratio : ratio
+ end
+
+ def get_luminance(color)
+ rgb = [
+ ChunkyPNG::Color.r(color).to_f,
+ ChunkyPNG::Color.g(color).to_f,
+ ChunkyPNG::Color.b(color).to_f
+ ]
+
+ # Calculating the relative luminance as described in the WCAG 2.0:
+ # https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
+
+ rgb.map! do |value|
+ value /= 255
+ value < 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4
+ end
+
+ 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]
+ end
+
+ def generate_spritesheet(size, items_with_icons, output_path, &item_to_icon)
+ logger.info("Generating spritesheet #{output_path} with icons of size #{size} x #{size}")
+
+ icons_per_row = Math.sqrt(items_with_icons.length).ceil
+ spritesheet = ChunkyPNG::Image.new(size * icons_per_row, size * icons_per_row)
+
+ items_with_icons.each do |item|
+ icon = item_to_icon.call(item)
+
+ # Calculate the base coordinates
+ base_x = item[:col] * size
+ base_y = item[:row] * size
+
+ # Center the icon if it's not a perfect rectangle
+ x = base_x + ((size - icon.width) / 2).floor
+ y = base_y + ((size - icon.height) / 2).floor
+
+ spritesheet.compose!(icon, x, y)
+ end
+
+ FileUtils.mkdir_p(File.dirname(output_path))
+ spritesheet.save(output_path)
+ end
+
+ def save_manifest(items, icons_per_row, path)
+ logger.info("Saving spritesheet details to #{path}")
+
+ FileUtils.mkdir_p(File.dirname(path))
+
+ # Only save the details that the scss file needs
+ manifest_items = items.map do |item|
+ {
+ :type => item[:type],
+ :row => item[:row],
+ :col => item[:col],
+ :dark_icon_fix => item[:dark_icon_fix]
+ }
+ end
+
+ manifest = {:icons_per_row => icons_per_row, :items => manifest_items}
+
+ File.open(path, 'w') do |f|
+ f.write(JSON.generate(manifest))
+ end
+ end
+
+ def log_details(items_with_icons, icons_per_row)
+ logger.debug("Amount of icons: #{items_with_icons.length}")
+ logger.debug("Amount of icons needing the dark icon fix: #{items_with_icons.count {|item| item[:dark_icon_fix]}}")
+ logger.debug("Amount of icons per row: #{icons_per_row}")
+
+ max_type_length = items_with_icons.map {|item| item[:type].length}.max
+ border = "+#{'-' * (max_type_length + 2)}+#{'-' * 5}+#{'-' * 8}+#{'-' * 15}+"
+
+ logger.debug(border)
+ logger.debug("| #{'Type'.ljust(max_type_length)} | Row | Column | Dark icon fix |")
+ logger.debug(border)
+
+ items_with_icons.each do |item|
+ logger.debug("| #{item[:type].ljust(max_type_length)} | #{item[:row].to_s.ljust(3)} | #{item[:col].to_s.ljust(6)} | #{(item[:dark_icon_fix] ? 'Yes' : 'No').ljust(13)} |")
+ end
+
+ logger.debug(border)
+ end
+
+ def logger
+ @logger ||= Logger.new($stdout).tap do |logger|
+ logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
+ logger.formatter = proc {|severity, datetime, progname, msg| "#{msg}\n"}
+ end
+ end
+end
diff --git a/lib/tasks/updates.thor b/lib/tasks/updates.thor
new file mode 100644
index 00000000..c715f752
--- /dev/null
+++ b/lib/tasks/updates.thor
@@ -0,0 +1,315 @@
+class UpdatesCLI < Thor
+ # The GitHub user that is allowed to upload reports
+ UPLOAD_USER = 'devdocs-bot'
+
+ # The repository to create an issue in when uploading the results
+ UPLOAD_REPO = 'freeCodeCamp/devdocs'
+
+ def self.to_s
+ 'Updates'
+ end
+
+ def initialize(*args)
+ require 'docs'
+ require 'progress_bar'
+ require 'terminal-table'
+ require 'date'
+ super
+ end
+
+ desc 'check [--github-token] [--upload] [--verbose] [doc]...', 'Check for outdated documentations'
+ option :github_token, :type => :string
+ option :upload, :type => :boolean
+ option :verbose, :type => :boolean
+ def check(*names)
+ # Convert names to a list of Scraper instances
+ # Versions are omitted, if v10 is outdated than v8 is aswell
+ docs = names.map {|name| Docs.find(name.split(/@|~/)[0], false)}.uniq
+
+ # Check all documentations for updates when no arguments are given
+ docs = Docs.all if docs.empty?
+
+ opts = {
+ logger: logger
+ }
+
+ if options.key?(:github_token)
+ opts[:github_token] = options[:github_token]
+ end
+
+ with_progress_bar do |bar|
+ bar.max = docs.length
+ bar.write
+ end
+
+ results = docs.map do |doc|
+ result = check_doc(doc, opts)
+ with_progress_bar(&:increment!)
+ result
+ end
+
+ process_results(results)
+ rescue Docs::DocNotFound => error
+ logger.error(error)
+ logger.info('Run "thor docs:list" to see the list of docs.')
+ end
+
+ private
+
+ def check_doc(doc, opts)
+ logger.debug("Checking #{doc.name}")
+
+ instance = doc.versions.first.new
+ scraper_version = instance.get_scraper_version(opts)
+ latest_version = instance.get_latest_version(opts)
+
+ {
+ name: doc.name,
+ scraper_version: format_version(scraper_version),
+ latest_version: format_version(latest_version),
+ is_outdated: instance.is_outdated(scraper_version, latest_version)
+ }
+ rescue NotImplementedError
+ logger.warn("Couldn't check #{doc.name}, get_latest_version is not implemented")
+ error_result(doc, '`get_latest_version` is not implemented')
+ rescue => error
+ logger.error("Error while checking #{doc.name}\n#{error.full_message.strip}")
+ error_result(doc, error.message.gsub(/'/, '`'))
+ end
+
+ def format_version(version)
+ str = version.to_s
+
+ # If the version is numeric and greater than or equal to 1e9 it's probably a timestamp
+ return str if str.match(/^(\d)+$/).nil? or str.to_i < 1e9
+
+ DateTime.strptime(str, '%s').strftime('%F')
+ end
+
+ def error_result(doc, reason)
+ {
+ name: doc.name,
+ error: reason
+ }
+ end
+
+ def process_results(results)
+ successful_results = results.select {|result| result.key?(:is_outdated)}
+ failed_results = results.select {|result| result.key?(:error)}
+
+ up_to_date_results = successful_results.select {|result| !result[:is_outdated]}
+ outdated_results = successful_results.select {|result| result[:is_outdated]}
+
+ log_results(outdated_results, up_to_date_results, failed_results)
+ upload_results(outdated_results, up_to_date_results, failed_results) if options[:upload]
+ end
+
+ #
+ # Result logging methods
+ #
+
+ def log_results(outdated_results, up_to_date_results, failed_results)
+ log_failed_results(failed_results) unless failed_results.empty?
+ log_successful_results('Up-to-date', up_to_date_results) unless up_to_date_results.empty?
+ log_successful_results('Outdated', outdated_results) unless outdated_results.empty?
+ end
+
+ def log_successful_results(label, results)
+ title = "#{label} documentations (#{results.length})"
+ headings = ['Documentation', 'Scraper version', 'Latest version']
+ rows = results.map {|result| [result[:name], result[:scraper_version], result[:latest_version]]}
+
+ table = Terminal::Table.new :title => title, :headings => headings, :rows => rows
+ puts table
+ end
+
+ def log_failed_results(results)
+ title = "Documentations that could not be checked (#{results.length})"
+ headings = %w(Documentation Reason)
+ rows = results.map {|result| [result[:name], result[:error]]}
+
+ table = Terminal::Table.new :title => title, :headings => headings, :rows => rows
+ puts table
+ end
+
+ #
+ # Upload methods
+ #
+
+ def upload_results(outdated_results, up_to_date_results, failed_results)
+ # We can't create issues without a GitHub token
+ unless options.key?(:github_token)
+ logger.error("Please specify a GitHub token with the public_repo permission for #{UPLOAD_USER} with the --github-token parameter")
+ return
+ end
+
+ logger.info('Uploading the results to a new GitHub issue')
+
+ logger.info('Checking if the GitHub token belongs to the correct user')
+ user = github_get('/user')
+
+ # Only allow the DevDocs bot to upload reports
+ unless user['login'] == UPLOAD_USER
+ logger.error("Only #{UPLOAD_USER} is supposed to upload the results to a new issue. The specified github token is not for #{UPLOAD_USER}.")
+ return
+ end
+
+ logger.info('Creating a new GitHub issue')
+
+ issue = results_to_issue(outdated_results, up_to_date_results, failed_results)
+ created_issue = github_post("/repos/#{UPLOAD_REPO}/issues", issue)
+
+ logger.info('Checking if the previous issue is still open')
+
+ search_params = {
+ q: "Documentation versions report in:title author:#{UPLOAD_USER} is:issue repo:#{UPLOAD_REPO}",
+ sort: 'created',
+ order: 'desc'
+ }
+
+ matching_issues = github_get('/search/issues', search_params)
+ previous_issue = matching_issues['items'].find {|item| item['number'] != created_issue['number']}
+
+ if previous_issue.nil?
+ logger.info('No previous issue found')
+ log_upload_success(created_issue)
+ else
+ logger.info('Commenting on the previous issue')
+
+ comment = "This report was superseded by ##{created_issue['number']}."
+ github_post("/repos/#{UPLOAD_REPO}/issues/#{previous_issue['number']}/comments", {body: comment})
+ if previous_issue['closed_at'].nil?
+ logger.info('Closing the previous issue')
+ github_patch("/repos/#{UPLOAD_REPO}/issues/#{previous_issue['number']}", {state: 'closed'})
+ log_upload_success(created_issue)
+ else
+ logger.info('The previous issue has already been closed')
+ log_upload_success(created_issue)
+ end
+ end
+ end
+
+ def results_to_issue(outdated_results, up_to_date_results, failed_results)
+ results = [
+ successful_results_to_markdown('Outdated', outdated_results),
+ successful_results_to_markdown('Up-to-date', up_to_date_results),
+ failed_results_to_markdown(failed_results)
+ ]
+
+ results_str = results.select {|result| !result.nil?}.join("\n\n")
+ travis_str = ENV['TRAVIS'].nil? ? '' : "\n\nThis issue was created by Travis CI build [##{ENV['TRAVIS_BUILD_NUMBER']}](#{ENV['TRAVIS_BUILD_WEB_URL']})."
+
+ title = "Documentation versions report for #{Date.today.strftime('%B %Y')}"
+ body = <<-MARKDOWN
+## What is this?
+
+This is an automatically created issue which contains information about the version status of the documentations available on DevDocs. The results of this report can be used by maintainers when updating outdated documentations.
+
+Maintainers can close this issue when all documentations are up-to-date. The issue is also automatically closed when the next report is created.#{travis_str}
+
+## Results
+
+The #{outdated_results.length + up_to_date_results.length + failed_results.length} documentations are divided as follows:
+- #{outdated_results.length} that #{outdated_results.length == 1 ? 'is' : 'are'} outdated
+- #{up_to_date_results.length} that #{up_to_date_results.length == 1 ? 'is' : 'are'} up-to-date (patch updates are ignored)
+- #{failed_results.length} that could not be checked
+ MARKDOWN
+
+ {
+ title: title,
+ body: body.strip + "\n\n" + results_str
+ }
+ end
+
+ def successful_results_to_markdown(label, results)
+ return nil if results.empty?
+
+ title = "#{label} documentations (#{results.length})"
+ headings = ['Documentation', 'Scraper version', 'Latest version']
+ rows = results.map {|result| [result[:name], result[:scraper_version], result[:latest_version]]}
+
+ results_to_markdown(title, headings, rows)
+ end
+
+ def failed_results_to_markdown(results)
+ return nil if results.empty?
+
+ title = "Documentations that could not be checked (#{results.length})"
+ headings = %w(Documentation Reason)
+ rows = results.map {|result| [result[:name], result[:error]]}
+
+ results_to_markdown(title, headings, rows)
+ end
+
+ def results_to_markdown(title, headings, rows)
+ "\n#{title} \n\n#{create_markdown_table(headings, rows)}\n "
+ end
+
+ def create_markdown_table(headings, rows)
+ header = headings.join(' | ')
+ separator = '-|' * headings.length
+ body = rows.map {|row| row.join(' | ')}
+
+ header + "\n" + separator[0...-1] + "\n" + body.join("\n")
+ end
+
+ def log_upload_success(created_issue)
+ logger.info("Successfully uploaded the results to #{created_issue['html_url']}")
+ end
+
+ #
+ # HTTP utilities
+ #
+
+ def github_get(endpoint, params = {})
+ github_request(endpoint, {method: :get, params: params})
+ end
+
+ def github_post(endpoint, params)
+ github_request(endpoint, {method: :post, body: params.to_json})
+ end
+
+ def github_patch(endpoint, params)
+ github_request(endpoint, {method: :patch, body: params.to_json})
+ end
+
+ def github_request(endpoint, opts)
+ url = "https://api.github.com#{endpoint}"
+
+ # GitHub token authentication
+ opts[:headers] = {
+ Authorization: "token #{options[:github_token]}"
+ }
+
+ # GitHub requires the Content-Type to be application/json when a body is passed
+ if opts.key?(:body)
+ opts[:headers]['Content-Type'] = 'application/json'
+ end
+
+ logger.debug("Making a #{opts[:method]} request to #{url}")
+ response = Docs::Request.run(url, opts)
+
+ # response.success? is false if the response code is 201
+ # GitHub returns 201 Created after an issue is created
+ if response.success? || response.code == 201
+ JSON.parse(response.body)
+ else
+ logger.error("Couldn't make a #{opts[:method]} request to #{url} (response code #{response.code})")
+ nil
+ end
+ end
+
+ # A utility method which ensures no progress bar is shown when stdout is not a tty
+ def with_progress_bar(&block)
+ return unless $stdout.tty?
+ @progress_bar ||= ::ProgressBar.new
+ block.call @progress_bar
+ end
+
+ def logger
+ @logger ||= Logger.new($stdout).tap do |logger|
+ logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
+ logger.formatter = proc {|severity, datetime, progname, msg| "[#{severity}] #{msg}\n"}
+ end
+ end
+end
diff --git a/public/docs/docs.json b/public/docs/docs.json
deleted file mode 100644
index 0637a088..00000000
--- a/public/docs/docs.json
+++ /dev/null
@@ -1 +0,0 @@
-[]
\ No newline at end of file
diff --git a/public/icons/docs-1.pxm b/public/icons/docs-1.pxm
deleted file mode 100644
index d9418ee7..00000000
Binary files a/public/icons/docs-1.pxm and /dev/null differ
diff --git a/public/icons/docs-1@2x.pxm b/public/icons/docs-1@2x.pxm
deleted file mode 100644
index d2b97c84..00000000
Binary files a/public/icons/docs-1@2x.pxm and /dev/null differ
diff --git a/public/icons/docs-2.pxm b/public/icons/docs-2.pxm
deleted file mode 100644
index ba5ce1b5..00000000
Binary files a/public/icons/docs-2.pxm and /dev/null differ
diff --git a/public/icons/docs-2@2x.pxm b/public/icons/docs-2@2x.pxm
deleted file mode 100644
index 3c390953..00000000
Binary files a/public/icons/docs-2@2x.pxm and /dev/null differ
diff --git a/public/icons/docs/bluebird/16@2x.png b/public/icons/docs/bluebird/16@2x.png
index 9ffae075..64ad5903 100644
Binary files a/public/icons/docs/bluebird/16@2x.png and b/public/icons/docs/bluebird/16@2x.png differ
diff --git a/public/images/webapp-icon-192.png b/public/images/webapp-icon-192.png
new file mode 100644
index 00000000..d1d1dd75
Binary files /dev/null and b/public/images/webapp-icon-192.png differ
diff --git a/public/manifest.json b/public/manifest.json
index 1faa5978..301c56d1 100644
--- a/public/manifest.json
+++ b/public/manifest.json
@@ -4,6 +4,7 @@
"description": "API Documentation Browser",
"start_url": "/",
"display": "standalone",
+ "background_color": "#EEEEEE",
"icons": [
{
"src": "/images/webapp-icon-32.png",
@@ -25,6 +26,11 @@
"sizes": "128x128",
"type": "image/png"
},
+ {
+ "src": "/images/webapp-icon-192.png",
+ "sizes": "192x192",
+ "type": "image/png"
+ },
{
"src": "/images/webapp-icon-256.png",
"sizes": "256x256",
diff --git a/test/app_test.rb b/test/app_test.rb
index 92a24acd..8e9e369b 100644
--- a/test/app_test.rb
+++ b/test/app_test.rb
@@ -43,35 +43,6 @@ class AppTest < MiniTest::Spec
assert last_response.redirect?
assert_equal 'https://example.org/', last_response['Location']
end
-
- it "sets default size" do
- get '/'
- assert_includes last_response.body, 'data-size="20rem"'
- end
-
- it "sets size from cookie" do
- set_cookie('size=42')
- get '/'
- assert_includes last_response.body, 'data-size="42px"'
- end
-
- it "sets layout from cookie" do
- set_cookie('layout=foo')
- get '/'
- assert_includes last_response.body, ''
- end
-
- it "sets the theme from cookie" do
- get '/'
- assert_match %r{]*class="[^\"]*_theme-default}, last_response.body
- refute_includes last_response.body, '_theme-dark'
-
- set_cookie('dark=1')
-
- get '/'
- assert_match %r{]*class="[^\"]*_theme-dark}, last_response.body
- refute_includes last_response.body, '_theme-default'
- end
end
describe "/[static-page]" do
@@ -106,58 +77,6 @@ class AppTest < MiniTest::Spec
end
end
- describe "/manifest.appcache" do
- it "works" do
- get '/manifest.appcache'
- assert last_response.ok?
- end
-
- it "works with cookie" do
- set_cookie('docs=css/html~5')
- get '/manifest.appcache'
- assert last_response.ok?
- assert_includes last_response.body, '/css/index.json?1420139788'
- assert_includes last_response.body, '/html~5/index.json?1420139791'
- end
-
- it "ignores invalid docs in the cookie" do
- set_cookie('docs=foo')
- get '/manifest.appcache'
- assert last_response.ok?
- refute_includes last_response.body, 'foo'
- end
-
- it "has the word 'default' when no 'dark' cookie is set" do
- get '/manifest.appcache'
- assert_includes last_response.body, '# default'
- refute_includes last_response.body, '# dark'
- end
-
- it "has the word 'dark' when the cookie is set" do
- set_cookie('dark=1')
- get '/manifest.appcache'
- assert_includes last_response.body, '# dark'
- refute_includes last_response.body, '# default'
- end
-
- it "sets default size" do
- get '/manifest.appcache'
- assert_includes last_response.body, '20rem'
- end
-
- it "sets size from cookie" do
- set_cookie('size=42')
- get '/manifest.appcache'
- assert_includes last_response.body, '42px'
- end
-
- it "sets layout from cookie" do
- set_cookie('layout=foo_layout')
- get '/manifest.appcache'
- assert_includes last_response.body, 'foo_layout'
- end
- end
-
describe "/[doc]" do
it "renders when the doc exists and isn't enabled" do
set_cookie('docs=html~5')
diff --git a/test/lib/docs/core/scrapers/file_scraper_test.rb b/test/lib/docs/core/scrapers/file_scraper_test.rb
index 7d90d262..88b5e8d5 100644
--- a/test/lib/docs/core/scrapers/file_scraper_test.rb
+++ b/test/lib/docs/core/scrapers/file_scraper_test.rb
@@ -63,7 +63,7 @@ class FileScraperTest < MiniTest::Spec
end
it "reads a file" do
- mock(scraper).read_file(path)
+ mock(scraper).read_file(File.join(ROOT_PATH, 'docs/scraper', path))
result
end
@@ -165,7 +165,7 @@ class FileScraperTest < MiniTest::Spec
describe "#read_file" do
let :result do
- scraper.send :read_file, 'file'
+ scraper.send :read_file, File.join(ROOT_PATH, 'docs', 'scraper', 'file')
end
it "returns the file's content when the file exists in the source directory" do
diff --git a/views/app.erb b/views/app.erb
index 7cffabd0..ffaa1bf3 100644
--- a/views/app.erb
+++ b/views/app.erb
@@ -28,13 +28,7 @@
@@ -63,9 +57,3 @@
-
diff --git a/views/index.erb b/views/index.erb
index 022e927f..4fb96153 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -1,5 +1,5 @@
- prefix="og: http://ogp.me/ns#" lang="en" class="_booting _theme-<%= app_theme %>">
+
@@ -14,6 +14,7 @@
+
DevDocs API Documentation
@@ -32,7 +33,7 @@
<%= stylesheet_tag 'application' %>
->
+
DevDocs requires JavaScript to run.
<%= erb :app -%>
<%= javascript_tag 'application', asset_host: false %>
diff --git a/views/manifest.erb b/views/manifest.erb
deleted file mode 100644
index 9d2df923..00000000
--- a/views/manifest.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-CACHE MANIFEST
-# <%= app_theme %> <%= app_size %> <%= app_layout %>
-
-CACHE:
-/
-<%= manifest_asset_urls.join "\n" %>
-<%= doc_index_urls.join "\n" %>
-
-NETWORK:
-/s/
-*
-
-FALLBACK:
-/ /
diff --git a/views/other.erb b/views/other.erb
index ee9b8de1..45cab943 100644
--- a/views/other.erb
+++ b/views/other.erb
@@ -1,10 +1,11 @@
-
+
<% if doc_index_page? %>
<% else %>
<% end %>
+
DevDocs<%= " — #{@doc['full_name']} documentation" if doc_index_page? %>
@@ -13,7 +14,7 @@
<%= stylesheet_tag 'application' %>
- data-doc="<%= CGI::escape_html @doc.to_json %>">
+
DevDocs requires JavaScript to run.
<%= erb :app -%>
<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
diff --git a/views/service-worker.js.erb b/views/service-worker.js.erb
new file mode 100644
index 00000000..8d5698a7
--- /dev/null
+++ b/views/service-worker.js.erb
@@ -0,0 +1,49 @@
+<%# The name of the cache to store responses in %>
+<%# If the cache name changes DevDocs is assumed to be updated %>
+const cacheName = '<%= service_worker_cache_name %>';
+
+<%# Url's to cache when the service worker is installed %>
+const urlsToCache = [
+ '/',
+ '/favicon.ico',
+ '/manifest.json',
+ '<%= service_worker_asset_urls.join "',\n '" %>',
+ '<%= doc_index_urls.join "',\n '" %>',
+];
+
+<%# Set-up the cache %>
+self.addEventListener('install', event => {
+ self.skipWaiting();
+
+ event.waitUntil(
+ caches.open(cacheName).then(cache => cache.addAll(urlsToCache)),
+ );
+});
+
+<%# Remove old caches %>
+self.addEventListener('activate', event => {
+ event.waitUntil((async () => {
+ const keys = await caches.keys();
+ const jobs = keys.map(key => key !== cacheName ? caches.delete(key) : Promise.resolve());
+ return Promise.all(jobs);
+ })());
+});
+
+<%# Handle HTTP requests %>
+self.addEventListener('fetch', event => {
+ event.respondWith((async () => {
+ const cachedResponse = await caches.match(event.request);
+ if (cachedResponse) return cachedResponse;
+
+ const url = new URL(event.request.url);
+
+ <%# Attempt to return the index page from the cache if the user is visiting a url like devdocs.io/offline or devdocs.io/javascript/global_objects/array/find %>
+ <%# The index page will handle the routing %>
+ if (url.origin === location.origin && !url.pathname.includes('.')) {
+ const cachedIndex = await caches.match('/');
+ if (cachedIndex) return cachedIndex;
+ }
+
+ return fetch(event.request);
+ })());
+});
diff --git a/views/unsupported.erb b/views/unsupported.erb
index a01b7c7e..6c1ded7e 100644
--- a/views/unsupported.erb
+++ b/views/unsupported.erb
@@ -11,9 +11,9 @@
DevDocs is an API documentation browser which supports the following browsers:
Recent versions of Firefox, Chrome, or Opera
- Safari 9.1+
- Edge 16+
- iOS 10+
+ Safari 11.1+
+ Edge 17+
+ iOS 11.3+
If you're unable to upgrade, we apologize.