Skip to content
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
2 changes: 1 addition & 1 deletion lib/filters/clean_class/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { newTwingFilter } from '../../helpers/twing.js';
import config from '../../config.js';
import { name, options, acceptedArguments, cleanClass } from './definition.js';

export async function callable(string) {
export async function callable(_ctx, string) {
return cleanClass(config, string);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/filters/clean_id/twing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { newTwingFilter } from '../../helpers/twing.js';
import { name, options, acceptedArguments, cleanID } from './definition.js';

export async function callable(...args) {
export async function callable(_ctx, ...args) {
return cleanID(...args);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/filters/format_date/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* ```
*/

import date from 'locutus/php/datetime/date.js';
import { date } from 'locutus/php/datetime/date';

export const name = 'format_date';

Expand Down
9 changes: 8 additions & 1 deletion lib/filters/format_date/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { newTwingFilter } from '../../helpers/twing.js';
import config from '../../config.js';
import { name, options, acceptedArguments, formatDate } from './definition.js';

export async function callable(timestamp, type, format, timezone, langcode) {
export async function callable(
_ctx,
timestamp,
type,
format,
timezone,
langcode,
) {
return formatDate(config, timestamp, type, format, timezone, langcode);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/filters/placeholder/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
wrapPlaceholder,
} from './definition.js';

export async function callable(template, value) {
const escapedValue = await escape(template, value, 'html', null, true);
return wrapPlaceholder(escapedValue);
export async function callable(_ctx, value) {
const escapedValue = await escape(_ctx, value, 'html');
return wrapPlaceholder(String(escapedValue));
}

export default newTwingFilter(name, callable, options, acceptedArguments);
2 changes: 1 addition & 1 deletion lib/filters/render/twing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { newTwingFilter } from '../../helpers/twing.js';
import { name, options, acceptedArguments, renderVar } from './definition.js';

export async function callable(...args) {
export async function callable(_ctx, ...args) {
return renderVar(...args);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/filters/safe_join/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { isTraversable } from 'twing/dist/cjs/lib/helpers/is-traversable.js';
import { newTwingFilter } from '../../helpers/twing.js';
import { name, options, acceptedArguments } from './definition.js';

export async function callable(value, glue) {
export async function callable(executionContext, value, glue) {
// Twing's join() doesn't join Object values like it should. Issue #44
// @see https://gitlab.com/nightlycommit/twing/-/issues/544
// @see https://github.com/JohnAlbin/drupal-twig-extensions/issues/45
const newValue =
typeof value === 'object' && !isTraversable(value)
? Object.values(value)
: value;
return join(newValue, glue);
return join(executionContext, newValue, glue, null);
}

export default newTwingFilter(name, callable, options, acceptedArguments);
11 changes: 1 addition & 10 deletions lib/filters/without/twing.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { newTwingFilter } from '../../helpers/twing.js';
import { name, options, without } from './definition.js';

export async function callable(element, argsMap) {
// Twing will give an is_variadic filter its arguments as a Map.
const args = Array.from(argsMap.values()).map((value) => {
if (value instanceof Map) {
// Twing v5 converts Twig [] into JS Maps; convert to an Array.
return Array.from(value.values());
} else {
return value;
}
});
export async function callable(_ctx, element, ...args) {
return without(element, ...args);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/functions/active_theme/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

export const name = 'active_theme';

export const options = {};
export const options = { is_variadic: true };

export const acceptedArguments = [];

Expand Down
3 changes: 2 additions & 1 deletion lib/functions/active_theme/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { newTwingFunction } from '../../helpers/twing.js';
import config from '../../config.js';
import { name, options, acceptedArguments, activeTheme } from './definition.js';

export async function callable() {
// eslint-disable-next-line no-unused-vars
export async function callable(_ctx) {
return activeTheme(config);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/functions/active_theme_path/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

export const name = 'active_theme_path';

export const options = {};
export const options = { is_variadic: true };

export const acceptedArguments = [];

Expand Down
3 changes: 2 additions & 1 deletion lib/functions/active_theme_path/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
activeThemePath,
} from './definition.js';

export async function callable() {
// eslint-disable-next-line no-unused-vars
export async function callable(_ctx) {
return activeThemePath(config);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/functions/create_attribute/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
createAttribute,
} from './definition.js';

export async function callable(...args) {
export async function callable(_ctx, ...args) {
return createAttribute(...args);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/functions/file_url/twing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { newTwingFunction } from '../../helpers/twing.js';
import config from '../../config.js';
import { name, options, acceptedArguments, fileUrl } from './definition.js';

export async function callable(uri) {
export async function callable(_ctx, uri) {
return fileUrl(config, uri);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/functions/link/twing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { newTwingFunction } from '../../helpers/twing.js';
import { name, options, acceptedArguments, link } from './definition.js';

export async function callable(...args) {
export async function callable(_ctx, ...args) {
return link(...args);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/functions/render_var/twing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { newTwingFunction } from '../../helpers/twing.js';
import { name, options, renderVar } from './definition.js';
import { name, options, acceptedArguments, renderVar } from './definition.js';

export async function callable(...args) {
export async function callable(_ctx, ...args) {
return renderVar(...args);
}

export default newTwingFunction(name, callable, options);
export default newTwingFunction(name, callable, options, acceptedArguments);
3 changes: 2 additions & 1 deletion lib/helpers/twing/newEmptyStringFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const newEmptyStringFunction = (
) =>
newTwingFunction(
functionName,
async function () {
// eslint-disable-next-line no-unused-vars
async function (_ctx) {
return '';
},
options,
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/twing/newPassThroughFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const newPassThroughFilter = (
) =>
newTwingFilter(
filterName,
async function (value) {
async function (_ctx, value) {
return value;
},
options,
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/twing/newPassThroughFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const newPassThroughFunction = (
) =>
newTwingFunction(
functionName,
async function (value) {
async function (_ctx, value) {
return value;
},
options,
Expand Down
10 changes: 2 additions & 8 deletions lib/helpers/twing/newTwingFilter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { TwingFilter } from 'twing';
import { createFilter } from 'twing';

const newTwingFilter = (name, callable, options, acceptedArguments = []) =>
new TwingFilter(
name,
callable,
// @TODO File bug report; 3rd argument should be options.
acceptedArguments,
options,
);
createFilter(name, callable, acceptedArguments, options);

export default newTwingFilter;
10 changes: 2 additions & 8 deletions lib/helpers/twing/newTwingFunction.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { TwingFunction } from 'twing';
import { createFunction } from 'twing';

const newTwingFunction = (name, callable, options, acceptedArguments = []) =>
new TwingFunction(
name,
callable,
// @TODO File bug report; 3rd argument should be options.
acceptedArguments,
options,
);
createFunction(name, callable, acceptedArguments, options);

export default newTwingFunction;
Loading