mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API: add api for setting a custom template on a RSS feed.
See initial idea at http://open.silverstripe.org/ticket/6441. Added $template property and corresponding getters / setters for customizing the template used. Added relevant unit test.
This commit is contained in:
parent
23ed5335e6
commit
f1db65d6b6
@ -8,6 +8,7 @@
|
|||||||
* @subpackage integration
|
* @subpackage integration
|
||||||
*/
|
*/
|
||||||
class RSSFeed extends ViewableData {
|
class RSSFeed extends ViewableData {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Casting information for this object's methods.
|
* Casting information for this object's methods.
|
||||||
* Let's us use $Title.XML in templates
|
* Let's us use $Title.XML in templates
|
||||||
@ -80,6 +81,11 @@ class RSSFeed extends ViewableData {
|
|||||||
*/
|
*/
|
||||||
protected $etag;
|
protected $etag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $template = 'RSSFeed';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -203,10 +209,29 @@ class RSSFeed extends ViewableData {
|
|||||||
function feedContent() {
|
function feedContent() {
|
||||||
$prevState = SSViewer::get_source_file_comments();
|
$prevState = SSViewer::get_source_file_comments();
|
||||||
SSViewer::set_source_file_comments(false);
|
SSViewer::set_source_file_comments(false);
|
||||||
$content = str_replace(' ', ' ', $this->renderWith('RSSFeed'));
|
$content = str_replace(' ', ' ', $this->renderWith($this->getTemplate()));
|
||||||
SSViewer::set_source_file_comments($prevState);
|
SSViewer::set_source_file_comments($prevState);
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the name of the template to use. Actual template will be resolved
|
||||||
|
* via the standard template inclusion process.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
|
public function setTemplate($template) {
|
||||||
|
$this->template = $template;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the template to use.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTemplate() {
|
||||||
|
return $this->template;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +43,20 @@ class RSSFeedTest extends SapphireTest {
|
|||||||
$this->assertContains('<description>ItemC AltContent</description>', $content);
|
$this->assertContains('<description>ItemC AltContent</description>', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRenderWithTemplate() {
|
||||||
|
$rssFeed = new RSSFeed(new ArrayList(), "", "", "");
|
||||||
|
$rssFeed->setTemplate('RSSFeedTest');
|
||||||
|
|
||||||
|
$content = $rssFeed->feedContent();
|
||||||
|
|
||||||
|
$this->assertContains('<title>Test Custom Template</title>', $content);
|
||||||
|
|
||||||
|
$rssFeed->setTemplate('RSSFeed');
|
||||||
|
$content = $rssFeed->feedContent();
|
||||||
|
|
||||||
|
$this->assertNotContains('<title>Test Custom Template</title>', $content);
|
||||||
|
}
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Director::setBaseURL('/');
|
Director::setBaseURL('/');
|
||||||
|
6
tests/templates/RSSFeedTest.ss
Normal file
6
tests/templates/RSSFeedTest.ss
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||||
|
<channel>
|
||||||
|
<title>Test Custom Template</title>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
Loading…
Reference in New Issue
Block a user