-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
render display in the fixed position style
- Loading branch information
1 parent
1745830
commit 193aed2
Showing
8 changed files
with
185 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Ember from 'ember'; | ||
const { isPresent } = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
tagName: 'div', | ||
|
||
classNames: ['display'], | ||
|
||
termOne: null, | ||
|
||
termTwo: null, | ||
|
||
answer: null, | ||
|
||
level: null, | ||
|
||
operator: null, | ||
|
||
isEqualVisible: false, | ||
|
||
_pad(value, length) { | ||
return ` ${String(string)}`.slice(-length).split('').map((s) => { | ||
return isPresent(s.trim()) ? s : ''; | ||
}); | ||
}, | ||
|
||
characters: Ember.computed('termOne', 'termTwo', 'level', 'operator', function() { | ||
let characters = []; | ||
|
||
if (isPresent(this.get('termOne'))) { | ||
characters = characters.concat(` ${this.get('termOne').toString()}`.slice(-2).split('')); | ||
} else { | ||
characters = characters.concat(['','']); | ||
} | ||
if (isPresent(this.get('operator'))) { | ||
characters.pushObject(this.get('operator')); | ||
} | ||
if (isPresent(this.get('termTwo'))) { | ||
characters = characters.concat(this._pad(this.get('termTwo'))); | ||
} else { | ||
characters = characters.concat(['','']); | ||
} | ||
if (this.get('displayEquals')) { | ||
characters.pushObject('='); | ||
} else { | ||
characters.pushObject(' ') | ||
} | ||
if (isPresent(this.get('level'))) { | ||
characters = characters.concat(['L','',this.get('level')]); | ||
} else { | ||
if (isPresent(this.get('answer'))) { | ||
characters = characters.concat(` ${this.get('answer').toString()}`.slice(-2).split('')); | ||
} else { | ||
characters = characters.concat(['','']); | ||
} | ||
} | ||
|
||
return characters; | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Ember from 'ember'; | ||
const { isPresent } = Ember; | ||
|
||
export function formatTerm(params) { | ||
const term = params[0]; | ||
let formatted; | ||
const characters = ['','']; | ||
|
||
if (isPresent(term)) { | ||
const termCharacters = String(term).split(''); | ||
termCharacters.reverse().forEach((character, index) => { | ||
characters[characters.length - index - 1] = character; | ||
}); | ||
} | ||
|
||
return new Ember.Handlebars.SafeString(characters.map((c) => { | ||
return `<span class='display-character'>${c}</span>`; | ||
}).join('')); | ||
} | ||
|
||
export default Ember.Helper.helper(formatTerm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<div class="display-characters"> | ||
{{format-term termOne}} | ||
|
||
<span class="display-character"> | ||
{{#if operator}} | ||
{{format-operator operator}} | ||
{{/if}} | ||
</span> | ||
|
||
{{format-term termTwo}} | ||
|
||
<span class="display-character"> | ||
{{#if isEqualVisible}} | ||
= | ||
{{/if}} | ||
</span> | ||
|
||
{{#if level}} | ||
<span class="display-character">L</span> | ||
<span class="display-character"></span> | ||
<span class="display-character">{{level}}</span> | ||
{{else if isError}} | ||
<span class="display-character">E</span> | ||
<span class="display-character">E</span> | ||
<span class="display-character">E</span> | ||
{{else}} | ||
{{#if blink}} | ||
<span class="blink"> | ||
{{format-term answer}} | ||
</span> | ||
{{else}} | ||
{{format-term answer}} | ||
{{/if}} | ||
{{/if}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('display-characters', 'Integration | Component | display characters', { | ||
integration: true | ||
}); | ||
|
||
test('it renders', function(assert) { | ||
|
||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.on('myAction', function(val) { ... });" + EOL + EOL + | ||
|
||
this.render(hbs`{{display-characters}}`); | ||
|
||
assert.equal(this.$().text().trim(), ''); | ||
|
||
// Template block usage:" + EOL + | ||
this.render(hbs` | ||
{{#display-characters}} | ||
template block text | ||
{{/display-characters}} | ||
`); | ||
|
||
assert.equal(this.$().text().trim(), 'template block text'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { formatTerm } from '../../../helpers/format-term'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Helper | format term'); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
let result = formatTerm(42); | ||
assert.ok(result); | ||
}); |