Re: [Dev] [Caramel] Adding more custom Handlebars helpers to Caramel

2015-08-14 Thread Rasika Perera
Hi All,

Please find my comments inline.

*-1 ifCond and selectIf*
>  I agree with your view. Since Mustache and Handlebars follow the
> logic-less template approach, Caramel should also follow it.
> However there are some circumstances where you have to put some logic in
> the template. For example, in [1] we have used selectIf helper to determine
> the proper CSS class for some action buttons. Before introducing selectIf
> helper, these CSS classes were hard-coded in this [2] .js file (which is in
> the server-side). Hard-coding CSS classes is acceptable in HTML templates
> and client-side JavaScripts, but not for other server-side .js or .jsg
> files. That's why we introduced the selectIf helper.


+1 for the effort you have put to make it nice and well documented. If the
vision is to have "*logic-less*" templating we may need to follow it. "If
you prevent logic in templates by design (like handlebars and mustache
does), you will be obliged to put the logic elsewhere, so your templates
will end up uncluttered" [3].

For the specific use-case you have mentioned in [1]; I believe hard-coding
on view model[2] is a correct approach. Then you have control over all
templates that presenting the specific view model. Let me further explain
this. Suppose you need to change css class appearing for "Submit for
Review" phase in all templates including [1]. Since you
have implemented this logic at the template level you need to change all
the templates.

