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

docs(jsdoc): #3840 document all Meteor Template helpers in 1 @namespace #3841

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 34 additions & 37 deletions client/modules/core/helpers/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,17 @@ import { Reaction } from "/client/api";
import { Packages, Shops } from "/lib/collections";
import { Registry } from "/lib/collections/schemas/registry";


/**
*
* reactionApps
* provides="<where matching registry provides is this >"
* enabled=true <false for disabled packages>
* context= true filter templates to current route
* returns matching package registry objects
* @example {{#each reactionApps provides="settings" name=packageName container=container}}
* @example {{#each reactionApps provides="userAccountDropdown" enabled=true}}
* @example
* {{#each reactionApps provides="social" name="reaction-social"}}
* {{> Template.dynamic template=template data=customSocialSettings }}
* {{/each}}
*
* @typedef optionHash
* @type {object}
* @property {string} name - name of a package.
* @property {string} provides -purpose of this package as identified to the registry
* @property {string} container - filter registry entries for matching container.
* @property {string} shopId - filter to only display results matching shopId, not returned
* @property {string} template - filter registry entries for matching template
* @type {optionHash}
*
* @return {optionHash} returns an array of filtered, structure reactionApps
* [{
* enabled: true
* label: "Stripe"
* name: "reaction-stripe"
* packageId: "QqkGsQCDRhg2LSn8J"
* priority: 1
* provides: "paymentMethod"
* template: "stripePaymentForm"
* etc: "additional properties as defined in Packages.registry"
* ...
* }]
* @method Apps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that this is actually a template helper? We use it in templates but I think we use it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would reactionApps be a better fit in Helpers?

* @typedef optionHash
* @type {object}
* @property {string} name - name of a package.
* @property {string} provides -purpose of this package as identified to the registry
* @property {string} container - filter registry entries for matching container.
* @property {string} shopId - filter to only display results matching shopId, not returned
* @property {string} template - filter registry entries for matching template
* @return {optionHash} returns an array of filtered, structure reactionApps
*/

export function Apps(optionHash) {
const filter = {};
const registryFilter = {};
Expand Down Expand Up @@ -180,5 +153,29 @@ export function Apps(optionHash) {
return sortedApps;
}

// Register global template helper
/**
*
* @method reactionApps
* @memberof Templates
* @summary Return an array of filtered, structured `reactionApps` as a Template Helper
* @example {{#each reactionApps provides="settings" name=packageName container=container}}
* @example {{#each reactionApps provides="userAccountDropdown" enabled=true}}
* @property {string} name - name of a package.
* @property {string} provides -purpose of this package as identified to the registry
* @property {string} container - filter registry entries for matching container.
* @property {string} shopId - filter to only display results matching shopId, not returned
* @property {string} template - filter registry entries for matching template
* @return {optionHash} returns an array of filtered, structure reactionApps
* ```[{
* enabled: true
* label: "Stripe"
* name: "reaction-stripe"
* packageId: "QqkGsQCDRhg2LSn8J"
* priority: 1
* provides: "paymentMethod"
* template: "stripePaymentForm"
* etc: "additional properties as defined in Packages.registry"
* ...
* }]```
*/
Template.registerHelper("reactionApps", (optionHash) => Reaction.Apps(optionHash));
8 changes: 4 additions & 4 deletions client/modules/core/helpers/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Logger from "/client/modules/logger";
import * as Collections from "/lib/collections";

/**
* reactionTemplate helper
* use the reactionTemplate helper when you are using templates defined
* @name reactionTemplate
* @summary use the reactionTemplate helper when you are using templates defined
* as workflow templates in the package registery.Layout
* use "collection" on the layout to indicate a workflow source
*
* @summary reactionTemplate provides templates as defined in ReactionRegistry.Layout
* @memberof Template
* @description reactionTemplate provides templates as defined in ReactionRegistry.Layout
* @param {Object} options - workflow defaults to "coreLayout/coreWorkflow"
* @returns {Array} returns an array with labels, templates that match workflow
*/
Expand Down
33 changes: 16 additions & 17 deletions client/modules/core/helpers/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Reaction } from "/client/api";

/*
* Methods for the reaction permissions
* helpers for roles, uses alanning:meteor-roles
* see: http://alanning.github.io/meteor-roles/classes/Roles.html
* use: {{hasPermission admin userId}}
*/

