GithubHelp home page GithubHelp logo

Comments (8)

joeldrapper avatar joeldrapper commented on July 19, 2024

A SyntaxTree mutation visitor would probably be the easiest solution for this.

from phlexing.

jaredcwhite avatar jaredcwhite commented on July 19, 2024

@marcoroth @joeldrapper This dovetails into a separate project I've been slowly working on to transform HTML that has certain configurable directives…for example, in a Vue-style configuration, <div v-text="someValue"></div> would render out as <div v-text="someValue">Expanded with the value text</div>.

I had been using Nokogiri for this, but now I'm musing on the idea of using Phlexing to compile the HTML to Phlex and then using something like what you're describing to handle the directives so when the Phlex template runs it can expand out that content.

Any thoughts?

from phlexing.

jaredcwhite avatar jaredcwhite commented on July 19, 2024

(Could be tricky with things like lists, where a single <template> tag with directives in its content would need to be duplicated and expanded out for n items in an array.)

from phlexing.

marcoroth avatar marcoroth commented on July 19, 2024

@jaredcwhite maybe I'm not understanding 100% what you are trying to do, but it seems kinda overkill to me to use phlexing (or phlex for that matter) as an intermediate format for those kind of transformations. Unless you already have those transformations written and implemented based on a Ruby AST.

from phlexing.

joeldrapper avatar joeldrapper commented on July 19, 2024

I agree. I think you’ll find it's easier to use Nokogiri than SyntaxTree for this kind of thing @jaredcwhite. If PhlexML is the final target, you can always do the transformations in Nokogiri first, then run it through Phlexing.

from phlexing.

jaredcwhite avatar jaredcwhite commented on July 19, 2024

If PhlexML is the final target, you can always do the transformations in Nokogiri first, then run it through Phlexing.

Interesting…I could essentially inject ERB into the markup via Nokogiri prior to the Phlexing stage. I'll give that a try!

from phlexing.

jaredcwhite avatar jaredcwhite commented on July 19, 2024

@marcoroth @joeldrapper OK, this looks like it can work! I just need to use special delimiters (eg.,{{{{%= value %}}}}) and gsub back to angle brackets (so Nokogiri doesn't turn them into entities), class_eval a template method with the Phlexing conversion at "compile time", and then renders at run time simply execute the straightforward Phlex template.

This is rad!!

from phlexing.

marcoroth avatar marcoroth commented on July 19, 2024

@jaredcwhite depening what you are doing you might also find Phlexing::ERBTransformer or Phlexing::Parser helpful so you don't need to replace the output tags with weird markers

from phlexing.

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.