From 9a4a5b9061093fef9d701d2fbb0e623ff3dc2ca6 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Sun, 1 Mar 2020 23:38:30 -0600 Subject: [PATCH 1/2] Fix microsecond error for 2 weeks by using 3. --- tests/DateFormatTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DateFormatTest.php b/tests/DateFormatTest.php index c009d07..6245cc9 100644 --- a/tests/DateFormatTest.php +++ b/tests/DateFormatTest.php @@ -120,7 +120,7 @@ public function testWeeksAgo() { } public function testWeeksin() { - $this->assertEquals('in 2 weeks', $this->relative('+2 weeks')); + $this->assertEquals('in 3 weeks', $this->relative('+3 weeks')); } public function testMonthsAgo() { From 23ef68364cf76376a7916da74173030e674804bb Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Tue, 25 Aug 2020 08:45:29 -0500 Subject: [PATCH 2/2] Add File function to TSS. - Inserts the contents of the file into the targeted element. --- src/Module/Functions.php | 1 + src/TSSFunction/File.php | 36 ++++++++++++++++++++++++++++++++++++ tests/TransphpormTest.php | 21 +++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/TSSFunction/File.php diff --git a/src/Module/Functions.php b/src/Module/Functions.php index 4a6dc72..1c836f2 100644 --- a/src/Module/Functions.php +++ b/src/Module/Functions.php @@ -22,6 +22,7 @@ public function load(\Transphporm\Config $config) { $functionSet->addFunction('template', $templateFunction); $functionSet->addFunction('json', new \Transphporm\TSSFunction\Json($baseDir)); $functionSet->addFunction('constant', new \Transphporm\TSSFunction\Constant()); + $functionSet->addFunction('file', new \Transphporm\TSSFunction\File($baseDir)); // Register HTML formatter here because it uses the template function $config->registerFormatter(new \Transphporm\Formatter\HTMLFormatter($templateFunction)); diff --git a/src/TSSFunction/File.php b/src/TSSFunction/File.php new file mode 100644 index 0000000..00f3745 --- /dev/null +++ b/src/TSSFunction/File.php @@ -0,0 +1,36 @@ +filePath = $filePath; + } + + /** + * @param array $args + * @param \DomElement|null $element + * + * @return array + * @throws \Exception + */ + public function run(array $args, \DomElement $element = null) + { + $fileContents = $args[0]; + + $path = $this->filePath->getFilePath($fileContents); + if (!file_exists($path)) { + throw new \Exception('File does not exist at: ' . $path); + } + $fileContents = file_get_contents($path); + + return $fileContents; + } +} diff --git a/tests/TransphpormTest.php b/tests/TransphpormTest.php index 501a782..27461d8 100644 --- a/tests/TransphpormTest.php +++ b/tests/TransphpormTest.php @@ -1436,6 +1436,27 @@ public function testJsonFile() { unlink($file); } + public function testFile() { + $data = <<assertEquals($this->stripTabs(""), $this->stripTabs($template->output($data)->body)); + + unlink($file); + } + public function testRoot() { $xml = "