From 8949dfa6915f9dd82ceec2ed67cc5f7256292bd1 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Sat, 14 Apr 2012 19:56:13 +1200 Subject: [PATCH] ENHANCEMENT Replaced locations of sapphire with $ModulePath(framework) in templates, based off Controller which implements TemplateGlobalProvider --- admin/templates/Includes/CMSLoadingScreen.ss | 2 +- admin/templates/LeftAndMain.ss | 2 +- control/Controller.php | 26 +++++++++++++++ docs/en/changelogs/3.0.0.md | 2 +- templates/CodeViewer.ss | 2 +- templates/ComplexTableField.ss | 6 ++-- templates/ComplexTableField_popup.ss | 4 +-- .../Includes/TableListField_PageControls.ss | 16 ++++----- templates/RelationComplexTableField.ss | 2 +- templates/TableField.ss | 4 +-- templates/TableListField.ss | 4 +-- templates/TestViewer.ss | 2 +- templates/forms/ToggleCompositeField.ss | 4 +-- tests/model/DataDifferencerTest.php | 11 +++++++ view/GenericTemplateGlobalProvider.php | 33 ------------------- view/TemplateGlobalProvider.php | 1 - 16 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 view/GenericTemplateGlobalProvider.php diff --git a/admin/templates/Includes/CMSLoadingScreen.ss b/admin/templates/Includes/CMSLoadingScreen.ss index f39323552..ed896c8d7 100644 --- a/admin/templates/Includes/CMSLoadingScreen.ss +++ b/admin/templates/Includes/CMSLoadingScreen.ss @@ -1,6 +1,6 @@
diff --git a/admin/templates/LeftAndMain.ss b/admin/templates/LeftAndMain.ss index 3db0feed5..4c1ca189c 100644 --- a/admin/templates/LeftAndMain.ss +++ b/admin/templates/LeftAndMain.ss @@ -7,7 +7,7 @@ $Title - + <% include CMSLoadingScreen %> diff --git a/control/Controller.php b/control/Controller.php index cd5757edd..2fde7a873 100644 --- a/control/Controller.php +++ b/control/Controller.php @@ -405,6 +405,32 @@ class Controller extends RequestHandler implements TemplateGlobalProvider { //----------------------------------------------------------------------------------- + /** + * Given some pre-defined modules, return the filesystem path of the module. + * @param string $name Name of module to find path of + * @return string + */ + function ModulePath($name) { + switch($name) { + case 'framework': + $path = FRAMEWORK_DIR; + break; + case 'frameworkadmin': + $path = FRAMEWORK_ADMIN_DIR; + break; + case 'thirdparty': + $path = THIRDPARTY_DIR; + break; + case 'assets': + $path = ASSETS_DIR; + break; + default: + throw InvalidArgumentException($name . ' is not a supported argument. Possible values: framework, frameworkadmin, thirdparty, assets'); + } + + return $path; + } + /** * returns a date object for use within a template * Usage: $Now.Year - Returns 2006 diff --git a/docs/en/changelogs/3.0.0.md b/docs/en/changelogs/3.0.0.md index 57d9558e5..6891f7618 100644 --- a/docs/en/changelogs/3.0.0.md +++ b/docs/en/changelogs/3.0.0.md @@ -23,7 +23,7 @@ Existing code bases can retain `sapphire` as the framework directory name, and a transitions if you want to rename the framework directory. In your templates, `$ModulePath(framework)` gives whatever directory the SilverStripe framework resides in. -It takes the value from the FRAMEWORK_PATH constant, which is automatically worked out based on where the +It takes the value from the FRAMEWORK_DIR constant, which is automatically worked out based on where the framework directory is, but can be set manually by defining FRAMEWORK_DIR in your _ss_environment.php file. ### New ORM: More flexible and expressive querying via `DataList` ### diff --git a/templates/CodeViewer.ss b/templates/CodeViewer.ss index b509d2b62..e87b0648b 100644 --- a/templates/CodeViewer.ss +++ b/templates/CodeViewer.ss @@ -1,7 +1,7 @@ <% base_tag %> - + $Content diff --git a/templates/ComplexTableField.ss b/templates/ComplexTableField.ss index 9ad4905a1..79262244c 100644 --- a/templates/ComplexTableField.ss +++ b/templates/ComplexTableField.ss @@ -17,9 +17,9 @@ <% if SortDirection = desc %> - <% _t('SORTASC', 'Sort ascending') %> + <% _t('SORTASC', 'Sort ascending') %> <% else %> - <% _t('SORTDESC', 'Sort descending') %> + <% _t('SORTDESC', 'Sort descending') %> <% end_if %>   @@ -49,7 +49,7 @@ - <% _t('ADDITEM', 'add') %> + <% _t('ADDITEM', 'add') %> <% sprintf(_t('ADDITEM', 'Add %s', PR_MEDIUM, 'Add [name]'),$Title) %> diff --git a/templates/ComplexTableField_popup.ss b/templates/ComplexTableField_popup.ss index 116ab4619..56c96764e 100644 --- a/templates/ComplexTableField_popup.ss +++ b/templates/ComplexTableField_popup.ss @@ -15,7 +15,7 @@ <% if Paginator.PrevLink %> - <% _t('PREVIOUS', 'Previous') %> + <% _t('PREVIOUS', 'Previous') %> <% end_if %> <% if xdsfdsf %> @@ -32,7 +32,7 @@ <% end_if %> <% if Paginator.NextLink %> - <% _t('NEXT', 'Next') %> + <% _t('NEXT', 'Next') %> <% end_if %> diff --git a/templates/Includes/TableListField_PageControls.ss b/templates/Includes/TableListField_PageControls.ss index 12acfbca5..22dd5189f 100644 --- a/templates/Includes/TableListField_PageControls.ss +++ b/templates/Includes/TableListField_PageControls.ss @@ -1,17 +1,17 @@ <% if ShowPagination %> <% if TotalCount %>
- <% if FirstLink %><% _t('VIEWFIRST', 'View first') %> $PageSize - <% else %><% _t('VIEWFIRST', 'View first') %> $PageSize<% end_if %> - <% if PrevLink %> - <% else %><% _t('VIEWPREVIOUS', 'View previous') %> $PageSize<% end_if %> + <% if FirstLink %><% _t('VIEWFIRST', 'View first') %> $PageSize + <% else %><% _t('VIEWFIRST', 'View first') %> $PageSize<% end_if %> + <% if PrevLink %> + <% else %><% _t('VIEWPREVIOUS', 'View previous') %> $PageSize<% end_if %> <% _t('DISPLAYING', 'Displaying') %> $FirstItem <% _t('TO', 'to') %> $LastItem <% _t('OF', 'of') %> $TotalCount - <% if NextLink %> - <% else %><% _t('VIEWNEXT', 'View next') %> $PageSize<% end_if %> - <% if LastLink %><% _t('VIEWLAST', 'View last') %> $PageSize - <% else %><% _t('VIEWLAST', 'View last') %> $PageSize<% end_if %> + <% if NextLink %> + <% else %><% _t('VIEWNEXT', 'View next') %> $PageSize<% end_if %> + <% if LastLink %><% _t('VIEWLAST', 'View last') %> $PageSize + <% else %><% _t('VIEWLAST', 'View last') %> $PageSize<% end_if %>
<% end_if %> diff --git a/templates/RelationComplexTableField.ss b/templates/RelationComplexTableField.ss index 14c41c9da..a8d23ed23 100644 --- a/templates/RelationComplexTableField.ss +++ b/templates/RelationComplexTableField.ss @@ -34,7 +34,7 @@ - <% _t('ADD', 'Add') %><% _t('ADD', 'Add') %> $Title + <% _t('ADD', 'Add') %><% _t('ADD', 'Add') %> $Title <% if Can(show) %> <% end_if %> <% if Can(edit) %> <% end_if %> diff --git a/templates/TableField.ss b/templates/TableField.ss index 141b8e671..61fa6ddc5 100644 --- a/templates/TableField.ss +++ b/templates/TableField.ss @@ -30,7 +30,7 @@ <% if Can(add) %> - <% _t('ADD','Add a new row') %> + <% _t('ADD','Add a new row') %> <% sprintf(_t('ADDITEM','Add %s'),$Title) %> @@ -47,7 +47,7 @@ $Field <% end_control %> $ExtraData - <% if Can(delete) %><% _t('DELETE') %><% end_if %> + <% if Can(delete) %><% _t('DELETE') %><% end_if %> <% end_control %> <% else %> diff --git a/templates/TableListField.ss b/templates/TableListField.ss index ccd441a4c..088d074fb 100644 --- a/templates/TableListField.ss +++ b/templates/TableListField.ss @@ -24,9 +24,9 @@
<% if SortDirection = desc %> - <% _t('SORTDESC', 'Sort in descending order') %> + <% _t('SORTDESC', 'Sort in descending order') %> <% else %> - <% _t('SORTASC', 'Sort in ascending order') %> + <% _t('SORTASC', 'Sort in ascending order') %> <% end_if %>   diff --git a/templates/TestViewer.ss b/templates/TestViewer.ss index cf913d72b..e14ea0878 100644 --- a/templates/TestViewer.ss +++ b/templates/TestViewer.ss @@ -1,7 +1,7 @@ <% base_tag %> - + $Content diff --git a/templates/forms/ToggleCompositeField.ss b/templates/forms/ToggleCompositeField.ss index cf7a65659..ae6510939 100644 --- a/templates/forms/ToggleCompositeField.ss +++ b/templates/forms/ToggleCompositeField.ss @@ -1,7 +1,7 @@
- - + + $Title
diff --git a/tests/model/DataDifferencerTest.php b/tests/model/DataDifferencerTest.php index ad5172ecf..20ef65eaf 100644 --- a/tests/model/DataDifferencerTest.php +++ b/tests/model/DataDifferencerTest.php @@ -35,6 +35,16 @@ class DataDifferencerTest extends SapphireTest { $relobj1 = $this->objFromFixture('DataDifferencerTest_HasOneRelationObject', 'relobj1'); $relobj2 = $this->objFromFixture('DataDifferencerTest_HasOneRelationObject', 'relobj2'); + // in order to ensure the Filename path is correct, append the correct FRAMEWORK_DIR to the start + // this is only really necessary to make the test pass when FRAMEWORK_DIR is not "framework" + $image1->Filename = FRAMEWORK_DIR . substr($image1->Filename, 9); + $image2->Filename = FRAMEWORK_DIR . substr($image2->Filename, 9); + $origUpdateFilesystem = File::$update_filesystem; + File::$update_filesystem = false; // we don't want the filesystem being updated on write, as we're only dealing with mock files + $image1->write(); + $image2->write(); + File::$update_filesystem = $origUpdateFilesystem; + // create a new version $obj1->ImageID = $image2->ID; $obj1->HasOneRelationID = $relobj2->ID; @@ -43,6 +53,7 @@ class DataDifferencerTest extends SapphireTest { $obj1v2 = Versioned::get_version('DataDifferencerTest_Object', $obj1->ID, $obj1->Version); $differ = new DataDifferencer($obj1v1, $obj1v2); $obj1Diff = $differ->diffedData(); + $this->assertContains($image1->Filename, $obj1Diff->getField('Image')); $this->assertContains($image2->Filename, $obj1Diff->getField('Image')); $this->assertContains('obj2obj1', str_replace(' ','',$obj1Diff->getField('HasOneRelationID'))); diff --git a/view/GenericTemplateGlobalProvider.php b/view/GenericTemplateGlobalProvider.php deleted file mode 100644 index b61d070f7..000000000 --- a/view/GenericTemplateGlobalProvider.php +++ /dev/null @@ -1,33 +0,0 @@ -