Giter Site home page Giter Site logo

Template String Support? about nbb HOT 3 CLOSED

jaidetree avatar jaidetree commented on May 24, 2024
Template String Support?

from nbb.

Comments (3)

borkdude avatar borkdude commented on May 24, 2024

I have read the post, but I don't understand some parts.

(js-template-str "git add " some-var)

Isn't js-template-str just the str function here?

What about using goog.string.format which is available in nbb?

from nbb.

jaidetree avatar jaidetree commented on May 24, 2024

goog.string.format works for problems where I'm just trying to format a string. But in the case of libraries like zx, goog string format would not work. Same with using the sql function from packages like slonik.

In js land:

import $ from 'zx'

$`ls -a ${path.join(process.cwd(), 'nbb.edn')}` 

Will call the $ function like:

$(['ls -a '], '/Users/j/projects/cljs-piano/nbb.edn')

Where each str is included in that first array of strings, then each interpolation value is provided as a function arg.

https://github.com/google/zx/blob/4999435182fe1f34f6b2ef2471184d9878456b5e/src/core.ts#L93

So that macro could be used like this:

(require '['zx' :refer [$]]
         '['path' :as path])

(apply $ (js-template-str "ls -a" (.join path (js/process.cwd) "nbb.edn")))

Took a stab at a first draft:

(defmacro js-template-str
  [& args]
  (let [[strs# args#] (partition-by string? args)
        result# (cons (clj->js (conj (vec strs#) "")) args#)]
    `(list ~@result#)))

(comment
  (macroexpand-1
    '(js-template-str "iconutil -c icns " (.join path (js/process.cwd) "nbb.edn"))))

;; => (#js ["iconutil -c icns "] (.join path (js/process.cwd) "nbb.edn"))

from nbb.

borkdude avatar borkdude commented on May 24, 2024

I've had a discussion about template string support here:

squint-cljs/squint#40

There was also a string interpolation << macro in incubator:

https://clojure.github.io/clojure-contrib/strint-api.html

The output of your macro seems pretty specific to what zx expects or are there more general use cases?

from nbb.

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.