-
Notifications
You must be signed in to change notification settings - Fork 21
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
alter index html response #33
Comments
was just about to open an issue for this - this would be amazing |
Perhaps the developer simply defines a hash in the app controller to be converted to meta tags def feb_meta(app_name)
if app_name == "blog"
{ yapp_user: current_user }
end
end |
Just brainstorming with Ryan about this, one way we could design this would be to have user-defined transforms. class MyTransformer < FrontEndBuilds::Transformer
def transforms(scope, html)
append_to_head(html, "<meta value=#{scope.current_user.to_json}")
end
end
FrontEndBuilds.register_transforms(MyTransformer)
# every request, instantiate the transformers, and call #transform on the scope and html
This way, FEB could provide a CSRF transformer that works out the box (you could disable it), and we could apply that transform in addition to any user-generated ones. |
Hmm, I like the flexibility of that idea, but I wonder if it isn't more complex than is needed. @hhff's suggestion does everything I need and strikes me as a lot simpler and I would guess covers the vast majority of people's requirements. Especially given that the existing BestsController already has logic for injecting meta tags, so adding the custom hash to that would really be trivial. |
Yep, great point. I think this covers all known use cases for now, and much simpler! |
Cool -- I'll try to get this sorted and submit a PR this week sometime. |
i tend to think it would be worth exposing a low level hook that the index.html string gets passed through for the developer to override and do whatever manipulation they want too. maybe that's where we call the |
I wonder if it isn't worth making that a separate feature, though? Just because the mechanics for meta tags is already there, and it's a very simple and common requirement. |
yeah, i mean it's just 3 lines of code to add the low level hook also |
I guess I could go either way -- I'm relatively new to this gem, so I'll defer to you guys. |
Why don't we start with a |
How are you guys envisioning that a user/developer overrides https://github.com/ngottlieb/front_end_builds/tree/feb_meta Thoughts? It could be pretty neat to go further with this and expose setting custom meta variables to the UI per app or per build. |
I think what you have solves your need, and we're happy to merge it in. We can revisit it later as more needs arise - I guess we don't have a ton of time just this moment to look further into this. How does that sound? |
Works for me, I'll submit a PR. I'd be happy to do more work on it with a bit of direction -- whether that's towards exposing customizable meta tags to the UI or building the Transformers idea out -- I think both are useful ideas. |
Just jotting an idea down, Luke mentioned in his talk they sometimes alter the HTML response after it was fetched from Redis. For example, they inject
current_user
into a meta tag, so the Ember app doesn't have to make an XHR request. You could also addWe may want to eventually have an API for this type of thing.
The text was updated successfully, but these errors were encountered: