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

locals hash not supported in current implementation of Stache::Mustache::Handler #56

Open
lulu-2021 opened this issue Jul 27, 2015 · 1 comment

Comments

@lulu-2021
Copy link

Currently the Stache::Mustache::Handler compile method only passes controller instance variables to the view context - however in many circumstances you want to have more control over the render method - ie. not use the standard rails automagic way..

I would like to see this added to the compile method so that the locals hash is supported:

      local_assigns.each do |key, val|
        variable_name = '@'.concat(key.to_s).to_s.to_sym
        variables << variable_name
        mustache.instance_variable_set(variable_name, val)
      end

that would enable me to do something like this in the controller#action

render 'people/new', locals: { person: person }

and therefore not have to create an instance variable as person becomes an attr_reader etc..

I am happy to provide you with a pull request if you like - Thanks

Steve

@lulu-2021
Copy link
Author

Just as an aside - Poirot also supports this - i.e. it is pretty standard..

https://github.com/olivernn/poirot/blob/master/lib/poirot/view.rb

if Rails.version >= "3.1"
# get the locals from the view context, is there a better way?
locals = view_context.send(:view_renderer).send(:_partial_renderer).instance_variable_get("@Locals") || {}

    locals.each do |name, val|
      instance_variable_set("@#{name}", val)
      self[name] = val
    end
  end

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

1 participant