Skip to content

Commit

Permalink
Add version warning extension (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
danroth27 committed Jun 26, 2016
1 parent 35072bd commit 08cefb4
Show file tree
Hide file tree
Showing 29 changed files with 117 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,4 @@ FakesAssemblies/
project.lock.json
**/sample/**/wwwroot/lib/
**/samples/**/wwwroot/lib/
__pycache__/
2 changes: 2 additions & 0 deletions aspnet/client-side/angular.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Using Angular for Single Page Applications (SPAs)
=================================================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/client-side/bundling-and-minification.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

Bundling and Minification
=========================

Expand Down
8 changes: 6 additions & 2 deletions aspnet/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
sys.path.append(os.path.abspath('ext'))

extensions = [
'sphinx.ext.intersphinx',
'sphinxcontrib.dotnetdomain']
'sphinxcontrib.dotnetdomain',
'versionwarning']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates', '../common/_templates']
Expand All @@ -56,7 +59,7 @@
# built documents.
#
# The short X.Y version.
# version = '0.0.1'
version = '1.0.0'
# The full version, including alpha/beta/rc tags.
# release = '0.0.1'

Expand Down Expand Up @@ -374,3 +377,4 @@ def setup(app):
'api': ('http://docs.asp.net/projects/api/en/latest', '../common/api.inv')
}

versionwarning_console = False
58 changes: 58 additions & 0 deletions aspnet/ext/versionwarning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
"""
Add the ability to specify the version for a specific page.
This allows you to put metadata at the top of your document::
:version: 2.3
This version should be the version of the project that this page or API targets.
If you configure ``versionwarning_node`` to True (default),
then it will generate an in-page warning for out of date versions.
If you configure ``versionwarning_console`` to True (default),
then it will output a warning on the console.
"""


from collections import defaultdict

from sphinx.util.console import red, bold
from docutils import nodes


def process_meta(app, doctree, fromdocname):
env = app.builder.env
env.page_to_version = defaultdict(set)
env.version_to_page = defaultdict(set)

# index metadata
for pagename, metadata in iter(env.metadata.items()):
if 'version' in metadata:
version = metadata['version']
env.page_to_version[pagename] = version
env.version_to_page[version].add(pagename)

if fromdocname == pagename:

# Alert on outdated version
current_version = env.config['version']
if version != current_version:
text = 'This page documents version {old} and has not yet been updated for version {new}'.format(
old=version,
new=current_version,
)

if app.config['versionwarning_node']:
prose = nodes.paragraph(text, text)
warning = nodes.warning(prose, prose)
doctree.insert(0, warning)
if app.config['versionwarning_console']:
app.warn(bold('[Version Warning: %s] ' % pagename) + red(text))


def setup(app):
app.connect('doctree-resolved', process_meta)
app.add_config_value('versionwarning_node', True, 'html')
app.add_config_value('versionwarning_console', True, 'html')
2 changes: 2 additions & 0 deletions aspnet/fundamentals/app-state.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Managing Application State
==========================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/fundamentals/dependency-injection.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

.. _fundamentals-dependency-injection:

Dependency Injection
Expand Down
2 changes: 2 additions & 0 deletions aspnet/fundamentals/environments.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Working with Multiple Environments
==================================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/fundamentals/error-handling.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Error Handling
==============

Expand Down
2 changes: 2 additions & 0 deletions aspnet/fundamentals/owin.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

OWIN
====

Expand Down
2 changes: 2 additions & 0 deletions aspnet/fundamentals/routing.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

Routing
=======
By `Steve Smith`_
Expand Down
2 changes: 2 additions & 0 deletions aspnet/fundamentals/servers.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Servers
=======

Expand Down
2 changes: 2 additions & 0 deletions aspnet/migration/http-modules.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Migrating HTTP Modules to Middleware
====================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.AspNetCore.Http": "1.0.0-rc2-16272",
"Microsoft.AspNet.Http": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
Expand Down
2 changes: 2 additions & 0 deletions aspnet/migration/mvc.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

Migrating From ASP.NET MVC to ASP.NET Core MVC
================================================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/migration/webapi.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Migrating from ASP.NET Web API
==============================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/mvc/controllers/dependency-injection.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

.. _dependency-injection-controllers:

Dependency Injection and Controllers
Expand Down
2 changes: 2 additions & 0 deletions aspnet/mvc/controllers/testing.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Testing Controller Logic
========================
By `Steve Smith`_
Expand Down
2 changes: 2 additions & 0 deletions aspnet/mvc/views/partial.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

Partial Views
=============

Expand Down
2 changes: 2 additions & 0 deletions aspnet/mvc/views/view-components.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

View Components
================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/mvc/views/working-with-forms.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Working with Forms
====================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/performance/caching/distributed.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Working with a Distributed Cache
================================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/performance/caching/memory.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

In Memory Caching
=================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/performance/caching/response.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Response Caching
================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/security/authentication/2fa.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-beta8

.. _security-authentication-2fa:

Two-factor authentication with SMS
Expand Down
2 changes: 2 additions & 0 deletions aspnet/security/authentication/accconfirm.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-beta7

.. _security-authentication-account-confirmation:

Account Confirmation and Password Recovery
Expand Down
4 changes: 3 additions & 1 deletion aspnet/security/cors.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Enabling Cross-Origin Requests (CORS)
:version: 1.0.0-rc1

Enabling Cross-Origin Requests (CORS)
=====================================

By `Mike Wasson`_
Expand Down
2 changes: 2 additions & 0 deletions aspnet/testing/integration-testing.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc1

Integration Testing
===================

Expand Down
2 changes: 2 additions & 0 deletions aspnet/testing/unit-testing.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:version: 1.0.0-rc2

Unit Testing
============

Expand Down

0 comments on commit 08cefb4

Please sign in to comment.