question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

idea: template string interpolation

See original GitHub issue

Curious if interpolation for template strings is something of interest? For example:

var red = '#f00'
var cssString = '.upper { text-transform: uppercase }'

var prefix = css`
  :host {
    background: ${red}
  }

  ${cssString}
`

In Node, doing the interpolation itself isn’t tooo bad if we parse sheetify args and pass into a thing like:

// v simplified for example sake!
function sheetify () {
  var args = Array.prototype.slice.apply(arguments)
  var css = interpolate(args[0], args.slice(1))
  // ...etc
}

function interpolate (strs, vals) {
  return strs.map(function (str, i) {
    return str + (vals[i] || '')
  }).join('')
}

But! It seems like the complication is the browserify transform. Ideally the transform would actually execute the js so the insert-css() call has no additional overhead. But perhaps a transform like yo-yoify where calls to sheetify w/in the source are converted into plain functions could work too?

I took a look at implementing this today, but I’m quite unfamiliar with writing browserify transforms, and as I was banging head against wall figured I’d stop and check to see if this even falls within the sheetify radar 📡🖖

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yoshuawuytscommented, Sep 19, 2017

Woot! Yeah, think this good to close (:

On Wed, Sep 20, 2017 at 12:18 AM Jon Gacnik notifications@github.com wrote:

Hey all @ahdinosaur https://github.com/ahdinosaur @yoshuawuyts https://github.com/yoshuawuyts ! Jumping back in here since #134 https://github.com/stackcss/sheetify/pull/134 pretty much solves this for us! This added support to require node modules via the transform, something like:

style.js

var red = ‘#f00’ module.exports = :host { color: ${red} }

app.js

var css = require(‘sheetify’)var html = require(‘bel’) var prefix = css(‘./style.js’) document.body.appendChild(html <div class="${prefix}">bam!</div>)

wonder if we should call this closed 🤔 ?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/stackcss/sheetify/issues/128#issuecomment-330689992, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWleuHQYDM7AfKojC32XbMTyvZdzTKqks5skD24gaJpZM4OSQz_ .

1reaction
jongacnikcommented, Sep 19, 2017

Hey all @ahdinosaur @yoshuawuyts ! Jumping back in here since #134 pretty much solves this for us! This added support to require node modules via the transform, something like:

style.js

var red = '#f00'

module.exports = `
 :host {
    color: ${red}
  }
`

app.js

var css = require('sheetify')
var html = require('bel')

var prefix = css('./style.js')

document.body.appendChild(html`
  <div class="${prefix}">bam!</div>
`)

wonder if we should call this closed 🤔 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template string interpolation · Issue #623 · emberjs/rfcs - GitHub
This is a good idea, but it doesn't seem like anyone actually wants to write the RFC. Is there anything we can do...
Read more >
String Interpolation for Apex | IdeaExchange - Salesforce
The ability to have line breaks within the template. I feel very burdened when writing tests for my Apex REST methods, which invariably...
Read more >
Code analysis and helpers for string literals - ReSharper
ReSharper analyzes format strings and arguments of all .NET string formatting methods, such as String.Format , Text.StringBuilder.
Read more >
Idea: String interpolation in i18n API - Temenos Basecamp
A good example of how this should work is Javascript's concept of Template Strings using named variable substitutions in a ${var_name} notation, ...
Read more >
Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found