From 26099d657ca03a4048697313ac2cce6e98168689 Mon Sep 17 00:00:00 2001 From: Daniel Dourvaris Date: Sun, 9 Jul 2017 11:09:18 +0200 Subject: [PATCH] debug-style: moved from pylons controller to pyramid view. --- .../debug_style/__init__.py} | 37 ++++++------ rhodecode/apps/debug_style/views.py | 58 +++++++++++++++++++ rhodecode/config/middleware.py | 1 + rhodecode/config/routing.py | 9 --- rhodecode/public/js/rhodecode/routes.js | 2 + rhodecode/templates/base/base.mako | 2 +- rhodecode/templates/debug_style/alerts.html | 2 +- rhodecode/templates/debug_style/buttons.html | 2 +- .../templates/debug_style/code-block.html | 2 +- .../debug_style/collapsable-content.html | 2 +- .../debug_style/form-elements-small.html | 2 +- .../templates/debug_style/form-elements.html | 2 +- .../templates/debug_style/form-inline.html | 2 +- .../templates/debug_style/form-vertical.html | 2 +- rhodecode/templates/debug_style/forms.html | 2 +- rhodecode/templates/debug_style/icons.html | 2 +- rhodecode/templates/debug_style/index.html | 38 ++++++------ rhodecode/templates/debug_style/labels.html | 2 +- .../debug_style/layout-form-sidebar.html | 2 +- rhodecode/templates/debug_style/login.html | 2 +- rhodecode/templates/debug_style/panels.html | 2 +- .../templates/debug_style/tables-wide.html | 2 +- rhodecode/templates/debug_style/tables.html | 2 +- .../templates/debug_style/typography.html | 2 +- 24 files changed, 118 insertions(+), 63 deletions(-) rename rhodecode/{controllers/debug_style.py => apps/debug_style/__init__.py} (57%) create mode 100644 rhodecode/apps/debug_style/views.py diff --git a/rhodecode/controllers/debug_style.py b/rhodecode/apps/debug_style/__init__.py similarity index 57% rename from rhodecode/controllers/debug_style.py rename to rhodecode/apps/debug_style/__init__.py index c7a5db01..8d44eb38 100644 --- a/rhodecode/controllers/debug_style.py +++ b/rhodecode/apps/debug_style/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2014-2017 RhodeCode GmbH +# Copyright (C) 2016-2017 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License, version 3 @@ -17,23 +17,26 @@ # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ - -""" -Provides a few url endpoints that help understanding the styling concept. -""" -import os - -from pylons import tmpl_context as c - -from rhodecode.lib.base import BaseController, render +from rhodecode.apps._base import ADMIN_PREFIX +from rhodecode.lib.utils2 import str2bool -class DebugStyleController(BaseController): +def debug_style_enabled(info, request): + return str2bool(request.registry.settings.get('debug_style')) + + +def includeme(config): + config.add_route( + name='debug_style_home', + pattern=ADMIN_PREFIX + '/debug_style', + custom_predicates=(debug_style_enabled,)) + config.add_route( + name='debug_style_template', + pattern=ADMIN_PREFIX + '/debug_style/t/{t_path}', + custom_predicates=(debug_style_enabled,)) + + # Scan module for configuration decorators. + config.scan() + - def index(self): - c.active = 'index' - return render('debug_style/index.html') - def template(self, t_path): - c.active = os.path.splitext(t_path)[0] - return render('debug_style/' + t_path) diff --git a/rhodecode/apps/debug_style/views.py b/rhodecode/apps/debug_style/views.py new file mode 100644 index 00000000..9ea9ab05 --- /dev/null +++ b/rhodecode/apps/debug_style/views.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2016-2017 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +import os +import logging + +from pyramid.view import view_config +from pyramid.renderers import render_to_response +from rhodecode.apps._base import BaseAppView + +log = logging.getLogger(__name__) + + +class DebugStyleView(BaseAppView): + def load_default_context(self): + c = self._get_local_tmpl_context() + self._register_global_c(c) + return c + + @view_config( + route_name='debug_style_home', request_method='GET', + renderer=None) + def index(self): + c = self.load_default_context() + c.active = 'index' + + return render_to_response( + 'debug_style/index.html', self._get_template_context(c), + request=self.request) + + @view_config( + route_name='debug_style_template', request_method='GET', + renderer=None) + def template(self): + t_path = self.request.matchdict['t_path'] + c = self.load_default_context() + c.active = os.path.splitext(t_path)[0] + + return render_to_response( + 'debug_style/' + t_path, self._get_template_context(c), + request=self.request) \ No newline at end of file diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py index 50b56f85..3d87771c 100644 --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -305,6 +305,7 @@ def includeme(config): config.include('rhodecode.apps.svn_support') config.include('rhodecode.apps.gist') + config.include('rhodecode.apps.debug_style') config.include('rhodecode.tweens') config.include('rhodecode.api') diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py index 3bb129cd..86c9cee1 100644 --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -369,15 +369,6 @@ def make_map(config): m.connect('admin_defaults_repositories', '/defaults/repositories', action='index', conditions={'method': ['GET']}) - # ADMIN DEBUG STYLE ROUTES - if str2bool(config.get('debug_style')): - with rmap.submapper(path_prefix=ADMIN_PREFIX + '/debug_style', - controller='debug_style') as m: - m.connect('debug_style_home', '', - action='index', conditions={'method': ['GET']}) - m.connect('debug_style_template', '/t/{t_path}', - action='template', conditions={'method': ['GET']}) - # ADMIN SETTINGS ROUTES with rmap.submapper(path_prefix=ADMIN_PREFIX, controller='admin/settings') as m: diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js index acd4c279..6f5e2f22 100644 --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -170,5 +170,7 @@ function registerRCRoutes() { pyroutes.register('gist_show_rev', '/_admin/gists/%(gist_id)s/%(revision)s', ['gist_id', 'revision']); pyroutes.register('gist_show_formatted', '/_admin/gists/%(gist_id)s/%(revision)s/%(format)s', ['gist_id', 'revision', 'format']); pyroutes.register('gist_show_formatted_path', '/_admin/gists/%(gist_id)s/%(revision)s/%(format)s/%(f_path)s', ['gist_id', 'revision', 'format', 'f_path']); + pyroutes.register('debug_style_home', '/_admin/debug_style', []); + pyroutes.register('debug_style_template', '/_admin/debug_style/t/%(t_path)s', ['t_path']); pyroutes.register('apiv2', '/_admin/api', []); } diff --git a/rhodecode/templates/base/base.mako b/rhodecode/templates/base/base.mako index 63c343e7..a9e71f98 100644 --- a/rhodecode/templates/base/base.mako +++ b/rhodecode/templates/base/base.mako @@ -425,7 +425,7 @@ % endif % if c.debug_style:
  • - +
  • diff --git a/rhodecode/templates/debug_style/alerts.html b/rhodecode/templates/debug_style/alerts.html index 496de5d5..02b12122 100644 --- a/rhodecode/templates/debug_style/alerts.html +++ b/rhodecode/templates/debug_style/alerts.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/buttons.html b/rhodecode/templates/debug_style/buttons.html index c1322212..50d8b796 100644 --- a/rhodecode/templates/debug_style/buttons.html +++ b/rhodecode/templates/debug_style/buttons.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/code-block.html b/rhodecode/templates/debug_style/code-block.html index 247127ec..52c76840 100644 --- a/rhodecode/templates/debug_style/code-block.html +++ b/rhodecode/templates/debug_style/code-block.html @@ -3,7 +3,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/collapsable-content.html b/rhodecode/templates/debug_style/collapsable-content.html index f5fb4b84..0f948c2f 100644 --- a/rhodecode/templates/debug_style/collapsable-content.html +++ b/rhodecode/templates/debug_style/collapsable-content.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/form-elements-small.html b/rhodecode/templates/debug_style/form-elements-small.html index 8fc1faac..2a99322e 100644 --- a/rhodecode/templates/debug_style/form-elements-small.html +++ b/rhodecode/templates/debug_style/form-elements-small.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/form-elements.html b/rhodecode/templates/debug_style/form-elements.html index 0bd429a9..9a1e9956 100644 --- a/rhodecode/templates/debug_style/form-elements.html +++ b/rhodecode/templates/debug_style/form-elements.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/form-inline.html b/rhodecode/templates/debug_style/form-inline.html index 107b1a89..16f916ab 100644 --- a/rhodecode/templates/debug_style/form-inline.html +++ b/rhodecode/templates/debug_style/form-inline.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/form-vertical.html b/rhodecode/templates/debug_style/form-vertical.html index c3b21706..97b23bd3 100644 --- a/rhodecode/templates/debug_style/form-vertical.html +++ b/rhodecode/templates/debug_style/form-vertical.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/forms.html b/rhodecode/templates/debug_style/forms.html index 7149d33d..c9b8821e 100644 --- a/rhodecode/templates/debug_style/forms.html +++ b/rhodecode/templates/debug_style/forms.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/icons.html b/rhodecode/templates/debug_style/icons.html index 54f2d2af..85ff5f97 100644 --- a/rhodecode/templates/debug_style/icons.html +++ b/rhodecode/templates/debug_style/icons.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/index.html b/rhodecode/templates/debug_style/index.html index 53baa63f..9690a9e2 100644 --- a/rhodecode/templates/debug_style/index.html +++ b/rhodecode/templates/debug_style/index.html @@ -51,29 +51,29 @@ <%def name="sidebar()"> \ No newline at end of file diff --git a/rhodecode/templates/debug_style/labels.html b/rhodecode/templates/debug_style/labels.html index 5bd2de5b..9e957cc7 100644 --- a/rhodecode/templates/debug_style/labels.html +++ b/rhodecode/templates/debug_style/labels.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/layout-form-sidebar.html b/rhodecode/templates/debug_style/layout-form-sidebar.html index c1944ad1..770ee562 100644 --- a/rhodecode/templates/debug_style/layout-form-sidebar.html +++ b/rhodecode/templates/debug_style/layout-form-sidebar.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/login.html b/rhodecode/templates/debug_style/login.html index 78a3ec32..a58034b7 100644 --- a/rhodecode/templates/debug_style/login.html +++ b/rhodecode/templates/debug_style/login.html @@ -3,7 +3,7 @@ <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/panels.html b/rhodecode/templates/debug_style/panels.html index 7adac9c7..41b7378a 100644 --- a/rhodecode/templates/debug_style/panels.html +++ b/rhodecode/templates/debug_style/panels.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/tables-wide.html b/rhodecode/templates/debug_style/tables-wide.html index 33aeedfb..2ec7a7be 100644 --- a/rhodecode/templates/debug_style/tables-wide.html +++ b/rhodecode/templates/debug_style/tables-wide.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/tables.html b/rhodecode/templates/debug_style/tables.html index fe6fa592..f0a69a4f 100644 --- a/rhodecode/templates/debug_style/tables.html +++ b/rhodecode/templates/debug_style/tables.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active} diff --git a/rhodecode/templates/debug_style/typography.html b/rhodecode/templates/debug_style/typography.html index b2fdb737..39de5d70 100644 --- a/rhodecode/templates/debug_style/typography.html +++ b/rhodecode/templates/debug_style/typography.html @@ -2,7 +2,7 @@ <%inherit file="/debug_style/index.html"/> <%def name="breadcrumbs_links()"> - ${h.link_to(_('Style'), h.url('debug_style_home'))} + ${h.link_to(_('Style'), h.route_path('debug_style_home'))} » ${c.active}