Skip to content

Commit

Permalink
Merge pull request #869 from Program-AR/develop
Browse files Browse the repository at this point in the history
1.8.1
  • Loading branch information
tfloxolodeiro authored Nov 30, 2021
2 parents bd04a54 + d64cb56 commit 60b58ef
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 61 deletions.
5 changes: 4 additions & 1 deletion app/components/header.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
tagName: 'div',
classNames: [],
storage: service(),


didRender() {
document.documentElement.setAttribute('theme', localStorage.getItem('theme') || 'light');
document.documentElement.setAttribute('theme', this.storage.getUseNightTheme() ? 'dark' : 'light');
},

});
20 changes: 5 additions & 15 deletions app/components/night-mode-toggle.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({

tagName: 'div',
classNames: [],
storage: service(),
isNightTheme: false,

didRender() {
this.set('isNightTheme', localStorage.getItem('theme') === 'dark');
},

setLightTheme() {
localStorage.setItem('theme', 'light');
},

setDarkTheme() {
localStorage.setItem('theme', 'dark');
this.set('isNightTheme', this.storage.getUseNightTheme());
},

actions: {
toggleTheme() {
if (this.isNightTheme) {
this.setLightTheme();
}
else {
this.setDarkTheme();
}
this.storage.toggleNightTheme();
}
}

Expand Down
27 changes: 17 additions & 10 deletions app/services/pilas-mulang.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default Service.extend({

function buildBlockAst(block) {
if (block.isShadow()) return createEmptyNode()
let {tag, parse} = mulangParser(block)
let { tag, parse } = mulangParser(block)
return createNode(tag, parse(block))
}

function mulangParser(block) {
let parser = pilasToMulangParsers[block.type] || searchAlias(block)
let parser = pilasToMulangParsers[block.type] || searchAlias(block)
if (parser) return parser
return isValue(block) ? referenceParser : applicationParser
}
Expand Down Expand Up @@ -49,9 +49,9 @@ let ifParser = {
parse: parseIf
}

let whileParser = {
let untilParser = {
tag: "While",
parse: parseWhile
parse: parseUntil
}

let numberParser = {
Expand Down Expand Up @@ -80,7 +80,7 @@ let pilasToMulangParsers = {
"repetir": repeatParser,
"Si": ifParser,
"SiNo": { ...ifParser, parse: parseIfElse },
"Hasta": whileParser,
"Hasta": untilParser,
"math_number": numberParser,
"Numero": numberParser,
"procedures_defnoreturn": procedureParser,
Expand Down Expand Up @@ -109,9 +109,9 @@ function parseEntryPoint(block) {
}

function referenceName(block) {
return isProcedureCall(block) ? block.getFieldValue('NAME')
: isOperator(block) ? block.getFieldValue('OP')
: block.type
return isProcedureCall(block) ? block.getFieldValue('NAME')
: isOperator(block) ? block.getFieldValue('OP')
: block.type
}

function parseApplication(block) {
Expand Down Expand Up @@ -152,11 +152,11 @@ function parseRepeat(block) {
]
}

function parseWhile(block) {
function parseUntil(block) {
let condition = block.getInputTargetBlock("condition")
let statements = block.getInputTargetBlock("block")
return [
buildBlockAst(condition),
negate(buildBlockAst(condition)),
buildSequenceAst(statements)
]
}
Expand Down Expand Up @@ -203,4 +203,11 @@ function parseEquationParams(block) {
function parseEquationBody(block) {
let bodyContents = buildSequenceAst(getChild(block))
return createNode("UnguardedBody", bodyContents)
}

function negate(condition) {
return {
tag: "Application",
contents: [{ tag: "Primitive", contents: "Negation" }, [condition]]
}
}
7 changes: 6 additions & 1 deletion app/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default Ember.Service.extend({
USER_KEY: 'PB_USER',
ANALYTICS_KEY: 'PB_ANALYTICS_SESSION',
TOS_ACCEPTED_KEY: 'PB_TOS_ACCEPTED',
USE_NIGHT_THEME_KEY: 'PB_USE_NIGHT_THEME',

getUserId() {
const user = this.getUser()
Expand All @@ -26,6 +27,10 @@ export default Ember.Service.extend({

termsAreAccepted() { return this._get(this.TOS_ACCEPTED_KEY) },

getUseNightTheme() { return this._get(this.USE_NIGHT_THEME_KEY) },

toggleNightTheme() { this._save(this.USE_NIGHT_THEME_KEY, !this.getUseNightTheme()) },

clear() { localStorage.clear() },

_get(key) {
Expand All @@ -43,4 +48,4 @@ export default Ember.Service.extend({
this.router.transitionTo('clear')
}
},
})
})
72 changes: 43 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions tests/helpers/astFactories.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ export function ifElse(condition, seqTrue, seqFalse) {
}
}

export function muWhile(condition, ...seq) {
export function muUntil(condition, ...seq) {
return {
tag: "While",
contents: [
condition,
primitiveApplication('Negation', condition),
sequence(...seq)
]
}
Expand All @@ -129,4 +129,18 @@ export function none() {
tag: "None",
contents: []
}
}

function primitive(name) {
return {
tag: "Primitive",
contents: name
}
}

function primitiveApplication(name, ...params) {
return {
tag: "Application",
contents: [primitive(name), params]
}
}
6 changes: 3 additions & 3 deletions tests/unit/services/mulang-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QUnit, { module, test } from 'qunit'
import { setupTest } from 'ember-qunit'
import { blocklyWorkspaceMock } from '../../helpers/mocks'
import { procedure, entryPoint, sequence, reference, application, repeat, muIf, ifElse, muWhile, number, string, none } from '../../helpers/astFactories'
import { procedure, entryPoint, sequence, reference, application, repeat, muIf, ifElse, muUntil, number, string, none } from '../../helpers/astFactories'
import { setUpTestLocale } from '../../helpers/utils';

let pilasMulang = null
Expand Down Expand Up @@ -175,7 +175,7 @@ module('Unit | Service | pilas-mulang', function (hooks) {
</block>
`
mulangParseBlockTest('hasta', hasta,
muWhile(
muUntil(
application("TocandoFinal"),
application("EncenderLuz"),
application("MoverACasillaAbajo")
Expand Down Expand Up @@ -674,7 +674,7 @@ module('Unit | Service | pilas-mulang', function (hooks) {
),
procedure('Prender compus hacia', ['direccion'],
application('MoverA', reference('direccion')),
muWhile(application('EstoyEnEsquina'),
muUntil(application('EstoyEnEsquina'),
application('PrenderComputadora'),
application('MoverA', reference('direccion')),
),
Expand Down

0 comments on commit 60b58ef

Please sign in to comment.