GSBCfamily / bvcms

The open source church management system
http://touchpointsoftware.com
GNU General Public License v2.0
1 stars 1 forks source link

New Handlebars Helpers #56

Closed hkouns closed 8 years ago

hkouns commented 8 years ago

Math Every nth

hkouns commented 8 years ago

JS version of Math: Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) { lvalue = parseFloat(lvalue); rvalue = parseFloat(rvalue);

return {
    "+": lvalue + rvalue,
    "-": lvalue - rvalue,
    "*": lvalue * rvalue,
    "/": lvalue / rvalue,
    "%": lvalue % rvalue
}[operator];

});

hkouns commented 8 years ago

Every Nth: Handlebars.registerHelper('everyNth', function(context, every, options) { var fn = options.fn, inverse = options.inverse; var ret = ""; if(context && context.length > 0) { for(var i=0, j=context.length; i<j; i++) { var modZero = i % every === 0; ret = ret + fn(_.extend({}, context[i], { isModZero: modZero, isModZeroNotFirst: modZero && i > 0, isLast: i === context.length - 1 })); } } else { ret = inverse(this); } return ret; });

hkouns commented 8 years ago

Currency ... take Type of Currency... and number of digits. e.g.: convert: 34.3478 to: $34.35 {{currency "$" 2 val}}

UPDATE: use FmtNum instead

hkouns commented 8 years ago

FmtNum

Standard formats, with their related outputs,

String s = String.Format("(C) Currency: . . . . . . . . {0:C}\n" + "(D) Decimal:. . . . . . . . . {0:D}\n" + "(E) Scientific: . . . . . . . {1:E}\n" + "(F) Fixed point:. . . . . . . {1:F}\n" + "(G) General:. . . . . . . . . {0:G}\n" + " (default):. . . . . . . . {0} (default = 'G')\n" + "(N) Number: . . . . . . . . . {0:N}\n" + "(P) Percent:. . . . . . . . . {1:P}\n" + "(R) Round-trip: . . . . . . . {1:R}\n" + "(X) Hexadecimal:. . . . . . . {0:X}\n",

hkouns commented 8 years ago

{{FmtAddress PID "type" lines}}

type = F or P Lines = 1, 2, 3

hkouns commented 8 years ago

Date Time:

{{Now}}

{{FmtDT date "fmt"}} (NEED TO LOOK AT EXISTING FmtDate Helper...

date being passed to helper fmt string complying with https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx#

returns a string thisDate1 = new DateTime(2011, 6, 10); Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy")

{{DateOffset date value "type"}}

type is d for day, m for month, y for year

hkouns commented 8 years ago

FmtPhone(string s, string prefix)

hkouns commented 8 years ago

InOrg InSubGroup

hkouns commented 8 years ago

int WeekNumber(object dt) SundayForDate(object dt) SundayForWeek(int year, int week) MostRecentAttendedSunday(int progid)

hkouns commented 8 years ago

http://www.levihackwith.com/creating-new-conditionals-in-handlebars/

hkouns commented 8 years ago

Submitted PR https://github.com/bvcms/bvcms/pull/81