Skip to content

Commit

Permalink
Fixed page includes erroring on save
Browse files Browse the repository at this point in the history
Closes #514
  • Loading branch information
ssddanbrown committed Sep 20, 2017
1 parent df0a982 commit 74a5e31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public function show($bookSlug, $pageSlug)

$this->checkOwnablePermission('page-view', $page);

$pageContent = $this->entityRepo->renderPage($page);
$page->html = $this->entityRepo->renderPage($page);
$sidebarTree = $this->entityRepo->getBookChildren($page->book);
$pageNav = $this->entityRepo->getPageNav($pageContent);
$pageNav = $this->entityRepo->getPageNav($page->html);
$page->load(['comments.createdBy']);

Views::add($page);
Expand Down Expand Up @@ -441,6 +441,7 @@ public function restoreRevision($bookSlug, $pageSlug, $revisionId)
public function exportPdf($bookSlug, $pageSlug)
{
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$page->html = $this->entityRepo->renderPage($page);
$pdfContent = $this->exportService->pageToPdf($page);
return response()->make($pdfContent, 200, [
'Content-Type' => 'application/octet-stream',
Expand All @@ -457,6 +458,7 @@ public function exportPdf($bookSlug, $pageSlug)
public function exportHtml($bookSlug, $pageSlug)
{
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$page->html = $this->entityRepo->renderPage($page);
$containedHtml = $this->exportService->pageToContainedHtml($page);
return response()->make($containedHtml, 200, [
'Content-Type' => 'application/octet-stream',
Expand Down
1 change: 0 additions & 1 deletion app/Repos/EntityRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ public function renderPage(Page $page, $ignorePermissions = false)
$content = str_replace($matches[0][$index], trim($innerContent), $content);
}

$page->setAttribute('renderedHTML', $content);
return $content;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Entity/PageContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public function test_page_includes()
$pageContent->assertSee('Well This is a second block of content');
}

public function test_saving_page_with_includes()
{
$page = Page::first();
$secondPage = Page::all()->get(2);
$this->asEditor();
$page->html = "<p>{{@$secondPage->id}}</p>";

$resp = $this->put($page->getUrl(), ['name' => $page->name, 'html' => $page->html, 'summary' => '']);

$resp->assertStatus(302);

$page = Page::find($page->id);
$this->assertContains("{{@$secondPage->id}}", $page->html);
}

public function test_page_revision_views_viewable()
{
$this->asEditor();
Expand Down

0 comments on commit 74a5e31

Please sign in to comment.