/**
* hasPermission template helper
* @summary check current user hasPermission
* @method hasPermission
* @memberof Template
* @summary check current user hasPermission, uses [alanning:meteor-roles](http://alanning.github.io/meteor-roles/classes/Roles.html)
* @example {{hasPermission admin userId}}
* @param {String|Array} "permissions"
* @param {String} checkUserId - optional Meteor.userId, default to current
* @return {Boolean}
Expand All @@ -33,29 +28,33 @@ Template.registerHelper("hasPermission", (permissions, options) => {
});

/**
* hasOwnerAccess template helper
* @summary check if user has owner access
* @method hasOwnerAccess
* @memberof Template
* @summary check if user has owner access, uses [alanning:meteor-roles](http://alanning.github.io/meteor-roles/classes/Roles.html)
* @return {Boolean} return true if owner
*/
Template.registerHelper("hasOwnerAccess", () => Reaction.hasOwnerAccess());

/**
* hasAdminAccess template helper
* @summary check if user has admin access
* @method hasAdminAccess
* @memberof Template
* @summary check if user has admin access, uses [alanning:meteor-roles](http://alanning.github.io/meteor-roles/classes/Roles.html)
* @return {Boolean} return true if admin
*/
Template.registerHelper("hasAdminAccess", () => Reaction.hasAdminAccess());

/**
* hasDashboardAccess template helper
* @summary check if user has dashboard access
* @method hasDashboardAccess
* @memberof Template
* @summary check if user has dashboard access, uses [alanning:meteor-roles](http://alanning.github.io/meteor-roles/classes/Roles.html)
* @return {Boolean} return true if user has dashboard permission
*/
Template.registerHelper("hasDashboardAccess", () => Reaction.hasDashboardAccess());

/**
* allowGuestCheckout template helper
* @summary check if guest users are allowed to checkout
* @method allowGuestCheckout
* @memberof Template
* @summary check if guest users are allowed to checkout, uses [alanning:meteor-roles](http://alanning.github.io/meteor-roles/classes/Roles.html)
* @return {Boolean} return true if shop has guest checkout enabled
*/
Template.registerHelper("allowGuestCheckout", () => Reaction.allowGuestCheckout());
65 changes: 45 additions & 20 deletions client/modules/core/helpers/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import * as Collections from "/lib/collections";
import * as Schemas from "/lib/collections/schemas";
import { toCamelCase } from "/lib/api";

/**
* @file Meteor Blaze Template helper methods - Use these helpers in Meteor Blaze templates with `{{ }}`
* Read more about Meteor Blaze helpers in the [Blaze Documentation](blazejs.org/api/templates.html#Template-registerHelper).
* @namespace Templates
*/

