8000 Use symfony.com theme on Platform.sh builds · symfony/symfony-docs@9d2bc8f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d2bc8f

Browse files
wouterjweaverryan
authored andcommitted
Use symfony.com theme on Platform.sh builds
1 parent dd20bbb commit 9d2bc8f

File tree

7 files changed

+273
-3
lines changed

7 files changed

+273
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/_build
22
/_exts
3+
*.pyc

.platform/_exts/symfonycom/__init__.py

Whitespace-only changes.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
from sphinx.highlighting import lexers, PygmentsBridge
2+
from pygments.style import Style
3+
from pygments.formatters import HtmlFormatter
4+
from pygments.token import Keyword, Name, Comment, String, Error, \
5+
Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
6+
7+
from sphinx.writers.html import HTMLTranslator
8+
from docutils import nodes
9+
from sphinx.locale import admonitionlabels, lazy_gettext
10+
11+
customadmonitionlabels = admonitionlabels
12+
l_ = lazy_gettext
13+
customadmonitionlabels['best-practice'] = l_('Best Practice')
14+
15+
def _getType(path):
16+
return path[:path.find('/')]
17+
18+
def _isIndex(path):
19+
return 'index' in path
20+
21+
class SensioHTMLTranslator(HTMLTranslator):
22+
def __init__(self, builder, *args, **kwds):
23+
HTMLTranslator.__init__(self, builder, *args, **kwds)
24+
builder.templates.environment.filters['get_type'] = _getType
25+
builder.templates.environment.tests['index'] = _isIndex
26+
self.highlightlinenothreshold = 0
27+
28+
def visit_literal(self, node):
29+
self.body.append(self.starttag(node, 'tt', '', CLASS='docutils literal'))
30+
self.body.append('<code>')
31+
32+
def depart_literal(self, node):
33+
self.body.append('</code>')
34+
self.body.append('</tt>')
35+
36+
def visit_admonition(self, node, name=''):
37+
self.body.append(self.starttag(node, 'div', CLASS=('admonition-wrapper')))
38+
self.body.append('<div class="' + name + '"></div>')
39+
self.body.append('<div class="admonition admonition-' + name + '">')
40+
if name and name != 'seealso':
41+
node.insert(0, nodes.title(name, customadmonitionlabels[name]))
42+
self.set_first_last(node)
43+
44+
def depart_admonition(self, node=None):
45+
self.body.append('</div></div>\n')
46+
47+
def visit_sidebar(self, node):
48+
self.body.append(self.starttag(node, 'div', CLASS=('admonition-wrapper')))
49+
self.body.append('<div class="sidebar"></div>')
50+
self.body.append('<div class="admonition admonition-sidebar">')
51+
self.set_first_last(node)
52+
self.in_sidebar = 1
53+
54+
def depart_sidebar(self, node):
55+
self.body.append('</div></div>\n')
56+
self.in_sidebar = None
57+
58+
# overriden to add a new highlight div around each block
59+
def visit_literal_block(self, node):
60+
if node.rawsource != node.astext():
61+
# most probably a parsed-literal block -- don't highlight
62+
return BaseTranslator.visit_literal_block(self, node)
63+
lang = self.highlightlang
64+
linenos = node.rawsource.count('\n') >= \
65+
self.highlightlinenothreshold - 1
66+
highlight_args = node.get('highlight_args', {})
67+
if node.has_key('language'):
68+
# code-block directives
69+
lang = node['language']
70+
highlight_args['force'] = True
71+
if node.has_key('linenos'):
72+
linenos = node['linenos']
73+
def warner(msg):
74+
self.builder.warn(msg, (self.builder.current_docname, node.line))
75+
highlighted = self.highlighter.highlight_block(
76+
node.rawsource, lang, warn=warner, linenos=linenos,
77+
**highlight_args)
78+
starttag = self.starttag(node, 'div', suffix='',
79+
CLASS='highlight-%s' % lang)
80+
self.body.append('<div class="literal-block">' + starttag + highlighted + '</div></div>\n')
81+
raise nodes.SkipNode
< F438 /td>82+
83+
class SensioStyle(Style):
84+
background_color = "#000000"
85+
default_style = ""
86+
87+
styles = {
88+
# No corresponding class for the following:
89+
#Text: "", # class: ''
90+
Whitespace: "underline #f8f8f8", # class: 'w'
91+
Error: "#a40000 border:#ef2929", # class: 'err'
92+
Other: "#ffffff", # class 'x'
93+
94+
Comment: "italic #B729D9", # class: 'c'
95+
Comment.Single: "italic #B729D9", # class: 'c1'
96+
Comment.Multiline: "italic #B729D9", # class: 'cm'
97+
Comment.Preproc: "noitalic #aaa", # class: 'cp'
98+
99+
Keyword: "#FF8400", # class: 'k'
100+
Keyword.Constant: "#FF8400", # class: 'kc'
101+
Keyword.Declaration: "#FF8400", # class: 'kd'
102+
Keyword.Namespace: "#FF8400", # class: 'kn'
103+
Keyword.Pseudo: "#FF8400", # class: 'kp'
104+
Keyword.Reserved: "#FF8400", # class: 'kr'
105+
Keyword.Type: "#FF8400", # class: 'kt'
106+
107+
Operator: "#E0882F", # class: 'o'
108+
Operator.Word: "#E0882F", # class: 'ow' - like keywords
109+
110+
Punctuation: "#999999", # class: 'p'
111+
112+
# because special names such as Name.Class, Name.Function, etc.
113+
# are not recognized as such later in the parsing, we choose them
114+
# to look the same as ordinary variables.
115+
Name: "#ffffff", # class: 'n'
116+
Name.Attribute: "#ffffff", # class: 'na' - to be revised
117+
Name.Builtin: "#ffffff", # class: 'nb'
118+
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
119+
Name.Class: "#ffffff", # class: 'nc' - to be revised
120+
Name.Constant: "#ffffff", # class: 'no' - to be revised
121+
Name.Decorator: "#888", # class: 'nd' - to be revised
122+
Name.Entity: "#ce5c00", # class: 'ni'
123+
Name.Exception: "#cc0000", # class: 'ne'
124+
Name.Function: "#ffffff", # class: 'nf'
125+
Name.Property: "#ffffff", # class: 'py'
126+
Name.Label: "#f57900", # class: 'nl'
127+
Name.Namespace: "#ffffff", # class: 'nn' - to be revised
128+
Name.Other: "#ffffff", # class: 'nx'
129+
Name.Tag: "#cccccc", # class: 'nt' - like a keyword
130+
Name.Variable: "#ffffff", # class: 'nv' - to be revised
131+
Name.Variable.Class: "#ffffff", # class: 'vc' - to be revised
132+
Name.Variable.Global: "#ffffff", # class: 'vg' - to be revised
133+
Name.Variable.Instance: "#ffffff", # class: 'vi' - to be revised
134+
135+
Number: "#1299DA", # class: 'm'
136+
137+
Literal: "#ffffff", # class: 'l'
138+
Literal.Date: "#ffffff", # class: 'ld'
139+
140+
String: "#56DB3A", # class: 's'
141+
String.Backtick: "#56DB3A", # class: 'sb'
142+
String.Char: "#56DB3A", # class: 'sc'
143+
String.Doc: "italic #B729D9", # class: 'sd' - like a comment
144+
String.Double: "#56DB3A", # class: 's2'
145+
String.Escape: "#56DB3A", # class: 'se'
146+
String.Heredoc: "#56DB3A", # class: 'sh'
147+
String.Interpol: "#56DB3A", # class: 'si'
148+
String.Other: "#56DB3A", # class: 'sx'
149+
String.Regex: "#56DB3A", # class: 'sr'
150+
String.Single: "#56DB3A", # class: 's1'
151+
String.Symbol: "#56DB3A", # class: 'ss'
152+
153+
Generic: "#ffffff", # class: 'g'
154+
Generic.Deleted: "#a40000", # class: 'gd'
155+
Generic.Emph: "italic #ffffff", # class: 'ge'
156+
Generic.Error: "#ef2929", # class: 'gr'
157+
Generic.Heading: "#000080", # class: 'gh'
158+
Generic.Inserted: "#00A000", # class: 'gi'
159+
Generic.Output: "#888", # class: 'go'
160+
Generic.Prompt: "#745334", # class: 'gp'
161+
Generic.Strong: "bold #ffffff", # class: 'gs'
162+
Generic.Subheading: "bold #800080", # class: 'gu'
163+
Generic.Traceback: "bold #a40000", # class: 'gt'
164+
}
165+
166+
def setup(app):
167+
app.set_translator('html', SensioHTMLTranslator)

