Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 Rewrite #229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.css]
indent_style = space
indent_size = 2

[*.html]
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
extends: 'eslint:recommended',
env: {
'browser': true
},
rules: {
}
};
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
testem.log
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ cache:
- node_modules

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-1.13
# we recommend testing LTS's and latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.8
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand All @@ -24,7 +24,9 @@ matrix:
before_install:
- npm config set spin false
- npm install -g bower
- bower --version
- npm install phantomjs-prebuilt
- node_modules/phantomjs-prebuilt/bin/phantomjs --version

install:
- npm install
Expand All @@ -33,4 +35,4 @@ install:
script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try $EMBER_TRY_SCENARIO test --skip-cleanup
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ This README outlines the details of collaborating on this Ember addon.

## Installation

* `git clone` this repository
* `git clone <repository-url>` this repository
* `cd ember-easy-form`
* `npm install`
* `bower install`

## Running

* `ember server`
* Visit your app at http://localhost:4200.
* `ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).

## Running Tests

* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions)
* `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions)
* `ember test`
* `ember test --server`

Expand Down
7 changes: 7 additions & 0 deletions addon/components/form-control-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';
import layout from '../templates/components/form-control-helper';

export default Ember.Component.extend({
layout,
classNames: ['form-control-helper']
});
35 changes: 35 additions & 0 deletions addon/components/form-controls/-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Ember from 'ember';
import layout from '../../templates/components/form-controls/-base';

const {
get,
set,
guidFor,
computed,
computed: { alias },
String: { capitalize },
Component
} = Ember;

let BaseComponent = Component.extend({
layout,
init() {
let property = get(this, 'property');
let value = alias(`subject.${property}`);
set(this, 'value', value);
return this._super(...arguments);
},
controlId: computed(function() {
return guidFor({});
}),
label: computed(function() {
let property = get(this, 'property');
return capitalize(property);
})
});

BaseComponent.reopenClass({
positionalParams: ['property']
});

export default BaseComponent;
44 changes: 44 additions & 0 deletions addon/components/form-controls/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Ember from 'ember'
import BaseComponent from './-base';

const {
get,
computed
} = Ember;

const types = [
'color',
'datetime-local',
'datetime',
'date',
'time',
'email',
'file',
'month',
'number',
'password',
'range',
'search',
'tel',
'text',
'url',
'week'
];

export default BaseComponent.extend({
controlType: '-text-field',

type: computed('property', function() {
let property = get(this, 'property').toLowerCase();
let type;

for (let i = 0; i < types.length; i++) {
if (property.indexOf(types[i]) > -1) {
type = types[i];
break;
}
}

return type || 'text';
})
});
5 changes: 5 additions & 0 deletions addon/components/form-controls/textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseComponent from './-base';

export default BaseComponent.extend({
controlType: '-text-area'
});
38 changes: 38 additions & 0 deletions addon/components/form-for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ember from 'ember';
import layout from '../templates/components/form-for';

const {
get,
Component,
Error: EmberError
} = Ember;

let FormForComponent = Component.extend({
layout,
classNames: ['easy-form'],
tagName: 'form',

init() {
let subject = get(this, 'subject');

if (!subject) {
let error = new EmberError('subject must be passed to `form-for` as either positional param or explicit param');
throw(error);
}

for (let key in this) {
if (key.indexOf('HAS_BLOCK') !== -1 && !this[key]) {
let error = new EmberError('cannot take inline, only block');
throw(error);
}
}

return this._super(...arguments);
}
});

FormForComponent.reopenClass({
positionalParams: ['subject']
});

export default FormForComponent;
5 changes: 5 additions & 0 deletions addon/templates/components/form-control-helper.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if hasBlock}}
{{yield}}
{{else}}
{{text}}
{{/if}}
9 changes: 9 additions & 0 deletions addon/templates/components/form-controls/-base.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{#if hasBlock}}
{{yield}}
{{else}}
<label for={{controlId}}>{{label}}</label>
{{component controlType id=controlId value=value type=type}}
{{#if helper}}
{{form-control-helper text=helper}}
{{/if}}
{{/if}}
4 changes: 4 additions & 0 deletions addon/templates/components/form-for.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{yield (hash
input=(component "form-controls/input" subject=subject)
textarea=(component "form-controls/textarea" subject=subject)
)}}
1 change: 1 addition & 0 deletions app/components/form-control-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-easy-form/components/form-control-helper';
1 change: 1 addition & 0 deletions app/components/form-controls/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-easy-form/components/form-controls/input';
1 change: 1 addition & 0 deletions app/components/form-controls/textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-easy-form/components/form-controls/textarea';
1 change: 1 addition & 0 deletions app/components/form-for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-easy-form/components/form-for';
6 changes: 2 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "ember-easy-form",
"dependencies": {
"ember": "~2.5.0",
"ember-cli-shims": "0.1.1",
"ember-cli-test-loader": "0.2.2",
"ember-qunit-notifications": "0.1.0"
"ember": "~2.10.0-beta.3",
"ember-cli-shims": "0.1.3"
}
}
12 changes: 3 additions & 9 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
module.exports = {
scenarios: [
{
name: 'default',
bower: {
dependencies: { }
}
},
{
name: 'ember-1.13',
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': '~1.13.0'
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': '~1.13.0'
'ember': 'lts-2-8'
}
}
},
Expand Down
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,38 @@
},
"repository": "",
"engines": {
"node": ">= 0.10.0"
"node": ">= 0.12.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"ember-ajax": "^2.0.1",
"ember-cli": "2.6.0-beta.1",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "^1.0.0",
"ember-cli-qunit": "^1.4.0",
"ember-cli-release": "0.2.8",
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
"ember-cli": "2.9.1",
"ember-cli-app-version": "^2.0.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "3.0.0",
"ember-cli-htmlbars-inline-precompile": "^0.3.3",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^3.0.1",
"ember-cli-release": "^0.2.9",
"ember-cli-sri": "^2.1.0",
"ember-cli-test-loader": "^1.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.5.0",
"ember-data": "^2.9.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-export-application-global": "^1.0.5",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-welcome-page": "^1.0.1",
"loader.js": "^4.0.1"
"eslint-plugin-ember-suave": "^1.0.0",
"loader.js": "^4.0.10"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.6"
"ember-cli-babel": "^5.1.7",
"ember-cli-htmlbars": "^1.0.10"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
5 changes: 5 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: {
'embertest': true
}
};
Loading