Giter VIP home page Giter VIP logo

Comments (14)

hhff avatar hhff commented on July 29, 2024

was just about to open an issue for this - this would be amazing

from front_end_builds.

hhff avatar hhff commented on July 29, 2024

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.

samselikoff avatar samselikoff commented on July 29, 2024

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.

ngottlieb avatar ngottlieb commented on July 29, 2024

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.

samselikoff avatar samselikoff commented on July 29, 2024

Yep, great point. I think this covers all known use cases for now, and much simpler!

from front_end_builds.

ngottlieb avatar ngottlieb commented on July 29, 2024

Cool -- I'll try to get this sorted and submit a PR this week sometime.

from front_end_builds.

hhff avatar hhff commented on July 29, 2024

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.

ngottlieb avatar ngottlieb commented on July 29, 2024

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.

hhff avatar hhff commented on July 29, 2024

yeah, i mean it's just 3 lines of code to add the low level hook also

from front_end_builds.

ngottlieb avatar ngottlieb commented on July 29, 2024

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.

samselikoff avatar samselikoff commented on July 29, 2024

Why don't we start with a feb_meta method that returns a hash

from front_end_builds.

ngottlieb avatar ngottlieb commented on July 29, 2024

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.

samselikoff avatar samselikoff commented on July 29, 2024

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.

ngottlieb avatar ngottlieb commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.