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

Mention generic options config in readme #179

Open
mslourens opened this issue Apr 8, 2021 · 7 comments
Open

Mention generic options config in readme #179

mslourens opened this issue Apr 8, 2021 · 7 comments

Comments

@mslourens
Copy link

mslourens commented Apr 8, 2021

I was looking for a way to set runtime options for handlebars, and came across the changelog for version 0.6.5, where this was mentioned, but in the readme it was not mentioned at all. It would be a good idea to mention it somewhere, so this option can be used. This is the way to set runtime options like allowProtoPropertiesByDefault, right?

@Cortlandd
Copy link

Cortlandd commented Feb 3, 2022

@mslourens Bump. Did doing so work for you?

@Cortlandd
Copy link

I'm thinking is the following what we need?

require 'handlebars_assets'

HandlebarsAssets::Config.options = {
  allowProtoMethodsByDefault: true,
  allowedProtoMethods: true    
}

@mslourens
Copy link
Author

yes, that's what I meant.

@Cortlandd
Copy link

I added that to config/initializers/handlebars.js but no luck. Went with

HandlebarsTemplates['TEMPLATE']({file: { name: file.name }})

but previously had

HandlebarsTemplates['TEMPLATE']({file: file})

@adeherdt-r7
Copy link

Is there an update regarding this?
I am using the latest version of this gem, created an initializer like this:

# Initializer for the Handlebars Assets gem.
#
# Allows us to pass down configuration options to HandlebarsJS when compiling assets.
# This is required for the versions >= 4.6.0 as they by default block certain access
# to methods and properties
# see https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access
require 'handlebars_assets'

# Since HandleBarsJS 4.6.0 these values default to false and block access to the methods
# and properties of prototype objects by default. To retain compatibility we will enable
# this for now so we can properly upgrade the gem.
::HandlebarsAssets::Config.options = {
  allowProtoMethodsByDefault: true,
  allowProtoPropertiesByDefault: true,

  # In order to grant access to specific methods and properties, they need to be
  # defined here.
  allowedProtoMethods: {},
  allowedProtoProperties: {
    'bg': true,
    'buttons': true
  }
}

But this doesn't seem to be passed down correctly towards the underlying handlebars internally.
Causing the frontend to break when we upgrade this gem.

image

Do I need to use the master branch of this gem?

@AlexRiedler
Copy link
Collaborator

Those are runtime of the template parameters; so you need to call it on your namespace'd object:

window.HandlebarsTemplates["trim_test"](
  { input: { trim: "foobar" } },
  { allowedProtoMethods: { 'trim': true } }
) 

so with the template "trim_test" of {{input.trim}} and this would output "foobar"

I am about to push a new release that might help a bit, I am trying to make the invalidation of files work correctly first though 😓

@adeherdt-r7
Copy link

Thanks, I appreciate the input on this.
We are using an old version of Backbone.js, so I am not sure whether this can be done even in our setup, but I'll take a look around to see if we can somehow set this somewhere...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants