Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M3P2 HTML Generator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
12
Issues
12
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
M3P2
M3P2 HTML Generator
Commits
210cd2ec
Commit
210cd2ec
authored
Apr 28, 2021
by
Administrator
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add a new template: parallel pages
parent
29e9202a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
5 deletions
+101
-5
m3-p2.php
user/plugins/m3-p2/m3-p2.php
+62
-5
parallel.html.twig
user/themes/textbook/templates/parallel.html.twig
+39
-0
No files found.
user/plugins/m3-p2/m3-p2.php
View file @
210cd2ec
<?php
namespace
Grav\Plugin
;
use
Grav\Common\Grav
;
use
Grav\Common\Page\Page
;
use
Grav\Common\Page\Pages
;
use
Grav\Common\Plugin
;
...
...
@@ -44,9 +45,8 @@ class M3P2Plugin extends Plugin
*/
public
function
onPluginsInitialized
()
{
// Don't proceed if we are in the admin plugin
if
(
$this
->
isAdmin
())
{
return
;
return
;
// Don't proceed if we are in the admin backend
}
$uri
=
$this
->
grav
[
'uri'
];
...
...
@@ -60,10 +60,15 @@ class M3P2Plugin extends Plugin
]);
}
$this
->
enable
([
'onTwigInitialized'
=>
[
'setupTwigGoodies'
,
0
],
]);
$this
->
enable
([
'onTwigInitialized'
=>
[
'setupWebIdeUrl'
,
0
],
]);
// $that_page_route = $uri->query('page');
// if ($that_page_route) {
// $this->enable([
...
...
@@ -95,10 +100,11 @@ class M3P2Plugin extends Plugin
public
function
onSyncPageInitialized
()
{
// shell cwd is project root
$out
=
""
;
$out
=
"Opening a fortune cookie…
\n\n\n
"
;
// $out .= shell_exec("fortune | cowsay -e Oø -f dragon") . "
\n";
$out
.=
shell_exec
(
"fortune"
)
.
"
\n
\n
"
;
//
$out = "Opening a fortune cookie…\n\n\n";
//$out .= shell_exec("fortune") . "\n
\n";
//$out .= shell_exec("fortune | cowsay -e Oø -f dragon") . "
\n";
$out
.=
"Trying to sync content with GitLab…
\n\n\n
"
;
$out
.=
shell_exec
(
"cd user/pages && git pull --rebase --autostash origin master 2>&1"
)
.
"
\n
"
;
...
...
@@ -108,6 +114,17 @@ class M3P2Plugin extends Plugin
die
(
"<pre>"
.
$out
.
"</pre>"
);
// This is all I could find to write to the page.
}
public
function
setupTwigGoodies
()
{
/** @var Pages $pages */
$pages
=
Grav
::
instance
()[
'pages'
];
$this
->
grav
[
'twig'
]
->
twig
()
->
addGlobal
(
'localized_pages'
,
$pages
);
$this
->
grav
[
'twig'
]
->
twig
()
->
addFilter
(
new
\Twig_SimpleFilter
(
'to_page'
,
[
$this
,
'getPageForPath'
])
);
}
public
function
setupWebIdeUrl
()
{
$this
->
grav
[
'twig'
]
->
twig
()
->
addFilter
(
...
...
@@ -130,6 +147,46 @@ class M3P2Plugin extends Plugin
// );
// }
public
function
getPageForPath
(
$meta
)
{
if
(
is_array
(
$meta
))
{
if
(
isset
(
$meta
[
'path'
]))
{
$path
=
$meta
[
'path'
];
}
else
{
trigger_error
(
"Missing `path` in: "
.
print_r
(
$meta
,
true
));
}
}
elseif
(
is_string
(
$meta
))
{
$path
=
$meta
;
}
else
{
trigger_error
(
"Unrecognized page: "
.
print_r
(
$meta
,
true
));
}
/** @var Pages $pages */
$pages
=
Grav
::
instance
()[
'pages'
];
$page
=
$pages
->
find
(
$path
);
if
(
!
$page
)
{
try
{
$page
=
$pages
->
get
(
$path
);
}
catch
(
\Exception
$e
)
{}
}
if
(
!
$page
)
{
try
{
$cwd
=
$pages
->
root
()
->
filePath
();
// ends with /
if
(
0
===
strpos
(
$path
,
'/'
))
{
$page
=
$pages
->
get
(
$cwd
.
substr
(
$path
,
1
));
}
else
{
$page
=
$pages
->
get
(
$cwd
.
$path
);
}
// die($cwd . $path);
}
catch
(
\Exception
$e
)
{}
}
return
$page
;
}
public
function
getWebIdeUrlForPage
(
Page
$page
)
{
$url
=
"https://gitlab.m3p2.com/-/ide/project/m3p2/courses/edit/master/-/"
;
# todo: move to YAML config
...
...
user/themes/textbook/templates/parallel.html.twig
0 → 100644
View file @
210cd2ec
{%
extends
'partials/base.html.twig'
%}
{%
block
stylesheets
%}
{%
do
assets.addCss
(
'theme://css/columns.css'
)
%}
{{
parent
()
}}
{%
endblock
%}
{%
block
body
%}
{#
{{
localized_pages.instances | keys | join('<br>') }}#}
<div
class=
"claude-columns"
>
{%
for
column_page_meta
in
page.header.pages
%}
{%
set
column
=
column_page_meta
|
to_page
%}
{%
if
column
%}
<section
id=
"
{{
macro.pageLinkName
(
column.menu
)
}}
"
class=
"claude-column"
>
{{
column.content
|
raw
}}
{%
include
'partials/contributions-incentive.html.twig'
with
{
page
:
column
}
%}
</section>
{%
else
%}
<p
class=
"col-4"
>
Column
<code>
{{
column_page_meta
|
join
(
' '
)
}}
</code>
not found.
</p>
{%
endif
%}
{%
endfor
%}
</div>
{#
{{
page.content|raw }}#}
{%
endblock
%}
{# Disable the Rosetta option of the language selector, for now. #}
{# How to access the Rosettas of the children poages? #}
{%
block
header_language_selection
%}
{%
embed
'partials/language-selector.html.twig'
%}
{%
block
polyglot_language_selector
%}{%
endblock
%}
{%
endembed
%}
{%
endblock
%}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment