Skip to content

Commit

Permalink
Bugfixes for require/reject group attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Jul 14, 2019
1 parent bb41bba commit 448ead9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
79 changes: 46 additions & 33 deletions src/load.js
Expand Up @@ -1116,39 +1116,8 @@ var CSL = {
UPDATE_GROUP_CONTEXT_CONDITION: function (state, termtxt, valueTerm) {
if (state.tmp.group_context.tip.condition) {
if (state.tmp.group_context.tip.condition.test) {
var testres;
if (state.tmp.group_context.tip.condition.test === "empty-label") {
testres = !termtxt;
} else if (state.tmp.group_context.tip.condition.test === "empty-label-no-decor") {
testres = !termtxt || termtxt.indexOf("%s") > -1;
} else if (state.tmp.group_context.tip.condition.test === "comma-safe") {
var empty = !termtxt;
var alpha = termtxt.slice(0,1).match(CSL.ALL_ROMANESQUE_REGEXP);
var num = state.tmp.just_did_number;
if (empty) {
testres = true;
} else if (num) {
if (alpha && !valueTerm) {
testres = true;
} else {
testres = false;
}
} else {
if (alpha && !valueTerm) {
testres = true;
} else {
testres = false;
}
}
}
if (testres) {
state.tmp.group_context.tip.force_suppress = false;
} else {
state.tmp.group_context.tip.force_suppress = true;
}
if (state.tmp.group_context.tip.condition.not) {
state.tmp.group_context.tip.force_suppress = !state.tmp.group_context.tip.force_suppress;
}
state.tmp.group_context.tip.condition.termtxt = termtxt;
state.tmp.group_context.tip.condition.valueTerm = valueTerm;
}
} else {
// If not inside a conditional group, raise numeric flag
Expand All @@ -1161,6 +1130,50 @@ var CSL = {
}
},

EVALUATE_GROUP_CONDITION: function(state, flags) {
var testres;
if (flags.condition.test === "empty-label") {
testres = !flags.condition.termtxt;
} else if (flags.condition.test === "empty-label-no-decor") {
testres = !flags.condition.termtxt || flags.condition.termtxt.indexOf("%s") > -1;
} else if (flags.condition.test === "comma-safe") {
var empty = !flags.condition.termtxt;
var termStartAlpha = false;
if (flags.condition.termtxt) {
termStartAlpha = flags.condition.termtxt.slice(0,1).match(CSL.ALL_ROMANESQUE_REGEXP);
}
var num = state.tmp.just_did_number;
if (empty) {
// i.e. Big L. Rev. 100, 102
// Little L. Rev. 102
// L. Rev. for Plan 9, 102
if (num) {
testres = true;
} else {
testres = false;
}
} else if (flags.condition.valueTerm) {
// i.e. Ibid. at 102
testres = false;
} else {
if (termStartAlpha) {
testres = true;
} else {
testres = false;
}
}
}
if (testres) {
var force_suppress = false;
} else {
var force_suppress = true;
}
if (flags.condition.not) {
force_suppress = !force_suppress;
}
return force_suppress;
},

SYS_OPTIONS: [
"prioritize_disambiguate_condition",
"csl_reverse_lookup_support",
Expand Down
13 changes: 10 additions & 3 deletions src/node_group.js
Expand Up @@ -57,7 +57,6 @@ CSL.Node.group = {
test: this.strings.reject,
not: true
};
force_suppress = true;
done_vars = [];
} else if (this.strings.require) {
condition = {
Expand Down Expand Up @@ -285,6 +284,9 @@ CSL.Node.group = {
// print("POP parent="+JSON.stringify(state.tmp.group_context.tip, params))
// print(" flags="+JSON.stringify(flags, params));
//}
if (flags.condition) {
flags.force_suppress = CSL.EVALUATE_GROUP_CONDITION(state, flags);
}
if (state.tmp.group_context.tip.condition) {
state.tmp.group_context.tip.force_suppress = flags.force_suppress;
}
Expand Down Expand Up @@ -312,15 +314,20 @@ CSL.Node.group = {
if (flags.force_suppress && !state.tmp.group_context.tip.condition) {
state.tmp.group_context.tip.variable_attempt = true;
state.tmp.group_context.tip.variable_success = flags.variable_success_parent;
}
if (flags.force_suppress) {
// 2019-04-15
// This is removing variables done within the group we're leaveing from global
// done_vars? How does that make sense?
// Ah. This is a FAILURE. So removing from done_vars allows it to re-render
// later in the cite if desired.
// Currently no tests fail from removing the condition, but leaving it in.
for (var i=0,ilen=flags.done_vars.length;i<ilen;i++) {
if (state.tmp.done_vars.indexOf(flags.done_vars[i]) > -1) {
state.tmp.done_vars = state.tmp.done_vars.slice(0, i).concat(state.tmp.done_vars.slice(i+1));
var doneVar = flags.done_vars[i];
for (var j=0,jlen=state.tmp.done_vars.length; j<jlen; j++) {
if (state.tmp.done_vars[j] === doneVar) {
state.tmp.done_vars = state.tmp.done_vars.slice(0, j).concat(state.tmp.done_vars.slice(j+1));
}
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/node_text.js
Expand Up @@ -224,17 +224,18 @@ CSL.Node.text = {
if (this.variables_real[0] !== "locator") {
state.tmp.have_collapsed = false;
}
var parallel_variable = this.variables[0];

if (parallel_variable === "title"
&& (form === "short" || Item["title-short"])) {
// Only if not main_title_from_short_title
parallel_variable = "title-short";
}

if (!state.tmp.group_context.tip.condition && Item[this.variables[0]]) {
state.tmp.just_did_number = false;
}
var val = Item[this.variables[0]];
if (val && !state.tmp.group_context.tip.condition) {
if (("" + val).slice(-1).match(/[0-9]/)) {
state.tmp.just_did_number = true;
} else {
state.tmp.just_did_number = false;
}
}
};
this.execs.push(func);

Expand Down

0 comments on commit 448ead9

Please sign in to comment.