Skip to content

Commit

Permalink
Update CI file to publish Docs on master branch push.
Browse files Browse the repository at this point in the history
Updated Package for Dart only projects.
Updated Readme.
  • Loading branch information
ibrahim-mubarak committed Aug 13, 2019
1 parent ce07d83 commit 3c06051
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 46 deletions.
20 changes: 18 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@ test_task:
CODECOV_TOKEN: ENCRYPTED[0b39ebc2857b16573838848a4359338b0b198c8342d9f846182ef1bd81e810c43809b7af330ab8a49f7bd708ecb82663]
pub_cache:
folder: ~/.pub-cache
test_script: flutter test --coverage
test_script:
- pub get
- pub run test_coverage
codecov_script:
- bash <(curl -s https://codecov.io/bash) -t $CODE_COV_TOKEN

publish_task:
only_if: $CIRRUS_BRANCH == 'master'
script: cd doc && deploy.sh
depends_on:
- test
container:
image: node:latest
env:
DEPLOYMENT_TOKEN: ENCRYPTED[892b4e38b52b3ffdf1ebf94761754ae05d32e23bfaf188baba0c651f8152f34dfc310f597a359086f55374387d8b72e8]
node_modules_cache:
folder: doc/node_modules
populate_script:
- cd doc
- yarn install
deploy_docs_script:
- cd doc
- yarn docs:build
- ./deploy.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ coverage/
.pub/
build/
pubspec.lock
test/.test_coverage.dart
coverage_badge.svg

# Android related
**/android/**/gradle-wrapper.jar
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## [v0.2.0]

### Added
- Support for all Dart projects.

## [v0.1.0]

Initial Release

[v0.2.0]: https://github.com/flrx/validator/compare/v0.2.0...v0.1.0
[v0.1.0]: https://github.com/flrx/validator/tag/v0.1.0
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
<!--- Include as many relevant details about the environment you experienced the bug in -->

- Version used:
- Flutter version:
- Flutter/Dart version:
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Validator on Steroids
![Pub](https://img.shields.io/pub/v/flrx_validator)
[![Build Status](https://api.cirrus-ci.com/github/flrx/validator.svg)](https://cirrus-ci.com/github/flrx/validator)
[![codecov](https://codecov.io/gh/flrx/validator/branch/master/graph/badge.svg)](https://codecov.io/gh/flrx/validator)
![GitHub](https://img.shields.io/github/license/flrx/validator)
[![GitHub](https://img.shields.io/github/license/flrx/validator)](https://github.com/flrx/validator/blob/master/LICENSE)

## Installation

Add the following to your `pubspec.yaml` file

```yaml
dependencies:
flrx_validator: ^0.1.0
flrx_validator: ^0.2.0
```
## Usage
Expand Down Expand Up @@ -46,8 +46,8 @@ TextFormField(

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md).
Please see [**CONTRIBUTING**](https://github.com/flrx/validator/blob/develop/CONTRIBUTING.md).

## License

Please see [LICENSE](LICENSE).
Please see [**LICENSE**](https://github.com/flrx/validator/blob/develop/LICENSE).
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Add the following to your `pubspec.yaml` file:

```yaml
dependencies:
flrx_validator: ^0.1.0
flrx_validator: ^0.2.0
```
10 changes: 4 additions & 6 deletions doc/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
# abort on errors
set -e

# build
npm run docs:build

# navigate into the build output directory
cd .vuepress/dist

# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME

git config --global user.email "[email protected]"
git config --global user.name "Cirrus CI: Flrx Validator"
git init
git add -A
git commit -m 'deploy'

git push -f [email protected]:flrx/validator.git master:gh-pages
git remote add origin https://$DEPLOYMENT_TOKEN@github.com/flrx/validator.git
git push -f -u origin master:gh-pages

cd -
3 changes: 2 additions & 1 deletion doc/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

## Introduction

Validator is primarily designed to be used by Flutter's `FormField`'s validator.
Flrx Validator allows you to take a specific value and validate against a set of rules.
It is primarily designed to be used by Flutter's `FormField`'s validator, however you can use it with any Dart 2 Project.

The `Validator` takes a List of `Rule`. The value supplied to the
`Validator` is supplied to the `Rule`s in the order they were registered.
Expand Down
180 changes: 170 additions & 10 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,176 @@
# example
# Validator Examples

A new Flutter project.
## Using FormField

## Getting Started
### example/lib/material_form.dart

This project is a starting point for a Flutter application.
```dart
import 'package:flrx_validator/rules/email_rule.dart';
import 'package:flrx_validator/rules/required_rule.dart';
import 'package:flrx_validator/validator.dart';
import 'package:flutter/material.dart';
A few resources to get you started if this is your first Flutter project:
class MaterialForm extends StatefulWidget {
MaterialForm({Key key}) : super(key: key);
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
@override
_MaterialFormState createState() => _MaterialFormState();
}
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
class _MaterialFormState extends State<MaterialForm> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Material Form Validator')),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
validator:
Validator().add(RequiredRule()).add(EmailRule()).build(),
decoration: InputDecoration(hintText: 'Email'),
),
buildDropdown(),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
onPressed: onFormSubmitPressed,
child: Text('Submit'),
),
),
],
),
),
),
);
}
Widget buildDropdown() {
return DropdownButtonFormField<String>(
validator: Validator().add(RequiredRule()).build(),
value: "",
items: <DropdownMenuItem<String>>[
DropdownMenuItem<String>(
child: Text('Please select an Item'),
value: "",
),
DropdownMenuItem<String>(
child: Text('Item 1'),
value: "Item 1",
)
],
);
}
void onFormSubmitPressed() {
if (_formKey.currentState.validate()) {
// Process data.
}
}
}
```

## Using TextEditingController

### example/lib/cupertino_form.dart

```dart
import 'package:flrx_validator/rules/email_rule.dart';
import 'package:flrx_validator/rules/required_rule.dart';
import 'package:flrx_validator/validator.dart';
import 'package:flutter/cupertino.dart';
class CupertinoForm extends StatefulWidget {
@override
_CupertinoFormState createState() => _CupertinoFormState();
}
class _CupertinoFormState extends State<CupertinoForm> {
TextEditingController _textEditingController = TextEditingController();
String emailValidationMessage = "";
@override
Widget build(BuildContext context) {
return DefaultTextStyle(
style: const TextStyle(
fontFamily: '.SF UI Text',
inherit: false,
fontSize: 17.0,
color: CupertinoColors.black,
),
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
previousPageTitle: "Form Selection",
middle: Text('Cupertino Form Validation'),
),
child: CupertinoScrollbar(
child: SingleChildScrollView(
padding:
const EdgeInsets.symmetric(vertical: 32.0, horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 72),
CupertinoTextField(
controller: _textEditingController,
prefixMode: OverlayVisibilityMode.always,
placeholder: 'Email',
prefix: Icon(
CupertinoIcons.mail_solid,
color: CupertinoColors.lightBackgroundGray,
size: 28.0,
),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 0.0, color: CupertinoColors.inactiveGray)),
),
padding:
EdgeInsets.symmetric(horizontal: 6.0, vertical: 12.0),
clearButtonMode: OverlayVisibilityMode.editing,
),
Padding(
padding: const EdgeInsets.fromLTRB(34, 8, 16, 16),
child: Text(
emailValidationMessage,
style: TextStyle(
color: CupertinoColors.destructiveRed,
fontSize: 12,
),
),
),
Center(
child: CupertinoButton.filled(
child: Text('Submit'), onPressed: onFormSubmitPressed),
)
],
),
),
)),
);
}
@override
void dispose() {
_textEditingController.dispose();
super.dispose();
}
void onFormSubmitPressed() {
String value = _textEditingController.text;
setState(() {
emailValidationMessage = Validator<String>()
.add(RequiredRule())
.add(EmailRule())
.validate(value) ??
'';
});
}
}
```
9 changes: 4 additions & 5 deletions lib/validator.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:flutter/widgets.dart';
import 'package:flrx_validator/rule.dart';
import 'package:flrx_validator/src/string_utils.dart';

/// A class primarily designed to be used by [FormField]'s validator.
/// A class primarily designed to retrieve validation messages based on [Rule]s.
///
/// The [Validator] class takes a List of [Rule]. The value supplied to the
/// [Validator] is supplied to the [Rule]s in the order they were registered.
/// The error message of the first [Rule] that fails is returned back.
/// If all the [Rule]s pass, then null is returned to the [FormField].
/// If all the [Rule]s pass, then null is returned.
class Validator<T> {
Validator(
{this.entityName = "Entity",
Expand Down Expand Up @@ -40,8 +39,8 @@ class Validator<T> {
return this;
}

/// Returns a [FormFieldValidator] to be used with a [FormField].
FormFieldValidator<T> build() => validate;
/// Returns a Function that can be called to validate. Added as a convenience for Flutter
String Function(T value) build() => validate;

/// Validates and returns an error message(if any).
String validate(T value) {
Expand Down
12 changes: 5 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: flrx_validator
description: Validator on steroids
version: 0.1.0
description: >
A powerful, extensible validator package to get validation messages based on a list of rules.
version: 0.2.0
author: Flrx Team <[email protected]>
homepage: https://flrx.github.io/validator/

Expand All @@ -9,10 +10,7 @@ environment:

dependencies:
meta: ^1.1.6
flutter:
sdk: flutter

dev_dependencies:
flutter_test:
sdk: flutter
test_api: ^0.2.5
test: ^1.6.5
test_coverage: ^0.3.0+1
2 changes: 1 addition & 1 deletion test/string_utils_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:test_api/test_api.dart';
import 'package:flrx_validator/src/string_utils.dart';
import 'package:test/test.dart';

void main() {
group('routes replaceWithValues function test', () {
Expand Down
2 changes: 1 addition & 1 deletion test/validator/any_rule_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:test_api/test_api.dart';
import 'package:test/test.dart';
import 'package:flrx_validator/rules/any_rule.dart';
import 'package:flrx_validator/src/string_utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/validator/email_rule_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:test_api/test_api.dart';
import 'package:test/test.dart';
import 'package:flrx_validator/rules/email_rule.dart';
import 'package:flrx_validator/src/string_utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/validator/max_length_rule_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:test_api/test_api.dart';
import 'package:test/test.dart';
import 'package:flrx_validator/rules/max_length_rule.dart';
import 'package:flrx_validator/src/string_utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/validator/min_length_rule_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:test_api/test_api.dart';
import 'package:test/test.dart';
import 'package:flrx_validator/rules/min_length_rule.dart';
import 'package:flrx_validator/src/string_utils.dart';

Expand Down
Loading

0 comments on commit 3c06051

Please sign in to comment.