.platform/_templates/globaltoc.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div class=submenu>
2+
{% set menu = [
3+
('The Book', 'book/index'),
4+
('The Cookbook', 'cookbook/index'),
5+
('The Components', 'components/index'),
6+
('The Best Practices', 'best_practices/index'),
7+
('The Quick Tour', 'quick_tour/index'),
8+
('Reference', 'reference/index'),
9+
('Index', 'genindex'),
10+
('Contributing', 'contributing/index')
11+
] %}
12+
13+
<ul class="list_submenu list-unstyled">
14+
{% for name, doc in menu %}
15+
<li {% if loop.first %}class="first"{% endif %}>
16+
<a href="{{ pathto(doc) }}">{{ name }}</a>
17+
</li>
18+
{% endfor %}
19+
</ul>
20+
</div>

.platform/_templates/layout.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{% extends '!layout.html' %}
2+
3+
{% set css_files = ['http://symfony.com/css/compiled/v5/all.css?v=4'] %}
4+
{# make sure the Sphinx stylesheet isn't loaded #}
5+
{% set style = '' %}
6+
{% set isIndex = pagename is index %}
7+
8+
{% block extrahead %}
9+
{# add JS to support tabs #}
10+
<script src="http://symfony.com/js/v5/all.js?v=4"></script>
11+
12+
{# pygment's styles are still loaded, undo some unwanted styles #}
13+
<style>
14+
.highlight .k { font-weight: normal; }
15+
.doc { background: none; }
16+
</style>
17+
{% endblock %}
18+
19+
{% block header %}
20+
{# ugly way, now we have 2 body tags, but styles rely on these classes #}
21+
<body class="{{ pagename|get_type }} {% if isIndex %}doc_index{% else %}doc_article{% endif %} doc">
22+
{% endblock %}
23+
24+
{% block content %}
25+
<div class="container"><div id="page-content">
26+
<div class="row">
27+
{%- if render_sidebar %}
28+
<div id="sidebar" class="col-sm-3">
29+
<div id="sidebar-content">
30+
{%- include "globaltoc.html" %}
31+
32+
{% if not isIndex %}
33+
{%- include "localtoc.html" %}
34+
{% endif %}
35+
</div>
36+
</div>
37+
{%- endif %}
38+
39+
<div id="main" class="col-sm-9">
40+
<ol class=breadcrumb>
41+
<li><a href="#">Home</a></li>
42+
<li><a href="#">Documentation</a></li>
43+
{% for parent in parents %}
44+
<li><a href="{{ parent.link|e }}">{{ parent.title }}</a></li>
45+
{% endfor %}
46+
<li class=active>{{ title }}</li>
47+
</ol>
48+
49+
<h1 class="content_title">{{ title }}</h1>
50+
51+
<div class=page>
52+
{% block body %}{% endblock %}
53+
</div>
54+
55+
{% if prev and next %}
56+
<div class=navigation>
57+
<a href="{{ prev.link|e }}">« {{ prev.title|striptags|e }}</a>
58+
<span class=separator>|</span>
59+
<a href="{{ next.link|e }}">{{ next.title|striptags|e }} »</a>
60+
</div>
61+
{% endif %}
62+
</div>
63+
</div>
64+
</div>
65+
{% endblock %}
66+
67+
{# relbar1 is at the top and should not render the quick navigation #}
68+
{% block relbar1 %}{% endblock %}
69+
{% block relbar2 %}{% endblock %}
70+
71+
{# remove "generated by sphinx" footer #}
72+
{% block footer %}{% endblock %}

.platform/_templates/localtoc.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="toc">
2+
<h4>{{ _('Table Of Contents') }}</h4>
3+
<div class=toc-content>
4+
{{ toc }}
5+
</div>
6+
</div>

conf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#sys.path.insert(0, os.path.abspath('.'))
2020

2121
sys.path.append(os.path.abspath('_exts'))
22+
sys.path.append(os.path.abspath('.platform/_exts'))
2223

2324
# adding PhpLexer
2425
from sphinx.highlighting import lexers
@@ -34,11 +35,14 @@
3435

3536
# Add any Sphinx extension module names here, as strings. They can be extensions
3637
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
37-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo',
38-
'sensio.sphinx.refinclude', 'sensio.sphinx.configurationblock', 'sensio.sphinx.phpcode', 'sensio.sphinx.bestpractice']
38+
extensions = [
39+
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo',
40+
'sensio.sphinx.refinclude', 'sensio.sphinx.configurationblock', 'sensio.sphinx.phpcode', 'sensio.sphinx.bestpractice', 'sensio.sphinx.codeblock',
41+
'symfonycom.sphinx'
42+
]
3943

4044
# Add any paths that contain templates here, relative to this directory.
41-
templates_path = ['_templates']
45+
templates_path = ['.platform/_templates']
4246

4347
# The suffix of source filenames.
4448
source_suffix = '.rst'

0 commit comments

Comments
 (0)
0