// Lazyload moment-timezone.months
const monthOptionsVar = new ReactiveVar([]);
async function lazyLoadMonths() {
Expand Down Expand Up @@ -47,11 +53,11 @@ Template.registerHelper("Collections", () => Collections);
Template.registerHelper("Schemas", () => Schemas);

/**
* currentUser
* @method currentUser
* @memberof Templates
* @summary overrides Meteor Package.blaze currentUser method
* @return {Boolean} returns true/null if user has registered
*/

Template.registerHelper("currentUser", () => {
if (typeof Reaction === "object") {
const shopId = Reaction.getShopId();
Expand All @@ -67,11 +73,17 @@ Template.registerHelper("currentUser", () => {
return null;
});


/**
* @method monthOptions
* @memberof Templates
* @summary Get monthOptionsVar ReactiveVar
* @param {Boolean} [showDefaultOption]
* @return {Array} returns array of months
*/
Template.registerHelper("monthOptions", (showDefaultOption = true) => {
const label = i18next.t("app.monthOptions", "Choose month");

// Call to get monthOptinosVar ReactiveVar
// Call to get monthOptionsVar ReactiveVar
lazyLoadMonths();
let monthOptions = [];

Expand All @@ -88,8 +100,10 @@ Template.registerHelper("monthOptions", (showDefaultOption = true) => {
});

/**
* yearOptions
* @method yearOptions
* @memberof Templates
* @summary formats moment.js next 9 years into array for autoform selector
* @param {Boolean} [showDefaultOption]
* @return {Array} returns array of years [value:, label:]
*/
Template.registerHelper("yearOptions", (showDefaultOption = true) => {
Expand All @@ -115,7 +129,7 @@ Template.registerHelper("yearOptions", (showDefaultOption = true) => {
});

/**
* camelToSpace
* @method camelToSpace
* @summary convert a camelcased string to spaces
* @param {String} str - camelcased string
* @return {String} returns space formatted string
Expand All @@ -126,31 +140,35 @@ Template.registerHelper("camelToSpace", (str) => {
});

/**
* toLowerCase
* @method toLowerCase
* @memberof Templates
* @summary convert a string to lower case
* @param {String} str - string
* @return {String} returns lowercased string
*/
Template.registerHelper("toLowerCase", (str) => str.toLowerCase());

/**
* toUpperCase
* @method toUpperCase
* @memberof Templates
* @summary convert a string to upper case
* @param {String} str - string
* @return {String} returns uppercased string
*/
Template.registerHelper("toUpperCase", (str) => str.toUpperCase());

/**
* capitalize
* @method capitalize
* @memberof Templates
* @summary capitalize first character of string
* @param {String} str - string
* @return {String} returns string with first letter capitalized
*/
Template.registerHelper("capitalize", (str) => str.charAt(0).toUpperCase() + str.slice(1));

/**
* toCamelCase
* @method toCamelCase
* @memberof Templates
* @summary camelCases a string
* @param {String} str - string
* @return {String|undefined} returns camelCased string
Expand All @@ -159,23 +177,22 @@ Template.registerHelper("toCamelCase", (str) => !!str && toCamelCase(str));


/**
* siteName
* @method siteName
* @memberof Templates
* @summary get the shop name
* @example <a href="{{pathFor 'index'}}"><span>{{siteName}}</span></a>
* @return {String} returns site name
*/
Template.registerHelper("siteName", () => {
const shop = Collections.Shops.findOne();
return typeof shop === "object" && shop.name ? shop.name : "";
});

/*
* General helpers for template functionality
*/

/**
* condition
* @method condition
* @summary conditional string comparison template helper
* @example {{#if condition status "eq" ../value}}
* @memberof Templates
* @param {String} v1 - first variable to compare
* @param {String} operator - eq,neq,ideq,or,lt,gt comparision operator
* @param {String} v2 - second variable to compare
Expand Down Expand Up @@ -219,17 +236,23 @@ Template.registerHelper("condition", (v1, operator, v2) => {
});

/**
* orElse
* @method orElse
* @summary if this is true, or else this
* @memberof Templates
* @example {{#if showCartIconWarning}}
<div class="badge badge-warning">!</div>
{{/if}}
<div class="badge">{{orElse cartCount 0}}</div>
* @param {String} v1 - variable one
* @param {String} v2 - variable two
* @return {String} returns v1 || v2
*/
Template.registerHelper("orElse", (v1, v2) => v1 || v2);

/**
* key_value
* @method key_value
* @summary template helper pushing object key/value into array
* @memberof Templates
* @param {Object} context - object to parse into key / value
* @return {Array} returns array[key:,value:]
*/
Expand All @@ -243,9 +266,10 @@ Template.registerHelper("key_value", (context) => {
});

/**
* nl2br
* @method nl2br
* @summary template helper nl2br - Converts new line (\n\r) to <br>
* from http://phpjs.org/functions/nl2br:480
* @memberof Templates
* @param {String} text - text
* @returns {String} returns formatted Spacebars.SafeString
*/
Expand All @@ -255,8 +279,9 @@ Template.registerHelper("nl2br", (text) => {
});

/**
* pluralize
* @method pluralize
* @summary general helper for plurization of strings
* @memberof Templates
* @example {{plurize "1 thing"}}
* @param {String} nCount - number, ie "1 "
* @param {String} pString - plural string ie " thing"
Expand Down
6 changes: 3 additions & 3 deletions client/modules/i18n/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { formatPriceString } from "./currency";
* @name i18n
* @see http://i18next.com/
* @summary Pass the translation key as the first argument and the default message as the second argument
* @memberof i18n
* @memberof Templates
* @method
* @param {String} i18nKey - i18nKey
* @param {String} i18nMessage - message text
Expand All @@ -33,7 +33,7 @@ Template.registerHelper("i18n", (i18nKey, i18nMessage) => {

/**
* @name currencySymbol
* @memberof i18n
* @memberof Templates
* @method
* @summary Eeturn shop /locale specific currency format (ie: $)
* @returns {String} return current locale currency symbol
Expand All @@ -55,7 +55,7 @@ Template.registerHelper("currencySymbol", () => {

/**
* @name formatPrice
* @memberof i18n
* @memberof Templates
* @method
* @summary Return shop /locale specific formatted price. Also accepts a range formatted with " - "
* @example {{formatPrice displayPrice}}
Expand Down
Loading