*+1 for for*
> The {{index}} expression has been introduced to the {{#each}} block helper
> in Handlebars 3.0.3 version. However startIndex, endIndex and jump optional
> parameters of the proposed for helper can be helpful. For example,
> displaying only certain number of items based on a user input (see below
> image). So, adding for helper will be helpful.


+1. This is awesome. Until you upgrade into handlebars v3.0.3 this is
really beneficial. Even in {{#each}}, I don't think you have features such
as startIndex, endIndex and jump optional parameters.

[1]
https://github.com/sajithar/carbon-appmgt/blob/047b7831886f50f6e656ca9d56739d08003c7240/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/partials/list-assets-row.hbs#L50
[2]
https://github.com/sajithar/carbon-appmgt/blob/2d362df789eadc1b67e0edf41209380aa82bf7c1/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/renderers/controllers/assets_router.js#L39
[3] http://stackoverflow.com/a/4946409/1560536


On Thu, Aug 13, 2015 at 11:04 AM, Sajith Ariyarathna 
wrote:

> Hi Manu,
>
> Please find my comments inline.
>
> -1 *ifCond* and *selectIf*
>
>  I agree with your view. Since Mustache and Handlebars follow the *logic-less
> template* approach, Caramel should also follow it.
>
> However there are some circumstances where you have to put some logic in
> the template. For example, in [1] we have used selectIf helper to
> determine the proper CSS class for some action buttons. Before introducing
> selectIf helper, these CSS classes were hard-coded in this [2] .js file
> (which is in the server-side). Hard-coding CSS classes is acceptable in
> HTML templates and client-side JavaScripts, but not for other server-side
> .js or .jsg files. That's why we introduced the selectIf helper.
>
> +1 for *for*
>>
> The {{index}} expression has been introduced to the {{#each}} block
> helper in Handlebars 3.0.3 version. However startIndex, endIndex and jump 
> optional
> parameters of the proposed for helper can be helpful. For example,
> displaying only certain number of items based on a user input (see below
> image). So, adding for helper will be helpful.
> [image: Inline image 1]
>
>
> [1]
> https://github.com/sajithar/carbon-appmgt/blob/047b7831886f50f6e656ca9d56739d08003c7240/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/partials/list-assets-row.hbs#L50
> [2]
> https://github.com/sajithar/carbon-appmgt/blob/2d362df789eadc1b67e0edf41209380aa82bf7c1/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/renderers/controllers/assets_router.js#L39
>
> Thanks.
>
>
> On Wed, Aug 12, 2015 at 6:40 PM, Manuranga Perera  wrote:
>
>> -1 *ifCond* and *selectIf*
>> the reason we have separate *logic-less* temperating is to remove logic
>> out of ui representation. this helper defeats whole purpose of having
>> handlebars.
>> different people have different opinions on this, see the discussion on
>> https://github.com/wycats/handlebars.js/issues/616 . I personally don't
>> like putting it in templates.
>>
>> It is better to do the necessary logic in the js/jag file and use the
>> built in Helpers. is there any reason to not to do it this way?
>>
>> +1 for *for*
>> but think it's there in new version anyway. is this one any different? if
>> not we should just update to new Handlebars instead.
>>
>> On Wed, Aug 12, 2015 at 3:28 PM, S

Re: [Dev] [Caramel] Adding more custom Handlebars helpers to Caramel

2015-08-12 Thread Sajith Ariyarathna
[attaching image]

[image: Inline image 1]


On Thu, Aug 13, 2015 at 11:04 AM, Sajith Ariyarathna 
wrote:

> Hi Manu,
>
> Please find my comments inline.
>
> -1 *ifCond* and *selectIf*
>
>  I agree with your view. Since Mustache and Handlebars follow the *logic-less
> template* approach, Caramel should also follow it.
>
> However there are some circumstances where you have to put some logic in
> the template. For example, in [1] we have used selectIf helper to
> determine the proper CSS class for some action buttons. Before introducing
> selectIf helper, these CSS classes were hard-coded in this [2] .js file
> (which is in the server-side). Hard-coding CSS classes is acceptable in
> HTML templates and client-side JavaScripts, but not for other server-side
> .js or .jsg files. That's why we introduced the selectIf helper.
>
> +1 for *for*
>>
> The {{index}} expression has been introduced to the {{#each}} block
> helper in Handlebars 3.0.3 version. However startIndex, endIndex and jump 
> optional
> parameters of the proposed for helper can be helpful. For example,
> displaying only certain number of items based on a user input (see below
> image). So, adding for helper will be helpful.
> [image: Inline image 1]
>
>
> [1]
> https://github.com/sajithar/carbon-appmgt/blob/047b7831886f50f6e656ca9d56739d08003c7240/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/partials/list-assets-row.hbs#L50
> [2]
> https://github.com/sajithar/carbon-appmgt/blob/2d362df789eadc1b67e0edf41209380aa82bf7c1/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/renderers/controllers/assets_router.js#L39
>
> Thanks.
>
>
> On Wed, Aug 12, 2015 at 6:40 PM, Manuranga Perera  wrote:
>
>> -1 *ifCond* and *selectIf*
>> the reason we have separate *logic-less* temperating is to remove logic
>> out of ui representation. this helper defeats whole purpose of having
>> handlebars.
>> different people have different opinions on this, see the discussion on
>> https://github.com/wycats/handlebars.js/issues/616 . I personally don't
>> like putting it in templates.
>>
>> It is better to do the necessary logic in the js/jag file and use the
>> built in Helpers. is there any reason to not to do it this way?
>>
>> +1 for *for*
>> but think it's there in new version anyway. is this one any different? if
>> not we should just update to new Handlebars instead.
>>
>> On Wed, Aug 12, 2015 at 3:28 PM, Sajith Ariyarathna 
>> wrote:
>>
>>> Hi All,
>>>
>>> For AppM we have implemented few custom Handlebars helpers [1]. Since
>>> they are very helpful, we like to suggest them to add to the Caramel
>>> framework. We suggest following 03 helpers.
>>>
>>> *ifCond*
>>>
>>> Conditional if block which can be used with a single logical expression.
>>> ifCond helper supports ==, !=, ===, !==, <, <=, >, >=, &&, || and typeof 
>>> operators.
>>> (see [2])
>>>
>>> *for*
>>>
>>> Iterates over an array and iteration manner can be customized. Also,
>>> index of the current iteration can be access as {{index}}. (see [3])
>>>
>>> *selectIf*
>>>
>>> For the given value, outputs the result based on the specified
>>> 'value-result' map. Very similar to the switch-case clause. (see [4])
>>>
>>>
>>> Thanks.
>>>
>>> [1]
>>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js
>>> [2]
>>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L92
>>> [3]
>>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L143
>>> [4]
>>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L250
>>>
>>> --
>>> Sajith Ariyarathna
>>> Software Engineer; WSO2, Inc.;  http://wso2.com/
>>> mobile: +94 77 6602284, +94 71 3951048
>>>
>>
>>
>>
>> --
>> With regards,
>> *Manu*ranga Perera.
>>
>> phone : 071 7 70 20 50
>> mail : m...@wso2.com
>>
>
>
>
> --
> Sajith Ariyarathna
> Software Engineer; WSO2, Inc.;  http://wso2.com/
> mobile: +94 77 6602284, +94 71 3951048
>



-- 
Sajith Ariyarathna
Software Engineer; WSO2, Inc.;  http://wso2.com/
mobile: +94 77 6602284, +94 71 3951048
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [Caramel] Adding more custom Handlebars helpers to Caramel

2015-08-12 Thread Sajith Ariyarathna
Hi Manu,

Please find my comments inline.

-1 *ifCond* and *selectIf*

 I agree with your view. Since Mustache and Handlebars follow the *logic-less
template* approach, Caramel should also follow it.

However there are some circumstances where you have to put some logic in
the template. For example, in [1] we have used selectIf helper to determine
the proper CSS class for some action buttons. Before introducing
selectIf helper,
these CSS classes were hard-coded in this [2] .js file (which is in the
server-side). Hard-coding CSS classes is acceptable in HTML templates and
client-side JavaScripts, but not for other server-side .js or .jsg files.
That's why we introduced the selectIf helper.

+1 for *for*
>
The {{index}} expression has been introduced to the {{#each}} block helper
in Handlebars 3.0.3 version. However startIndex, endIndex and jump optional
parameters of the proposed for helper can be helpful. For example,
displaying only certain number of items based on a user input (see below
image). So, adding for helper will be helpful.
[image: Inline image 1]


[1]
https://github.com/sajithar/carbon-appmgt/blob/047b7831886f50f6e656ca9d56739d08003c7240/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/partials/list-assets-row.hbs#L50
[2]
https://github.com/sajithar/carbon-appmgt/blob/2d362df789eadc1b67e0edf41209380aa82bf7c1/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/renderers/controllers/assets_router.js#L39

Thanks.


On Wed, Aug 12, 2015 at 6:40 PM, Manuranga Perera  wrote:

> -1 *ifCond* and *selectIf*
> the reason we have separate *logic-less* temperating is to remove logic
> out of ui representation. this helper defeats whole purpose of having
> handlebars.
> different people have different opinions on this, see the discussion on
> https://github.com/wycats/handlebars.js/issues/616 . I personally don't
> like putting it in templates.
>
> It is better to do the necessary logic in the js/jag file and use the
> built in Helpers. is there any reason to not to do it this way?
>
> +1 for *for*
> but think it's there in new version anyway. is this one any different? if
> not we should just update to new Handlebars instead.
>
> On Wed, Aug 12, 2015 at 3:28 PM, Sajith Ariyarathna 
> wrote:
>
>> Hi All,
>>
>> For AppM we have implemented few custom Handlebars helpers [1]. Since
>> they are very helpful, we like to suggest them to add to the Caramel
>> framework. We suggest following 03 helpers.
>>
>> *ifCond*
>>
>> Conditional if block which can be used with a single logical expression.
>> ifCond helper supports ==, !=, ===, !==, <, <=, >, >=, &&, || and typeof 
>> operators.
>> (see [2])
>>
>> *for*
>>
>> Iterates over an array and iteration manner can be customized. Also,
>> index of the current iteration can be access as {{index}}. (see [3])
>>
>> *selectIf*
>>
>> For the given value, outputs the result based on the specified
>> 'value-result' map. Very similar to the switch-case clause. (see [4])
>>
>>
>> Thanks.
>>
>> [1]
>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js
>> [2]
>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L92
>> [3]
>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L143
>> [4]
>> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L250
>>
>> --
>> Sajith Ariyarathna
>> Software Engineer; WSO2, Inc.;  http://wso2.com/
>> mobile: +94 77 6602284, +94 71 3951048
>>
>
>
>
> --
> With regards,
> *Manu*ranga Perera.
>
> phone : 071 7 70 20 50
> mail : m...@wso2.com
>



-- 
Sajith Ariyarathna
Software Engineer; WSO2, Inc.;  http://wso2.com/
mobile: +94 77 6602284, +94 71 3951048
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [Caramel] Adding more custom Handlebars helpers to Caramel

2015-08-12 Thread Manuranga Perera
-1 *ifCond* and *selectIf*
the reason we have separate *logic-less* temperating is to remove logic out
of ui representation. this helper defeats whole purpose of having
handlebars.
different people have different opinions on this, see the discussion on
https://github.com/wycats/handlebars.js/issues/616 . I personally don't
like putting it in templates.

It is better to do the necessary logic in the js/jag file and use the built
in Helpers. is there any reason to not to do it this way?

+1 for *for*
but think it's there in new version anyway. is this one any different? if
not we should just update to new Handlebars instead.

On Wed, Aug 12, 2015 at 3:28 PM, Sajith Ariyarathna 
wrote:

> Hi All,
>
> For AppM we have implemented few custom Handlebars helpers [1]. Since they
> are very helpful, we like to suggest them to add to the Caramel framework.
> We suggest following 03 helpers.
>
> *ifCond*
>
> Conditional if block which can be used with a single logical expression.
> ifCond helper supports ==, !=, ===, !==, <, <=, >, >=, &&, || and typeof 
> operators.
> (see [2])
>
> *for*
>
> Iterates over an array and iteration manner can be customized. Also, index
> of the current iteration can be access as {{index}}. (see [3])
>
> *selectIf*
>
> For the given value, outputs the result based on the specified
> 'value-result' map. Very similar to the switch-case clause. (see [4])
>
>
> Thanks.
>
> [1]
> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js
> [2]
> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L92
> [3]
> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L143
> [4]
> https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L250
>
> --
> Sajith Ariyarathna
> Software Engineer; WSO2, Inc.;  http://wso2.com/
> mobile: +94 77 6602284, +94 71 3951048
>



-- 
With regards,
*Manu*ranga Perera.

phone : 071 7 70 20 50
mail : m...@wso2.com
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] [Caramel] Adding more custom Handlebars helpers to Caramel

2015-08-12 Thread Sajith Ariyarathna
Hi All,

For AppM we have implemented few custom Handlebars helpers [1]. Since they
are very helpful, we like to suggest them to add to the Caramel framework.
We suggest following 03 helpers.

*ifCond*

Conditional if block which can be used with a single logical expression.
ifCond helper supports ==, !=, ===, !==, <, <=, >, >=, &&, || and
typeof operators.
(see [2])

*for*

Iterates over an array and iteration manner can be customized. Also, index
of the current iteration can be access as {{index}}. (see [3])

*selectIf*

For the given value, outputs the result based on the specified
'value-result' map. Very similar to the switch-case clause. (see [4])


Thanks.

[1]
https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js
[2]
https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L92
[3]
https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L143
[4]
https://github.com/wso2/carbon-appmgt/blob/master/features/appmgt/org.wso2.carbon.appmgt.publisher.feature/src/main/resources/publisher/themes/mobileapp/js/lib/handlebars/custom.handlebars.helpers.js#L250

-- 
Sajith Ariyarathna
Software Engineer; WSO2, Inc.;  http://wso2.com/
mobile: +94 77 6602284, +94 71 3951048
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev