Skip to content

Commit 109913d

Browse files
committed
Add template extension configuration
1 parent a7bdce4 commit 109913d

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

src/AirBubble/AirBubbleConfig.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class AirBubbleConfig
6868
*/
6969
private $_indentOutput = true;
7070

71+
/**
72+
* Define the default extension for templates.
73+
*
74+
* @var string
75+
*/
76+
private $_extension = "bubble";
77+
7178
/**
7279
* Checks if the renderer have to indent the
7380
* output.
@@ -135,4 +142,27 @@ public function setEncoding(string $encoding)
135142
$this->_templateEncoding = $encoding;
136143
return $this;
137144
}
145+
146+
/**
147+
* Get the default template extension.
148+
*
149+
* @return string
150+
*/
151+
public function getTemplateExtension()
152+
{
153+
return $this->_extension;
154+
}
155+
156+
/**
157+
* Set the default template extension.
158+
*
159+
* @param string $extension The template extension to use.
160+
*
161+
* @return self
162+
*/
163+
public function setTemplateExtension(string $extension)
164+
{
165+
$this->_extension = $extension;
166+
return $this;
167+
}
138168
}

src/AirBubble/Renderer/Template.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ private function _mergeWithParent($content): string {
338338

339339
public static function fromFile(string $path): Template
340340
{
341-
$path = Utilities::resolveTemplate($path);
341+
$templatePath = Utilities::resolveTemplate($path);
342342

343-
if (file_exists($path)) {
344-
return self::fromString(file_get_contents($path));
343+
if (file_exists($templatePath)) {
344+
return self::fromString(file_get_contents($templatePath));
345345
} else {
346-
throw new TemplateNotFoundException($path);
346+
throw new TemplateNotFoundException($templatePath);
347347
}
348348
}
349349

src/AirBubble/Tokens/DataTableToken.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ public function parse()
204204
* Render the token.
205205
*
206206
* @return \DOMNode|null
207+
*
207208
* @throws ElementNotFoundException
209+
* @throws \AirBubble\Exception\InvalidQueryException
210+
* @throws \AirBubble\Exception\KeyNotFoundException
211+
* @throws \AirBubble\Exception\PropertyNotFoundException
212+
* @throws \Exception
208213
*/
209214
public function render(): ?\DOMNode
210215
{
@@ -235,7 +240,7 @@ public function render(): ?\DOMNode
235240

236241
if (!is_iterable($data)) {
237242
// TODO: Create an exception for this
238-
throw new \Exception("Non-iterable data provided to a foreach loop.");
243+
throw new \Exception("Non-iterable data provided to the data table.");
239244
}
240245

241246
$domElement = $this->_document->createElement("table", "");

src/AirBubble/Util/Utilities.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public static function insertHTMLBefore(string $html, \DOMNode $refNode)
9393
public static function resolveTemplate(string $path)
9494
{
9595
$config = AirBubble::getConfiguration();
96+
$extension = "." . $config->getTemplateExtension();
97+
$path = strrpos($path, $extension) ? $path : $path . $extension;
9698
return realpath($config->getTemplatesBasePath() . DIRECTORY_SEPARATOR . $path);
9799
}
98100

0 commit comments

Comments
 (0)