Commit dba3b33f authored by Administrator's avatar Administrator 💬

Refactor how we link to the web ide.

parent e4f4a6ac
Pipeline #41 passed with stage
in 45 seconds
...@@ -40,25 +40,28 @@ class M3P2Plugin extends Plugin ...@@ -40,25 +40,28 @@ class M3P2Plugin extends Plugin
return; return;
} }
// /sync
$uri = $this->grav['uri']; $uri = $this->grav['uri'];
$route = $this->config->get('plugins.m3-p2.route'); $route = $this->config->get('plugins.m3-p2.route');
// throw new \Exception($route." - ".$uri->path());
if ($route && $route == $uri->path()) { if ($route && $route == $uri->path()) {
$this->enable([ $this->enable([
'onPageInitialized' => ['onPageInitialized', 0] 'onPageInitialized' => ['onSyncPageInitialized', 0]
]); ]);
} }
$this->enable([
'onTwigInitialized' => ['setupWebIdeUrl', 0],
]);
} }
/** /**
* Send user to a random page * Sync with the sources.
*/ */
public function onPageInitialized() public function onSyncPageInitialized()
{ {
$out = "Opening a fortune cookie…\n\n\n"; // shell cwd is project root
// shell pwd is project root $out = "Opening a fortune cookie…\n\n\n";
// $out .= shell_exec("fortune | cowsay -e Oø -f dragon") . "\n"; // $out .= shell_exec("fortune | cowsay -e Oø -f dragon") . "\n";
$out .= shell_exec("fortune") . "\n\n"; $out .= shell_exec("fortune") . "\n\n";
...@@ -67,6 +70,21 @@ class M3P2Plugin extends Plugin ...@@ -67,6 +70,21 @@ class M3P2Plugin extends Plugin
$out .= "Done."; $out .= "Done.";
die("<pre>".$out."</pre>"); // This is all I find to write to the page. die("<pre>".$out."</pre>"); // This is all I could find to write to the page.
}
public function setupWebIdeUrl()
{
$this->grav['twig']->twig()->addFilter(
new \Twig_SimpleFilter('webide_url', [$this, 'getWebIdeUrlForPage'])
);
}
public function getWebIdeUrlForPage(Page $page)
{
$url = "https://m3p2.ljbac.com/-/ide/project/m3p2/courses/edit/master/-/";
$url .= substr($page->filePathClean(), 11); // 11==strlen('/user/pages')
return $url;
} }
} }
...@@ -4,12 +4,11 @@ ...@@ -4,12 +4,11 @@
{{ page.content|raw }} {{ page.content|raw }}
{% set editor_url = "https://m3p2.ljbac.com/-/ide/project/m3p2/courses/edit/master/-/" ~ page.filePathClean | slice(11) %}
<div class="notices blue contribution-incentive"> <div class="notices blue contribution-incentive">
<p> <p>
{{ 'THEME_TEXTBOOK.PAGE.FOOTER_NOTICE.CONGRATULATIONS'|t }} {{ 'THEME_TEXTBOOK.PAGE.FOOTER_NOTICE.CONGRATULATIONS'|t }}
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<a href="{{ editor_url }}">{{ 'THEME_TEXTBOOK.PAGE.FOOTER_NOTICE.EDIT'|t }}</a> <a href="{{ page | webide_url }}">{{ 'THEME_TEXTBOOK.PAGE.FOOTER_NOTICE.EDIT'|t }}</a>
</p> </p>
</div> </div>
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment