From d7f0206a0e3ed82f5e3707a54dfaf16ecbd6350f Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Wed, 9 Sep 2015 11:07:51 +1200 Subject: [PATCH] Made supported --- .gitattributes | 6 +++ .scrutinizer.yml | 12 ++++++ .travis.yml | 39 +++++++++--------- README.md | 69 -------------------------------- changelog.md | 9 +++++ code-of-conduct.md | 22 +++++++++++ contributing.md | 3 ++ docs/en/installing.md | 9 +++++ docs/en/introduction.md | 14 +++++++ docs/en/using.md | 63 +++++++++++++++++++++++++++++ LICENCE => license.md | 2 +- readme.md | 88 +++++++++++++++++++++++++++++++++++++++++ 12 files changed, 248 insertions(+), 88 deletions(-) create mode 100644 .gitattributes create mode 100644 .scrutinizer.yml delete mode 100644 README.md create mode 100644 changelog.md create mode 100644 code-of-conduct.md create mode 100644 contributing.md create mode 100644 docs/en/installing.md create mode 100644 docs/en/introduction.md create mode 100644 docs/en/using.md rename LICENCE => license.md (95%) create mode 100644 readme.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..36779ab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/.scrutinizer.yml export-ignore +/phpunit.xml export-ignore diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..d9de4d0 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,12 @@ +inherit: true + +tools: + external_code_coverage: true + +checks: + php: + code_rating: true + duplication: true + +filter: + paths: [code/*, tests/*] diff --git a/.travis.yml b/.travis.yml index bc5b21b..600bb8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,31 @@ -# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details - language: php + php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - 7.0 sudo: false env: - - DB=MYSQL CORE_RELEASE=3.1 - -matrix: - allow_failures: - - php: 5.5 - env: DB=MYSQL CORE_RELEASE=3.1 - - php: 5.6 - env: DB=MYSQL CORE_RELEASE=3.1 + - DB=MYSQL CORE_RELEASE=3.1 before_script: - - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - - cd ~/builds/ss + - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support + - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss + - cd ~/builds/ss script: - - phpunit tagfield/tests + - vendor/bin/phpunit --coverage-clover coverage.clover tagfield/tests + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover coverage.clover --repository=g/silverstripe-labs/silverstripe-tagfield + +branches: + only: + - master + +matrix: + allow_failures: + - php: 7.0 diff --git a/README.md b/README.md deleted file mode 100644 index f35ea40..0000000 --- a/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# TagField Module - -[![Build Status](http://img.shields.io/travis/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://travis-ci.org/silverstripe-labs/silverstripe-tagfield) -[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-tagfield) - -## Requirements - -* SilverStripe 3.1 or newer -* Database: MySQL 5+, SQLite3, Postgres 8.3, SQL Server 2008 - -## Download/Information - -* http://silverstripe.org/tag-field-module - -## Usage - -### Relational Tags - -```php -class BlogPost extends DataObject { - private static $many_many = array( - 'BlogTags' => 'BlogTag' - ); -} -``` - -```php -class BlogTag extends DataObject { - private static $db = array( - 'Title' => 'Varchar(200)', - ); - - private static $belongs_many_many = array( - 'BlogPosts' => 'BlogPost' - ); -} -``` - -```php -$field = TagField::create( - 'BlogTags', - 'Blog Tags', - BlogTag::get(), - $this->BlogTags() -) - ->setShouldLazyLoad(true) // tags should be lazy loaded - ->setCanCreate(true); // new tag DataObjects can be created -``` - -### String Tags - -```php -class BlogPost extends DataObject { - private static $db = array( - 'Tags' => 'Text' - ); -} -``` - -```php -$field = StringTagField::create( - 'Tags', - 'Tags', - array('one', 'two'), - explode(',', $this->Tags) -); - -$field->setShouldLazyLoad(true); // tags should be lazy loaded -``` diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..76a9473 --- /dev/null +++ b/changelog.md @@ -0,0 +1,9 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](http://semver.org/). + +## [1.0.0] + +Changelog added. diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 0000000..ae45a0e --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,22 @@ +# Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..32334e2 --- /dev/null +++ b/contributing.md @@ -0,0 +1,3 @@ +# Contributing + +Contributions are welcome! Create an issue, explaining a bug or proposal. Submit pull requests if you feel brave. Speak to me on [Twitter](https://twitter.com/assertchris). diff --git a/docs/en/installing.md b/docs/en/installing.md new file mode 100644 index 0000000..550486b --- /dev/null +++ b/docs/en/installing.md @@ -0,0 +1,9 @@ +# Installing + +To install this module, [download and install Composer](https://getcomposer.org/doc/00-intro.md). Then run the following command: + +```sh +$ composer require silverstripe/tagfield +``` + +Then run `/dev/build`, from either the command line or the browser. You'll then be able to use this field in your application. diff --git a/docs/en/introduction.md b/docs/en/introduction.md new file mode 100644 index 0000000..0a38258 --- /dev/null +++ b/docs/en/introduction.md @@ -0,0 +1,14 @@ +# Introduction + +Custom tag input field, for SilverStripe. + +## Sections + +- [Installing](installing.md) +- [Using](using.md) + +## Questions + +This module is supported by [Christopher Pitt](https://twitter.com/assertchris). You can ask questions on Twitter. + +You can report bugs or request features on [GitHub](http://github.com/silverstripe-labs/silverstripe-tagfield/issues). diff --git a/docs/en/using.md b/docs/en/using.md new file mode 100644 index 0000000..12890e5 --- /dev/null +++ b/docs/en/using.md @@ -0,0 +1,63 @@ +# Using + +The primary use, for this module, is as a custom input field interface. For instance, imagine you had the following data objects: + +```php +class BlogPost extends DataObject { + private static $many_many = array( + 'BlogTags' => 'BlogTag' + ); +} + +class BlogTag extends DataObject { + private static $db = array( + 'Title' => 'Varchar(200)', + ); + + private static $belongs_many_many = array( + 'BlogPosts' => 'BlogPost' + ); +} +``` + +If you wanted to link blog tags to blog posts, you might override `getCMSFields` with the following field: + +```php +$field = TagField::create( + 'BlogTags', + 'Blog Tags', + BlogTag::get(), + $this->BlogTags() +) + ->setShouldLazyLoad(true) // tags should be lazy loaded + ->setCanCreate(true); // new tag DataObjects can be created +``` + +This will present a tag field, in which you can select existing blog tags or create new ones. They will be created/linked after the blog posts are saved. + +You can also store string-based tags, for blog posts, with the following field type: + +```php +$field = StringTagField::create( + 'Tags', + 'Tags', + array('one', 'two'), + explode(',', $this->Tags) +); + +$field->setShouldLazyLoad(true); // tags should be lazy loaded +``` + +This assumes you are storing tags in the following data object structure: + +```php +class BlogPost extends DataObject { + private static $db = array( + 'Tags' => 'Text' + ); +} +``` + +These tag field classes extend the `DropdownField` class. Their template(s) don't alter the underlying select element structure, so you can interact with them as with any normal select element. You can also interact with the Select2 instance applied to each field, as you would any other time when using Select2. + +> Chosen is applied to all select elements in the CMS, so this module attempts to remove it before applying Select2. Review the companion JS files to see how that happens... diff --git a/LICENCE b/license.md similarity index 95% rename from LICENCE rename to license.md index 186b6ff..273cb67 100644 --- a/LICENCE +++ b/license.md @@ -20,4 +20,4 @@ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 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. \ No newline at end of file +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..57fa87b --- /dev/null +++ b/readme.md @@ -0,0 +1,88 @@ +# Tag Field + +Custom tag input field, for SilverStripe. + +[![Build Status](http://img.shields.io/travis/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://travis-ci.org/silverstripe-labs/silverstripe-tagfield) +[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-tagfield) +[![Code Coverage](http://img.shields.io/scrutinizer/coverage/g/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-tagfield) +[![Version](http://img.shields.io/packagist/v/silverstripe/tagfield.svg?style=flat-square)](https://packagist.org/packages/silverstripe/tagfield) +[![License](http://img.shields.io/packagist/l/silverstripe/tagfield.svg?style=flat-square)](license.md) + +## Requirements + +* SilverStripe 3.1 or newer +* Database: MySQL 5+, SQLite3, Postgres 8.3, SQL Server 2008 + +## Installing + +```sh +$ composer require silverstripe/tagfield +``` + +## Using + +### Relational Tags + +```php +class BlogPost extends DataObject { + private static $many_many = array( + 'BlogTags' => 'BlogTag' + ); +} +``` + +```php +class BlogTag extends DataObject { + private static $db = array( + 'Title' => 'Varchar(200)', + ); + + private static $belongs_many_many = array( + 'BlogPosts' => 'BlogPost' + ); +} +``` + +```php +$field = TagField::create( + 'BlogTags', + 'Blog Tags', + BlogTag::get(), + $this->BlogTags() +) + ->setShouldLazyLoad(true) // tags should be lazy loaded + ->setCanCreate(true); // new tag DataObjects can be created +``` + +### String Tags + +```php +class BlogPost extends DataObject { + private static $db = array( + 'Tags' => 'Text' + ); +} +``` + +```php +$field = StringTagField::create( + 'Tags', + 'Tags', + array('one', 'two'), + explode(',', $this->Tags) +); + +$field->setShouldLazyLoad(true); // tags should be lazy loaded +``` + +You can find more in-depth documentation in [docs/en](docs/en/introduction.md). + +## Versioning + +This library follows [Semver](http://semver.org). According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library. + +All methods, with `public` visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep `protected` methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading. + +## Reporting Issues + +Please [create an issue](http://github.com/silverstripe-labs/silverstripe-tagfield/issues) for any bugs you've found, or features you're missing.