Skip to content

Commit 44b0145

Browse files
ralf401dvuckovic
andauthored
Fixes #701 - Unify and fix code blocks and add copy button
--------- Co-authored-by: Dusan Vuckovic <[email protected]>
1 parent 29b1384 commit 44b0145

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1753
-1255
lines changed

_static/theme/theme_overrides.css

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
}
3131
}
3232

33-
.collapsing-code-block__toggle {
33+
.collapsing-code-toggle {
3434
position: absolute;
3535
top: .25rem;
3636
right: .25rem;
3737
display: block;
3838
padding: .25rem .5rem;
39-
padding: 6px 12px 8px;
39+
padding: 4px 12px 7px;
40+
color: #57606a;
41+
background-color: #f6f8fa;
4042
border: 1px solid rgba(0,0,0,.1);
4143
box-shadow: inset 0 1px 2px -1px hsla(0,0%,100%,.5), inset 0 -2px 0 0 rgba(0,0,0,.1);
4244
-webkit-user-drag: none;
@@ -46,12 +48,26 @@
4648
user-select: none;
4749
}
4850

49-
.collapsing-code-block > .collapsing-code-block__toggle::after {
51+
.collapsing-code-toggle:hover {
52+
background-color: rgb(235, 235, 235);
53+
}
54+
55+
.copybtn + .collapsing-code-toggle {
56+
right: 2.3rem;
57+
}
58+
59+
.collapsing-code-block ~ .collapsing-code-toggle::after {
5060
content: "More";
61+
display: block;
62+
font-size: 12px;
63+
line-height: normal;
5164
}
5265

53-
.collapsing-code-block--open > .collapsing-code-block__toggle::after {
66+
.collapsing-code-block--open ~ .collapsing-code-toggle::after {
5467
content: "Less";
68+
display: block;
69+
font-size: 12px;
70+
line-height: normal;
5571
}
5672

5773
.highlight span.err {
@@ -97,3 +113,10 @@ article ul li ul {
97113
width: 70px;
98114
height: 61px;
99115
}
116+
117+
button.copybtn {
118+
opacity: 1;
119+
border-radius: 0;
120+
border: 1px solid rgba(0,0,0,.1);
121+
box-shadow: inset 0 1px 2px -1px hsla(0,0%,100%,.5), inset 0 -2px 0 0 rgba(0,0,0,.1);
122+
}

_static/theme/zammad_overrides.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
/* Custom overrides */
2-
// No oversized <pre>, please - Thanks to @TJemxx
3-
function collapseLongCodeBlocks() {
4-
const maxHeight = 250;
5-
6-
document.querySelectorAll('pre').forEach((el, i) => {
7-
if (el.clientHeight <= maxHeight) return;
8-
9-
el.classList.add('collapsing-code-block');
10-
if (el.querySelector(`.collapsing-code-block__toggle`)) return;
11-
12-
const button = document.createElement('button');
13-
button.classList.add('collapsing-code-block__toggle');
14-
button.onclick = (event) => {
15-
event.target.parentElement.classList.toggle('collapsing-code-block--open')
16-
};
17-
el.appendChild(button);
18-
});
19-
}
20-
21-
window.addEventListener('load', () => {
22-
collapseLongCodeBlocks();
23-
24-
// click any <a data-tab="..."></a> link
25-
// to manually re-compute if any code blocks need to be collapsed
26-
document.querySelectorAll('a').forEach((el) => {
27-
if ('tab' in el.dataset) el.onclick = collapseLongCodeBlocks;
28-
});
29-
}, false);
1+
/* Custom overrides */
2+
// No oversized <pre>, please - Thanks to @TJemxx
3+
function collapseLongCodeBlocks() {
4+
const maxHeight = 250;
5+
6+
document.querySelectorAll('pre').forEach((el, i) => {
7+
if (el.clientHeight <= maxHeight) return;
8+
9+
el.classList.add('collapsing-code-block');
10+
if (el.querySelector(`.collapsing-code-toggle`)) return;
11+
12+
const button = document.createElement('button');
13+
button.classList.add('collapsing-code-toggle');
14+
button.onclick = (event) => {
15+
console.debug('onclick', event.target)
16+
event.target.parentElement.querySelector('.collapsing-code-block').classList.toggle('collapsing-code-block--open')
17+
};
18+
el.parentElement.appendChild(button);
19+
});
20+
}
21+
22+
window.addEventListener('load', () => {
23+
collapseLongCodeBlocks();
24+
25+
// click any <a data-tab="..."></a> link
26+
// to manually re-compute if any code blocks need to be collapsed
27+
document.querySelectorAll('a').forEach((el) => {
28+
if ('tab' in el.dataset) el.onclick = collapseLongCodeBlocks;
29+
});
30+
}, false);
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
.. code-block:: sh
1+
Package installation:
2+
3+
.. code-block:: console
24
3-
# package installation
45
$ zammad run rails c
56
6-
# source installation
7+
Source installation:
8+
9+
.. code-block:: console
10+
711
$ rails c

admin/console.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ a shell (e.g. for automation).
3535

3636
.. tab:: Docker Installation
3737

38-
.. code-block:: sh
38+
.. code-block:: console
3939
4040
$ docker compose run --rm zammad-railsserver bundle exec rails r '{COMMAND}'
4141
4242
.. tab:: Package Installation
4343

44-
.. code-block:: sh
44+
.. code-block:: console
4545
4646
$ zammad run rails r '{COMMAND}'
4747
4848
.. tab:: Source/Development Installation
4949

50-
.. code-block:: sh
50+
.. code-block:: console
5151
5252
$ rails r '{COMMAND}'
5353
@@ -63,7 +63,7 @@ It allows you to run several commands inside it.
6363

6464
.. tab:: Docker Installation
6565

66-
.. code-block:: sh
66+
.. code-block:: console
6767
6868
$ docker compose run --rm zammad-railsserver bundle exec rails c
6969
@@ -73,13 +73,13 @@ It allows you to run several commands inside it.
7373

7474
.. tab:: Package Installation
7575

76-
.. code-block:: sh
76+
.. code-block:: console
7777
78-
$ $ zammad run rails c
78+
$ zammad run rails c
7979
8080
.. tab:: Source/Development Installation
8181

82-
.. code-block:: sh
82+
.. code-block:: console
8383
8484
$ rails c
8585
@@ -94,29 +94,35 @@ It allows you to run several commands inside it.
9494
the environment variable ``ZAMMAD_SAFE_MODE=1``. With this setting enabled,
9595
the availability of these services will be ignored.
9696

97+
**Set variable and run rails console:**
98+
9799
.. tabs::
98100

99-
.. code-tab:: console Package Installation
101+
.. tab:: Package Installation
102+
103+
104+
.. code-block:: console
105+
106+
$ ZAMMAD_SAFE_MODE=1 zammad run rails c
107+
108+
.. tab:: Source Installation
109+
110+
.. code-block:: console
100111
101-
$ ZAMMAD_SAFE_MODE=1 zammad run rails c
102-
Zammad is running in safe mode. Any third-party services like Redis are ignored.
112+
$ ZAMMAD_SAFE_MODE=1 rails c
103113
104-
There was an error trying to connect to Redis via redis://localhost:6379.
105-
Please provide a Redis instance at localhost:6379 or set REDIS_URL to point to a different location.
106-
#<Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)>
107-
Loading production environment (Rails 6.1.7.3)
108-
3.1.3 :001 >
114+
**This gives you a response like this:**
109115

110-
.. code-tab:: console Source Installation
116+
.. code-block:: text
117+
:class: no-copybutton
111118
112-
$ ZAMMAD_SAFE_MODE=1 rails c
113-
Zammad is running in safe mode. Any third-party services like Redis are ignored.
119+
Zammad is running in safe mode. Any third-party services like Redis are ignored.
114120
115-
There was an error trying to connect to Redis via redis://localhost:6379.
116-
Please provide a Redis instance at localhost:6379 or set REDIS_URL to point to a different location.
117-
#<Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)>
118-
Loading production environment (Rails 6.1.7.3)
119-
3.1.3 :001 >
121+
There was an error trying to connect to Redis via redis://localhost:6379.
122+
Please provide a Redis instance at localhost:6379 or set REDIS_URL to point to a different location.
123+
#<Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)>
124+
Loading production environment (Rails 6.1.7.3)
125+
3.1.3 :001 >
120126
121127
Working on the console
122128
----------------------

0 commit comments

Comments
 (0)