Comments (14)
was just about to open an issue for this - this would be amazing
from front_end_builds.
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
from front_end_builds.
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
add_to_head
could be a helper method provided by FEB, which adds the string to the end of the <head>
tag in the index html (which was fetched from the db). You could similarly define prepend_to_head
, append_to_body
and prepend_to_body
methods.
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.
from front_end_builds.
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.
from front_end_builds.
Yep, great point. I think this covers all known use cases for now, and much simpler!
from front_end_builds.
Cool -- I'll try to get this sorted and submit a PR this week sometime.
from front_end_builds.
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 setup_metatags
hook?
from front_end_builds.
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.
from front_end_builds.
yeah, i mean it's just 3 lines of code to add the low level hook also
from front_end_builds.
I guess I could go either way -- I'm relatively new to this gem, so I'll defer to you guys.
from front_end_builds.
Why don't we start with a feb_meta
method that returns a hash
from front_end_builds.
How are you guys envisioning that a user/developer overrides feb_meta
? I'd love to do something like Devise does so you could call super and incorporate the default meta tags + your own, but the way Devise makes that work involves a lot of overhead that I'm sure we don't want. So I just tried implementing a solution to that using Rails' decorator motif and it doesn't seem great. It doesn't end up saving the developer much time over just decorating the BestsController
method and overriding meta_tags
.
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.
from front_end_builds.
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?
from front_end_builds.
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.
from front_end_builds.
Related Issues (20)
- PUT builds HOT 1
- public assets not getting merged HOT 8
- Store configuration on server HOT 3
- Use build_id for links to builds
- Can't activate / deactive builds on Rails 4.2 HOT 3
- NameError: uninitialized constant FrontEndBuilds HOT 3
- Notify user if frontend isn't mounted
- tags
- Reevaluate open-uri
- Add basic http auth for admin HOT 2
- ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() SSL error: block type is not 01 HOT 1
- Named path helper for each frontend
- View helper to render frontend
- How to allow cross domain iframe embedding? HOT 1
- resolve warnings generated by rails_erd
- allow containing application to add `before_action` to front ends HOT 4
- Production builds should only contain production-ready builds HOT 3
- Respond to new build with new build id
- Update for Rails 5 HOT 4
- Lack of Rails anti-CSRF defaults when Controller is inherited from ActionController::Base
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from front_end_builds.