dd` mapping.
+* [Visual Studio Code plugin](https://marketplace.visualstudio.com/items?itemName=akfish.vscode-devdocs ) (1)
+* [Visual Studio Code plugin](https://marketplace.visualstudio.com/items?itemName=deibit.devdocs) (2)
+* [Desktop application](https://github.com/egoist/devdocs-desktop)
+* [Doc Browser](https://github.com/qwfy/doc-browser) is a native Linux app that supports DevDocs docsets
+* [GNOME Application](https://github.com/hardpixel/devdocs-desktop) GTK3 application with search integrated in headerbar
+* [macOS Application](https://github.com/dteoh/devdocs-macos)
+* [Android Application](https://github.com/Merith-TK/devdocs_webapp_kotlin) is a fully working, advanced WebView
## Copyright / License
-Copyright 2013-2018 Thibaut Courouble and [other contributors](https://github.com/freeCodeCamp/devdocs/graphs/contributors)
+Copyright 2013-2019 Thibaut Courouble and [other contributors](https://github.com/freeCodeCamp/devdocs/graphs/contributors)
-This software is licensed under the terms of the Mozilla Public License v2.0. See the [COPYRIGHT](https://github.com/freeCodeCamp/devdocs/blob/master/COPYRIGHT) and [LICENSE](https://github.com/freeCodeCamp/devdocs/blob/master/LICENSE) files.
+This software is licensed under the terms of the Mozilla Public License v2.0. See the [COPYRIGHT](./COPYRIGHT) and [LICENSE](./LICENSE) files.
-Please do not use the name DevDocs to endorse or promote products derived from this software without my permission, except as may be necessary to comply with the notice/attribution requirements.
+Please do not use the name DevDocs to endorse or promote products derived from this software without the maintainers' permission, except as may be necessary to comply with the notice/attribution requirements.
-I also wish that any documentation file generated using this software be attributed to DevDocs. Let's be fair to all contributors by giving credit where credit's due. Thanks!
+We also wish that any documentation file generated using this software be attributed to DevDocs. Let's be fair to all contributors by giving credit where credit's due. Thanks!
## Questions?
-If you have any questions, please feel free to ask them on the [mailing list](https://groups.google.com/d/forum/devdocs).
+If you have any questions, please feel free to ask them on the contributor chat room on [Gitter](https://gitter.im/FreeCodeCamp/DevDocs).
diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee
index e90f1d61..f92e296c 100644
--- a/assets/javascripts/app/app.coffee
+++ b/assets/javascripts/app/app.coffee
@@ -13,10 +13,12 @@
@el = $('._app')
@localStorage = new LocalStorageStore
- @appCache = new app.AppCache if app.AppCache.isEnabled()
+ @serviceWorker = new app.ServiceWorker if app.ServiceWorker.isEnabled()
@settings = new app.Settings
@db = new app.DB()
+ @settings.initLayout()
+
@docs = new app.collections.Docs
@disabledDocs = new app.collections.Docs
@entries = new app.collections.Entries
@@ -147,7 +149,7 @@
saveDocs: ->
@settings.setDocs(doc.slug for doc in @docs.all())
@db.migrate()
- @appCache?.updateInBackground()
+ @serviceWorker?.updateInBackground()
welcomeBack: ->
visitCount = @settings.get('count')
@@ -158,7 +160,7 @@
@updateChecker = new app.UpdateChecker()
reboot: ->
- if location.pathname isnt '/'
+ if location.pathname isnt '/' and location.pathname isnt '/settings'
window.location = "/##{location.pathname}"
else
window.location = '/'
@@ -167,14 +169,14 @@
reload: ->
@docs.clearCache()
@disabledDocs.clearCache()
- if @appCache then @appCache.reload() else @reboot()
+ if @serviceWorker then @serviceWorker.reload() else @reboot()
return
reset: ->
@localStorage.reset()
@settings.reset()
@db?.reset()
- @appCache?.update()
+ @serviceWorker?.update()
window.location = '/'
return
@@ -193,9 +195,9 @@
return
indexHost: ->
- # Can't load the index files from the host/CDN when applicationCache is
+ # Can't load the index files from the host/CDN when service worker is
# enabled because it doesn't support caching URLs that use CORS.
- @config[if @appCache and @settings.hasDocs() then 'index_path' else 'docs_origin']
+ @config[if @serviceWorker and @settings.hasDocs() then 'index_path' else 'docs_origin']
onBootError: (args...) ->
@trigger 'bootError'
@@ -252,7 +254,7 @@
matchMedia: !!window.matchMedia
insertAdjacentHTML: !!document.body.insertAdjacentHTML
defaultPrevented: document.createEvent('CustomEvent').defaultPrevented is false
- cssVariables: CSS.supports and CSS.supports('(--t: 0)')
+ cssVariables: !!CSS?.supports?('(--t: 0)')
for key, value of features when not value
Raven.captureMessage "unsupported/#{key}", level: 'info'
diff --git a/assets/javascripts/app/appcache.coffee b/assets/javascripts/app/appcache.coffee
deleted file mode 100644
index 8ad83904..00000000
--- a/assets/javascripts/app/appcache.coffee
+++ /dev/null
@@ -1,46 +0,0 @@
-class app.AppCache
- $.extend @prototype, Events
-
- @isEnabled: ->
- try
- applicationCache and applicationCache.status isnt applicationCache.UNCACHED
- catch
-
- constructor: ->
- @cache = applicationCache
- @notifyUpdate = true
- @onUpdateReady() if @cache.status is @cache.UPDATEREADY
-
- $.on @cache, 'progress', @onProgress
- $.on @cache, 'updateready', @onUpdateReady
-
- update: ->
- @notifyUpdate = true
- @notifyProgress = true
- try @cache.update() catch
- return
-
- updateInBackground: ->
- @notifyUpdate = false
- @notifyProgress = false
- try @cache.update() catch
- return
-
- reload: ->
- $.on @cache, 'updateready noupdate error', ->
- if location.pathname isnt '/'
- window.location = "/##{location.pathname}"
- else
- window.location = '/'
- @notifyUpdate = false
- @notifyProgress = true
- try @cache.update() catch
- return
-
- onProgress: (event) =>
- @trigger 'progress', event if @notifyProgress
- return
-
- onUpdateReady: =>
- @trigger 'updateready' if @notifyUpdate
- return
diff --git a/assets/javascripts/app/config.coffee.erb b/assets/javascripts/app/config.coffee.erb
index ec26b697..dba368e0 100644
--- a/assets/javascripts/app/config.coffee.erb
+++ b/assets/javascripts/app/config.coffee.erb
@@ -13,3 +13,5 @@ app.config =
version: <%= Time.now.to_i %>
release: <%= Time.now.utc.httpdate.to_json %>
mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'
+ service_worker_path: '/service-worker.js'
+ service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>
diff --git a/assets/javascripts/app/serviceworker.coffee b/assets/javascripts/app/serviceworker.coffee
new file mode 100644
index 00000000..40235566
--- /dev/null
+++ b/assets/javascripts/app/serviceworker.coffee
@@ -0,0 +1,49 @@
+class app.ServiceWorker
+ $.extend @prototype, Events
+
+ @isEnabled: ->
+ !!navigator.serviceWorker and app.config.service_worker_enabled
+
+ constructor: ->
+ @registration = null
+ @notifyUpdate = true
+
+ navigator.serviceWorker.register(app.config.service_worker_path, {scope: '/'})
+ .then(
+ (registration) => @updateRegistration(registration),
+ (error) -> console.error('Could not register service worker:', error)
+ )
+
+ update: ->
+ return unless @registration
+ @notifyUpdate = true
+ return @registration.update().catch(->)
+
+ updateInBackground: ->
+ return unless @registration
+ @notifyUpdate = false
+ return @registration.update().catch(->)
+
+ reload: ->
+ return @updateInBackground().then(() -> app.reboot())
+
+ updateRegistration: (registration) ->
+ @registration = registration
+ $.on @registration, 'updatefound', @onUpdateFound
+ return
+
+ onUpdateFound: =>
+ $.off @installingRegistration, 'statechange', @onStateChange() if @installingRegistration
+ @installingRegistration = @registration.installing
+ $.on @installingRegistration, 'statechange', @onStateChange
+ return
+
+ onStateChange: =>
+ if @installingRegistration and @installingRegistration.state == 'installed' and navigator.serviceWorker.controller
+ @installingRegistration = null
+ @onUpdateReady()
+ return
+
+ onUpdateReady: ->
+ @trigger 'updateready' if @notifyUpdate
+ return
diff --git a/assets/javascripts/app/settings.coffee b/assets/javascripts/app/settings.coffee
index 8d309c41..1d2e43bd 100644
--- a/assets/javascripts/app/settings.coffee
+++ b/assets/javascripts/app/settings.coffee
@@ -19,6 +19,8 @@ class app.Settings
'news'
]
+ LAYOUTS: ['_max-width', '_sidebar-hidden', '_native-scrollbars']
+
@defaults:
count: 0
hideDisabled: false
@@ -38,6 +40,7 @@ class app.Settings
set: (key, value) ->
@store.set(key, value)
delete @cache[key]
+ @toggleDark(value) if key == 'dark'
return
del: (key) ->
@@ -63,6 +66,8 @@ class app.Settings
return
setLayout: (name, enable) ->
+ @toggleLayout(name, enable)
+
layout = (@store.get('layout') || '').split(' ')
$.arrayDelete(layout, '')
@@ -104,3 +109,28 @@ class app.Settings
@store.reset()
@cache = {}
return
+
+ initLayout: ->
+ @toggleDark(@get('dark') is 1)
+ @toggleLayout(layout, @hasLayout(layout)) for layout in @LAYOUTS
+ @initSidebarWidth()
+ return
+
+ toggleDark: (enable) ->
+ classList = document.documentElement.classList
+ classList.toggle('_theme-default', !enable)
+ classList.toggle('_theme-dark', enable)
+ color = getComputedStyle(document.documentElement).getPropertyValue('--headerBackground').trim()
+ $('meta[name=theme-color]').setAttribute('content', color)
+ return
+
+ toggleLayout: (layout, enable) ->
+ classList = document.body.classList
+ classList.toggle(layout, enable) unless layout is '_sidebar-hidden'
+ classList.toggle('_overlay-scrollbars', $.overlayScrollbarsEnabled())
+ return
+
+ initSidebarWidth: ->
+ size = @get('size')
+ document.documentElement.style.setProperty('--sidebarWidth', size + 'px') if size
+ return
diff --git a/assets/javascripts/app/update_checker.coffee b/assets/javascripts/app/update_checker.coffee
index 5630b488..3558d6bc 100644
--- a/assets/javascripts/app/update_checker.coffee
+++ b/assets/javascripts/app/update_checker.coffee
@@ -3,13 +3,13 @@ class app.UpdateChecker
@lastCheck = Date.now()
$.on window, 'focus', @onFocus
- app.appCache.on 'updateready', @onUpdateReady if app.appCache
+ app.serviceWorker?.on 'updateready', @onUpdateReady
setTimeout @checkDocs, 0
check: ->
- if app.appCache
- app.appCache.update()
+ if app.serviceWorker
+ app.serviceWorker.update()
else
ajax
url: $('script[src*="application"]').getAttribute('src')
diff --git a/assets/javascripts/lib/license.coffee b/assets/javascripts/lib/license.coffee
index 8ff7c6e2..7f7ca938 100644
--- a/assets/javascripts/lib/license.coffee
+++ b/assets/javascripts/lib/license.coffee
@@ -1,5 +1,5 @@
###
- * Copyright 2013-2018 Thibaut Courouble and other contributors
+ * Copyright 2013-2019 Thibaut Courouble and other contributors
*
* This source code is licensed under the terms of the Mozilla
* Public License, v. 2.0, a copy of which may be obtained at:
diff --git a/assets/javascripts/news.json b/assets/javascripts/news.json
index 32da738e..a2d18a47 100644
--- a/assets/javascripts/news.json
+++ b/assets/javascripts/news.json
@@ -1,4 +1,8 @@
[
+ [
+ "2019-07-19",
+ "Replaced the AppCache with a Service Worker (which makes DevDocs an installable PWA) and fixed layout preferences on Firefox."
+ ],
[
"2018-09-23",
"New documentations: Puppeteer and Handlebars.js"
diff --git a/assets/javascripts/templates/error_tmpl.coffee b/assets/javascripts/templates/error_tmpl.coffee
index 37e2b5e4..9cca1f9d 100644
--- a/assets/javascripts/templates/error_tmpl.coffee
+++ b/assets/javascripts/templates/error_tmpl.coffee
@@ -12,8 +12,8 @@ app.templates.notFoundPage = ->
app.templates.pageLoadError = ->
error """ The page failed to load. """,
- """ It may be missing from the server (try reloading the app) or you could be offline.
- If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """,
+ """ It may be missing from the server (try reloading the app) or you could be offline (try installing the documentation for offline usage when online again).
+ If you're online and you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """,
""" #{back} · Reload
· Retry """
@@ -57,17 +57,17 @@ app.templates.unsupportedBrowser = """
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, I apologize.
- I decided to prioritize speed and new features over support for older browsers.
+ If you're unable to upgrade, we apologize.
+ We decided to prioritize speed and new features over support for older browsers.
Note: if you're already using one of the browsers above, check your settings and add-ons.
The app uses feature detection, not user agent sniffing.
- — Thibaut @DevDocs
+ — @DevDocs
"""
diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee
index c7e5a414..5d997403 100644
--- a/assets/javascripts/templates/pages/about_tmpl.coffee
+++ b/assets/javascripts/templates/pages/about_tmpl.coffee
@@ -11,22 +11,18 @@ app.templates.aboutPage = -> """
DevDocs: API Documentation Browser
- DevDocs combines multiple API documentations in a clean and organized web UI with instant search, offline support, mobile version, dark theme, keyboard shortcuts, and more.
-
+ DevDocs combines multiple developer documentations in a clean and organized web UI with instant search, offline support, mobile version, dark theme, keyboard shortcuts, and more.
+
DevDocs is free and open source. It was created by Thibaut Courouble and is operated by freeCodeCamp.
To keep up-to-date with the latest news:
Copyright and License
- Copyright 2013–2018 Thibaut Courouble and other contributors
+ Copyright 2013–2019 Thibaut Courouble and other contributors
This software is licensed under the terms of the Mozilla Public License v2.0.
You may obtain a copy of the source code at github.com/freeCodeCamp/devdocs.
For more information, see the COPYRIGHT
@@ -48,11 +44,10 @@ app.templates.aboutPage = -> """
Where can I suggest new docs and features?
You can suggest and vote for new docs on the Trello board.
If you have a specific feature request, add it to the issue tracker.
- Otherwise use the mailing list.
+ Otherwise, come talk to us in the Gitter chat room.
Where can I report bugs?
In the issue tracker. Thanks!
- For anything else, feel free to email me at thibaut@devdocs.io.
Credits
@@ -76,12 +71,12 @@ app.templates.aboutPage = -> """
Privacy Policy
- - devdocs.io ("App") is operated by Thibaut Courouble ("We").
-
- We do not collect personal information.
+
- devdocs.io ("App") is operated by freeCodeCamp ("We").
+
- We do not collect personal information through the app.
- We use Google Analytics, Gauges and Sentry to collect anonymous traffic information and improve the app.
- The app uses cookies to store user preferences.
- By using the app, you signify your acceptance of this policy. If you do not agree to this policy, please do not use the app.
-
- If you have any questions regarding privacy, please email thibaut@devdocs.io.
+
- If you have any questions regarding privacy, please email privacy@freecodecamp.org.
"""
diff --git a/assets/javascripts/templates/pages/offline_tmpl.coffee b/assets/javascripts/templates/pages/offline_tmpl.coffee
index a9a3c21c..bb9e06e8 100644
--- a/assets/javascripts/templates/pages/offline_tmpl.coffee
+++ b/assets/javascripts/templates/pages/offline_tmpl.coffee
@@ -25,8 +25,8 @@ app.templates.offlinePage = (docs) -> """
Questions & Answers
- How does this work?
-
- Each page is cached as a key-value pair in IndexedDB (downloaded from a single file).
- The app also uses AppCache and localStorage to cache the assets and index files.
+ - Each page is cached as a key-value pair in IndexedDB (downloaded from a single file).
+ The app also uses Service Workers and localStorage to cache the assets and index files.
- Can I close the tab/browser?
- #{canICloseTheTab()}
- 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 b5369403..a94a99a0 100644
--- a/assets/javascripts/templates/pages/root_tmpl.coffee.erb
+++ b/assets/javascripts/templates/pages/root_tmpl.coffee.erb
@@ -8,13 +8,13 @@ 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.
- To be notified about new versions, don't forget to watch the repository on GitHub.
- The issue tracker is the preferred channel for bug reports and
- feature requests. For everything else, use the mailing list.
+ feature requests. For everything else, use Gitter.
- Contributions are welcome. See the guidelines.
- DevDocs is licensed under the terms of the Mozilla Public License v2.0. For more information,
see the COPYRIGHT and
diff --git a/assets/javascripts/views/content/entry_page.coffee b/assets/javascripts/views/content/entry_page.coffee
index beae4d77..d11291a3 100644
--- a/assets/javascripts/views/content/entry_page.coffee
+++ b/assets/javascripts/views/content/entry_page.coffee
@@ -123,7 +123,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..af2e9a9d 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,25 +14,18 @@ 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[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) ->
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 8b104011..52ff753a 100644
--- a/assets/javascripts/views/search/search_scope.coffee
+++ b/assets/javascripts/views/search/search_scope.coffee
@@ -6,6 +6,7 @@ class app.views.SearchScope extends app.View
tag: '._search-tag'
@events:
+ click: 'onClick'
keydown: 'onKeydown'
textInput: 'onTextInput'
@@ -93,11 +94,17 @@ class app.views.SearchScope extends app.View
$.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()
+ $.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
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 fd6ffffd..2a64e5c9 100644
--- a/assets/stylesheets/application.css.scss
+++ b/assets/stylesheets/application.css.scss
@@ -4,7 +4,7 @@
//= depend_on docs-2@2x.png
/*!
- * Copyright 2013-2018 Thibaut Courouble and other contributors
+ * Copyright 2013-2019 Thibaut Courouble and other contributors
*
* This source code is licensed under the terms of the Mozilla
* Public License, v. 2.0, a copy of which may be obtained at:
diff --git a/assets/stylesheets/components/_fail.scss b/assets/stylesheets/components/_fail.scss
index 535100ac..c520977e 100644
--- a/assets/stylesheets/components/_fail.scss
+++ b/assets/stylesheets/components/_fail.scss
@@ -32,5 +32,3 @@
}
._fail-text:last-child { margin: 0; }
-
-._fail-link { float: right; }
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/pages/_mdn.scss b/assets/stylesheets/pages/_mdn.scss
index d2b9b643..fb2cce38 100644
--- a/assets/stylesheets/pages/_mdn.scss
+++ b/assets/stylesheets/pages/_mdn.scss
@@ -30,6 +30,7 @@
.notice,
.warning,
.overheadIndicator,
+ .blockIndicator,
.syntaxbox, // CSS, JavaScript
.twopartsyntaxbox, // CSS
.inheritsbox, // JavaScript
@@ -104,4 +105,28 @@
.cleared { clear: both; } // CSS/box-shadow
code > strong { font-weight: normal; }
+
+ // Compatibility tablees
+
+ .bc-github-link {
+ float: right;
+ font-size: .75rem;
+ }
+
+ .bc-supports-yes, .bc-supports-yes + dd, .bc-supports-yes + dd + dd { background: var(--noteGreenBackground); }
+ .bc-supports-partial, .bc-supports-partial + dd, .bc-supports-partial + dd + dd { background: var(--noteOrangeBackground); }
+ .bc-supports-no, .bc-supports-no + dd, .bc-supports-no + dd + dd { background: var(--noteRedBackground); }
+
+ .bc-table {
+ min-width: 100%;
+
+ dl {
+ margin: .25rem 0 0;
+ padding: .25rem 0 0;
+ font-size: .75rem;
+ border-top: 1px solid var(--boxBorder);
+ }
+
+ dd { margin: 0; }
+ }
}
diff --git a/assets/stylesheets/pages/_rdoc.scss b/assets/stylesheets/pages/_rdoc.scss
index 7873900a..6622e68e 100644
--- a/assets/stylesheets/pages/_rdoc.scss
+++ b/assets/stylesheets/pages/_rdoc.scss
@@ -33,19 +33,8 @@
}
}
- .method-description { position: relative; }
-
.method-source-code {
display: none;
- position: absolute;
- z-index: 1;
- top: 0;
- left: -1em;
- right: 0;
- background: var(--contentBackground);
- box-shadow: 0 1em 1em 1em var(--contentBackground);
-
- > pre { margin: 0; }
}
// Rails guides
diff --git a/docs/adding-docs.md b/docs/adding-docs.md
new file mode 100644
index 00000000..dfc96cb1
--- /dev/null
+++ b/docs/adding-docs.md
@@ -0,0 +1,23 @@
+Adding a documentation may look like a daunting task but once you get the hang of it, it's actually quite simple. Don't hesitate to ask for help [in Gitter](https://gitter.im/FreeCodeCamp/DevDocs) if you ever get stuck.
+
+**Note:** please read the [contributing guidelines](../.github/CONTRIBUTING.md) before submitting a new documentation.
+
+1. Create a subclass of `Docs::UrlScraper` or `Docs::FileScraper` in the `lib/docs/scrapers/` directory. Its name should be the [PascalCase](http://api.rubyonrails.org/classes/String.html#method-i-camelize) equivalent of the filename (e.g. `my_doc` → `MyDoc`)
+2. Add the appropriate class attributes and filter options (see the [Scraper Reference](./scraper-reference.md) page).
+3. Check that the scraper is listed in `thor docs:list`.
+4. Create filters specific to the scraper in the `lib/docs/filters/[my_doc]/` directory and add them to the class's [filter stacks](./scraper-reference.md#filter-stacks). You may create any number of filters but will need at least the following two:
+ * A [`CleanHtml`](./filter-reference.md#cleanhtmlfilter) filter whose task is to clean the HTML markup (e.g. adding `id` attributes to headings) and remove everything superfluous and/or nonessential.
+ * An [`Entries`](./filter-reference.md#entriesfilter) filter whose task is to determine the pages' metadata (the list of entries, each with a name, type and path).
+ The [Filter Reference](./filter-reference.md) page has all the details about filters.
+5. Using the `thor docs:page [my_doc] [path]` command, check that the scraper works properly. Files will appear in the `public/docs/[my_doc]/` directory (but not inside the app as the command doesn't touch the index). `path` in this case refers to either the remote path (if using `UrlScraper`) or the local path (if using `FileScraper`).
+6. Generate the full documentation using the `thor docs:generate [my_doc] --force` command. Additionally, you can use the `--verbose` option to see which files are being created/updated/deleted (useful to see what changed since the last run), and the `--debug` option to see which URLs are being requested and added to the queue (useful to pin down which page adds unwanted URLs to the queue).
+7. Start the server, open the app, enable the documentation, and see how everything plays out.
+8. Tweak the scraper/filters and repeat 5) and 6) until the pages and metadata are ok.
+9. To customize the pages' styling, create an SCSS file in the `assets/stylesheets/pages/` directory and import it in both `application.css.scss` AND `application-dark.css.scss`. Both the file and CSS class should be named `_[type]` where [type] is equal to the scraper's `type` attribute (documentations with the same type share the same custom CSS and JS). Setting the type to `simple` will apply the general styling rules in `assets/stylesheets/pages/_simple.scss`, which can be used for documentations where little to no CSS changes are needed.
+10. To add syntax highlighting or execute custom JavaScript on the pages, create a file in the `assets/javascripts/views/pages/` directory (take a look at the other files to see how it works).
+11. Add the documentation's icon in the `public/icons/docs/[my_doc]/` directory, in both 16x16 and 32x32-pixels formats. It'll be added to the icon spritesheet after your pull request is merged.
+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.
+
+If the documentation includes more than a few hundreds pages and is available for download, try to scrape it locally (e.g. using `FileScraper`). It'll make the development process much faster and avoids putting too much load on the source site. (It's not a problem if your scraper is coupled to your local setup, just explain how it works in your pull request.)
+
+Finally, try to document your scraper and filters' behavior as much as possible using comments (e.g. why some URLs are ignored, HTML markup removed, metadata that way, etc.). It'll make updating the documentation much easier.
diff --git a/docs/filter-reference.md b/docs/filter-reference.md
new file mode 100644
index 00000000..f5c74c66
--- /dev/null
+++ b/docs/filter-reference.md
@@ -0,0 +1,224 @@
+**Table of contents:**
+
+* [Overview](#overview)
+* [Instance methods](#instance-methods)
+* [Core filters](#core-filters)
+* [Custom filters](#custom-filters)
+ - [CleanHtmlFilter](#cleanhtmlfilter)
+ - [EntriesFilter](#entriesfilter)
+
+## Overview
+
+Filters use the [HTML::Pipeline](https://github.com/jch/html-pipeline) library. They take an HTML string or [Nokogiri](http://nokogiri.org/) node as input, optionally perform modifications and/or extract information from it, and then outputs the result. Together they form a pipeline where each filter hands its output to the next filter's input. Every documentation page passes through this pipeline before being copied on the local filesystem.
+
+Filters are subclasses of the [`Docs::Filter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/filter.rb) class and require a `call` method. A basic implementation looks like this:
+
+```ruby
+module Docs
+ class CustomFilter < Filter
+ def call
+ doc
+ end
+ end
+end
+```
+
+Filters which manipulate the Nokogiri node object (`doc` and related methods) are _HTML filters_ and must not manipulate the HTML string (`html`). Vice-versa, filters which manipulate the string representation of the document are _text filters_ and must not manipulate the Nokogiri node object. The two types are divided into two stacks within the scrapers. These stacks are then combined into a pipeline that calls the HTML filters before the text filters (more details [here](./scraper-reference.md#filter-stacks)). This is to avoid parsing the document multiple times.
+
+The `call` method must return either `doc` or `html`, depending on the type of filter.
+
+## Instance methods
+
+* `doc` [Nokogiri::XML::Node]
+ The Nokogiri representation of the container element.
+ See [Nokogiri's API docs](http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node) for the list of available methods.
+
+* `html` [String]
+ The string representation of the container element.
+
+* `context` [Hash] **(frozen)**
+ The scraper's `options` along with a few additional keys: `:base_url`, `:root_url`, `:root_page` and `:url`.
+
+* `result` [Hash]
+ Used to store the page's metadata and pass back information to the scraper.
+ Possible keys:
+
+ - `:path` — the page's normalized path
+ - `:store_path` — the path where the page will be stored (equal to `:path` with `.html` at the end)
+ - `:internal_urls` — the list of distinct internal URLs found within the page
+ - `:entries` — the [`Entry`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/models/entry.rb) objects to add to the index
+
+* `css`, `at_css`, `xpath`, `at_xpath`
+ Shortcuts for `doc.css`, `doc.xpath`, etc.
+
+* `base_url`, `current_url`, `root_url` [Docs::URL]
+ Shortcuts for `context[:base_url]`, `context[:url]`, and `context[:root_url]` respectively.
+
+* `root_path` [String]
+ Shortcut for `context[:root_path]`.
+
+* `subpath` [String]
+ The sub-path from the base URL of the current URL.
+ _Example: if `base_url` equals `example.com/docs` and `current_url` equals `example.com/docs/file?raw`, the returned value is `/file`._
+
+* `slug` [String]
+ The `subpath` removed of any leading slash or `.html` extension.
+ _Example: if `subpath` equals `/dir/file.html`, the returned value is `dir/file`._
+
+* `root_page?` [Boolean]
+ Returns `true` if the current page is the root page.
+
+* `initial_page?` [Boolean]
+ Returns `true` if the current page is the root page or its subpath is one of the scraper's `initial_paths`.
+
+## Core filters
+
+* [`ContainerFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/container.rb) — changes the root node of the document (remove everything outside)
+* [`CleanHtmlFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/clean_html.rb) — removes HTML comments, `