Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
colintucker committed Nov 6, 2017
2 parents 76389a2 + b468d5b commit 3ba518b
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 32 deletions.
2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 32 additions & 28 deletions client/src/styles/_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,44 @@

.blogpost {

.tags {
article {

padding-top: 1rem;
border-top: 1px solid #eee;

.with {
color: #888;
display: block;
margin-bottom: 2px;
}

ul {
.tags {

padding: 0;
font-size: 0;
list-style: none;
padding-top: 1rem;
border-top: 1px solid #eee;

li {

margin-left: 2px;
margin-right: 5px;
font-size: 1rem;
display: inline-block;
.with {
color: #888;
display: block;
margin-bottom: 2px;
}

ul {

&:before {
color: #ccc;
content: "\f02b";
font-family: 'FontAwesome';
}
padding: 0;
font-size: 0;
list-style: none;

a {
margin-left: 3px;
li {

margin-left: 2px;
margin-right: 5px;

font-size: 1rem;
display: inline-block;

&:before {
color: #ccc;
content: "\f02b";
font-family: 'FontAwesome';
}

a {
margin-left: 3px;
display: inline-block;
}

}

}
Expand Down
21 changes: 21 additions & 0 deletions src/Pages/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Blog extends Page implements ListSource, TagSource
* @config
*/
private static $db = [
'ShowCategoryInList' => 'Boolean',
'ShowTagsInList' => 'Boolean',
'FeedTitle' => 'Varchar(255)',
'FeedDescription' => 'Varchar(255)',
'FeedNumberOfPosts' => 'Int',
Expand All @@ -107,6 +109,8 @@ class Blog extends Page implements ListSource, TagSource
* @config
*/
private static $defaults = [
'ShowCategoryInList' => 1,
'ShowTagsInList' => 0,
'FeedEnabled' => 1,
'FeedNumberOfPosts' => 10
];
Expand Down Expand Up @@ -159,6 +163,20 @@ public function getCMSFields()
$fields->addFieldsToTab(
'Root.Options',
[
FieldSection::create(
'PostOptions',
$this->fieldLabel('PostOptions'),
[
CheckboxField::create(
'ShowCategoryInList',
$this->fieldLabel('ShowCategoryInList')
),
CheckboxField::create(
'ShowTagsInList',
$this->fieldLabel('ShowTagsInList')
)
]
),
FieldSection::create(
'FeedOptions',
$this->fieldLabel('FeedOptions'),
Expand Down Expand Up @@ -208,9 +226,12 @@ public function fieldLabels($includerelations = true)

$labels['FeedTitle'] = _t(__CLASS__ . '.FEEDTITLE', 'Title');
$labels['FeedOptions'] = _t(__CLASS__ . '.FEED', 'Feed');
$labels['PostOptions'] = _t(__CLASS__ . '.POSTS', 'Posts');
$labels['FeedEnabled'] = _t(__CLASS__ . '.FEEDENABLED', 'Feed enabled');
$labels['FeedDescription'] = _t(__CLASS__ . '.DESCRIPTION', 'Description');
$labels['FeedNumberOfPosts'] = _t(__CLASS__ . '.NUMBEROFPOSTS', 'Number of posts');
$labels['ShowCategoryInList'] = _t(__CLASS__ . '.SHOWCATEGORYINLIST', 'Show category in list');
$labels['ShowTagsInList'] = _t(__CLASS__ . '.SHOWTAGSINLIST', 'Show tags in list');

// Answer Field Labels:

Expand Down
35 changes: 33 additions & 2 deletions src/Pages/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class BlogController extends PageController
* @config
*/
private static $url_handlers = [
'tag/$tag!' => 'tag'
'tag/$Tag!' => 'tag',
'$Post' => 'index'
];

/**
Expand All @@ -54,6 +55,26 @@ class BlogController extends PageController
'tag'
];

/**
* Default action for this controller, either render the blog or redirect to an existing post.
*
* @param HTTPRequest $request
*
* @return DBHTMLText|HTTPResponse
*/
public function index(HTTPRequest $request)
{
if ($segment = $request->param('Post')) {

if ($post = BlogPost::get()->find('URLSegment', $segment)) {
return $this->redirect($post->Link());
}

}

return $this->render();
}

/**
* Renders a list of the latest blog posts as an RSS feed.
*
Expand Down Expand Up @@ -94,7 +115,7 @@ public function tag(HTTPRequest $request)
{
// Obtain Tag Segment:

if ($segment = $request->param('tag')) {
if ($segment = $request->param('Tag')) {

// Obtain Tag Object:

Expand All @@ -121,6 +142,16 @@ public function tag(HTTPRequest $request)
return $this->httpError(404);
}

/**
* Answers the associated blog record.
*
* @return Blog
*/
public function getBlog()
{
return $this->data();
}

/**
* Performs initialisation before any action is called on the receiver.
*
Expand Down
45 changes: 44 additions & 1 deletion src/Pages/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class BlogPost extends Page
* @config
*/
private static $casting = [
'TagsHTML' => 'HTMLFragment',
'CategoryLink' => 'HTMLFragment'
];

Expand Down Expand Up @@ -165,7 +166,13 @@ class BlogPost extends Page
private static $list_item_details = [
'category' => [
'icon' => 'folder-o',
'text' => '$CategoryLink'
'text' => '$CategoryLink',
'show' => 'ShowCategoryInList'
],
'tags' => [
'icon' => 'tag',
'text' => '$TagsHTML',
'show' => 'ShowTagsInList'
]
];

Expand Down Expand Up @@ -320,6 +327,42 @@ public function getCategoryLink()
);
}

/**
* Answers a string of HTML containing the tags for the blog post.
*
* @return string
*/
public function getTagsHTML()
{
$output = [];

foreach ($this->Tags() as $tag) {
$output[] = sprintf('<a class="tag" href="%s">%s</a>', $tag->Link, $tag->Title);
}

return implode(', ', $output);
}

/**
* Answers true if the category is to be shown in the list.
*
* @return boolean
*/
public function getShowCategoryInList()
{
return (boolean) $this->getBlog()->ShowCategoryInList;
}

/**
* Answers true if the tags are to be shown in the list.
*
* @return boolean
*/
public function getShowTagsInList()
{
return (boolean) $this->getBlog()->ShowTagsInList;
}

/**
* Answers the parent blog of the receiver.
*
Expand Down

0 comments on commit 3ba518b

Please sign in to comment.