You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I am building a template, but it seems complicated to do almost nothing, for example :
{{!-- If contains the tag "Ignore", then the annotation @Ignore is set on this class --}}
{{#if has_tags?}}{{#each rendered_children.tags}}{{#case this}}{{#when_includes "Ignore"}}
@Ignore
{{/when_includes}}{{/case}}{{/each}}{{/if}}
Describe the solution you'd like
I would like to have a "contains" function, and more generally, I would like to register custom function in order to have a cleaner code.
Describe alternatives you've considered
Learn handlebars ? ^^
Also, I don't understand why we can't write :
{{#each rendered_children.tags as |tag|}}
Bonus: could you give us some documentation or links to learn and use ruby handlebars ?
Thank
The text was updated successfully, but these errors were encountered:
For the custom handlebars functions, that should work by doing a little monkeypatching in your local code. The function that is utilized to register helpers is the Hiptest::HandlebarsHelper#register_custom_helpers:
def register_custom_helpers
self.class.instance_methods.each do |method_name|
if method_name.to_s.start_with? 'hh_'
@handlebars.register_helper(method_name.to_s.gsub(/hh_/, '')) do |*args|
send(method_name, *args)
end
elsif method_name.to_s.start_with? 'as_hh_'
@handlebars.register_as_helper(method_name.to_s.gsub(/as_hh_/, '')) do |*args|
send(method_name, *args)
end
end
end
end
What it does is look for all instance methods within Hiptest::HandlebarsHelper that begin with hh_ or as_hh and, for each one, it drops the hh_ or as_hh of the method name and registers the helper with any given arguments it may have.
So, in your code you could simply create a monkeypatch like so, that gets called prior to the HiptestPublisher gem:
module Hiptest
class HandlebarsHelper
def hh_if_contains(context, list, expected, block, else_block)
if list&.include?(expected)
block.fn(context)
elsif else_block
else_block.fn(context)
else
""
end
end
end
end
(the above is some off the top of my head code, so you might have to tweak it a bit)
For the question regarding {{#each ...}}, there should be no reason that wouldn't work. That is a valid statement and rendered_children.tags acts as an array (as can be seen in the usage of join like in {{{ join rendered_children.tags ' '}}}). Are you getting some particular error?
Is your feature request related to a problem? Please describe.
I am building a template, but it seems complicated to do almost nothing, for example :
Describe the solution you'd like
I would like to have a "contains" function, and more generally, I would like to register custom function in order to have a cleaner code.
Describe alternatives you've considered
Learn handlebars ? ^^
Also, I don't understand why we can't write :
Bonus: could you give us some documentation or links to learn and use ruby handlebars ?
Thank
The text was updated successfully, but these errors were encountered: