From a9f840641d61d58786a4220e11925c1b81d34f2e Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Fri, 13 Oct 2017 12:31:11 +1300 Subject: [PATCH] Initial commit Split out element lists from the core module. The element list provides a base class for blocks to sit inside other blocks. --- .editorconfig | 17 +++++++ .gitattributes | 6 +++ .scrutinizer.yml | 12 +++++ .travis.yml | 35 +++++++++++++ LICENSE | 29 +++++++++++ _config/elemental.yml | 6 +++ codecov.yml | 1 + composer.json | 32 ++++++++++++ contributing.md | 25 +++++++++ images/list.svg | 4 ++ phpunit.xml.dist | 14 +++++ readme.md | 20 ++++++++ src/Model/ElementList.php | 51 +++++++++++++++++++ .../DNADesign/ElementalList/ElementList.ss | 3 ++ tests/php/ElementListTest.php | 26 ++++++++++ tests/php/ElementListTest.yml | 21 ++++++++ 16 files changed, 302 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .scrutinizer.yml create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 _config/elemental.yml create mode 100644 codecov.yml create mode 100644 composer.json create mode 100644 contributing.md create mode 100644 images/list.svg create mode 100644 phpunit.xml.dist create mode 100644 readme.md create mode 100644 src/Model/ElementList.php create mode 100644 templates/DNADesign/ElementalList/ElementList.ss create mode 100644 tests/php/ElementListTest.php create mode 100644 tests/php/ElementListTest.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..47ae637 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# For more information about the properties used in this file, +# please see the EditorConfig documentation: +# http://editorconfig.org + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[{*.yml,package.json}] +indent_size = 2 + +# The indent size used in the package.json file cannot be changed: +# https://github.com/npm/npm/pull/3180#issuecomment-16336516 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..475f5f2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/tests export-ignore +/docs export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/.scrutinizer.yml export-ignore diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..3716f81 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,12 @@ +inherit: true + +tools: + external_code_coverage: false + +checks: + php: + code_rating: true + duplication: true + +filter: + paths: [src/*, tests/*] diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fe654d2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +language: php + +env: + global: + - COMPOSER_ROOT_VERSION=1.x-dev + +matrix: + include: + - php: 5.6 + env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1 + - php: 7.0 + env: DB=PGSQL PHPUNIT_TEST=1 + - php: 7.0 + env: DB=MYSQL PHPUNIT_TEST=1 + - php: 7.1 + env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 + +before_script: + # Init PHP + - phpenv rehash + - phpenv config-rm xdebug.ini + + # Install composer dependencies + - composer validate + - composer require silverstripe/recipe-cms 1.0.x-dev --no-update + - if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --no-update; fi + - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile + +script: + - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi + +after_success: + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..efab44a --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2017, DNA Designed Communications Limited +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/_config/elemental.yml b/_config/elemental.yml new file mode 100644 index 0000000..1f7d4de --- /dev/null +++ b/_config/elemental.yml @@ -0,0 +1,6 @@ +--- +name: elemental-list +--- +DNADesign/Elemental/Models/BaseElement: + extensions: + - DNADesign/ElementalList/Extensions/BaseElementExtension diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..69cb760 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: false diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6e1cca4 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "dnadesign/silverstripe-elemental-list", + "description": "Adds a new element for nested elements", + "type": "silverstripe-vendormodule", + "keywords": ["silverstripe", "element", "elemental", "content blocks"], + "license": "BSD-3-Clause", + "authors": [{ + "name": "John Milmine", + "email": "john.milmine@dna.co.nz" + }], + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "dnadesign/silverstripe-elemental": "2.x-dev", + "silverstripe/vendor-plugin": "^1.0" + }, + "extra": { + "installer-name": "elemental-list", + "branch-alias": { + "dev-master": "1.x-dev" + }, + "expose": [ + "images" + ] + }, + "autoload": { + "psr-4": { + "DNADesign\\ElementalList\\": "src/", + "DNADesign\\ElementalList\\Tests\\": "tests/php/" + } + } +} diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..8ba55ba --- /dev/null +++ b/contributing.md @@ -0,0 +1,25 @@ +# Contributing + +Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or +simply helping others. No matter what your skill level is, every contribution counts. + +See our [high level overview](http://silverstripe.org/contributing-to-silverstripe) on silverstripe.org on how you can +help out. + +Or, for more detailed guidance, read one of the following pages: + + * [Sharing your opinion and raising issues](http://docs.silverstripe.org/en/contributing/issues_and_bugs/) + * [Providing code, whether it's creating a feature or fixing a bug](http://docs.silverstripe.org/en/contributing/code/) + * [Writing and translating documentation](http://docs.silverstripe.org/en/contributing/translations/) + * [Translating user-interface elements](http://docs.silverstripe.org/en/contributing/translation_process/) + +## Copyright + +**IMPORTANT: By supplying code in patches, tickets and pull requests, you agree to assign copyright of that code to +DNA DESIGNED COMMUNICATIONS LIMITED, on the condition that DNA DESIGNED COMMUNICATIONS LIMITED releases that code under +the BSD license.** unless otherwise noted. + +We ask for this so that the ownership in the license is clear and unambiguous, and so that community involvement doesn't +stop us from being able to continue supporting these projects. By releasing this code under a permissive license, this +copyright assignment won't prevent you from using the code in any way you see fit. + diff --git a/images/list.svg b/images/list.svg new file mode 100644 index 0000000..b154fef --- /dev/null +++ b/images/list.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..49affdc --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,14 @@ + + + tests/php + + + + + src/ + + tests/php + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c580cae --- /dev/null +++ b/readme.md @@ -0,0 +1,20 @@ +# SilverStripe Elemental List + +[![Build Status](http://img.shields.io/travis/dnadesign/silverstripe-elemental-list.svg?style=flat-square)](https://travis-ci.org/dnadesign/silverstripe-elemental-list) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dnadesign/silverstripe-elemental-list/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dnadesign/silverstripe-elemental-list/?branch=master) +[![codecov](https://codecov.io/gh/dnadesign/silverstripe-elemental-list/branch/master/graph/badge.svg)](https://codecov.io/gh/dnadesign/silverstripe-elemental-list) +[![Version](http://img.shields.io/packagist/v/dnadesign/silverstripe-elemental-list.svg?style=flat-square)](https://packagist.org/packages/dnadesign/silverstripe-elemental-list) +[![License](http://img.shields.io/packagist/l/dnadesign/silverstripe-elemental-list.svg?style=flat-square)](LICENSE.md) + +## Introduction + +Adds a new element for Elemental which allows for nested blocks. This block allows users to nest blocks within other +blocks, allowing things like columns of blocks. + +## Installation + +``` +composer require "dnadesign/silverstripe-elemental-list" +``` + + diff --git a/src/Model/ElementList.php b/src/Model/ElementList.php new file mode 100644 index 0000000..2216bee --- /dev/null +++ b/src/Model/ElementList.php @@ -0,0 +1,51 @@ + ElementalArea::class + ]; + + private static $owns = [ + 'Elements' + ]; + + private static $cascade_deletes = [ + 'Elements' + ]; + + private static $extensions = [ + ElementalAreasExtension::class + ]; + + private static $table_name = 'ElementList'; + + private static $title = 'Group'; + + private static $description = 'Orderable list of elements'; + + + /** + * @return DBField + */ + public function ElementSummary() + { + $count = $this->Elements()->Count(); + $suffix = $count === 1 ? 'element': 'elements'; + $summary = $this->ListDescription ? DBField::create_field('HTMLText', $this->ListDescription)->Summary(10) . '
': ''; + + return DBField::create_field('HTMLText', $summary . ' Contains ' . $count . ' ' . $suffix . ''); + } +} diff --git a/templates/DNADesign/ElementalList/ElementList.ss b/templates/DNADesign/ElementalList/ElementList.ss new file mode 100644 index 0000000..f5756ee --- /dev/null +++ b/templates/DNADesign/ElementalList/ElementList.ss @@ -0,0 +1,3 @@ +
+ $Elements +
diff --git a/tests/php/ElementListTest.php b/tests/php/ElementListTest.php new file mode 100644 index 0000000..c1b4767 --- /dev/null +++ b/tests/php/ElementListTest.php @@ -0,0 +1,26 @@ +assertEquals(['Elements'], $list->getElementalRelations()); + } + + public function testGetCmsFields() + { + + } + + public function testForTemplate() + { + + } +} diff --git a/tests/php/ElementListTest.yml b/tests/php/ElementListTest.yml new file mode 100644 index 0000000..c829c73 --- /dev/null +++ b/tests/php/ElementListTest.yml @@ -0,0 +1,21 @@ +DNADesign\Elemental\Models\ElementalArea: + area1: + Title: Page A + area2: + Title: Element A +DNADesign\Elemental\Tests\Src\TestPage: + page1: + Title: Page 1 + URLSegment: test-page + ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.area1 +DNADesign\ElementalList\Model\ElementList: + listElement: + Title: Element 1 + ParentID: =>DNADesign\Elemental\Models\ElementalArea.area1 + ElementsID: =>DNADesign\Elemental\Models\ElementalArea.area2 +DNADesign\Elemental\Tests\Src\TestElement: + testContent: + TestValue: foo + ParentID: =>DNADesign\Elemental\Models\ElementalArea.area2 + +