Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom functions #27

Open
empyrical opened this issue May 2, 2015 · 4 comments
Open

Custom functions #27

empyrical opened this issue May 2, 2015 · 4 comments

Comments

@empyrical
Copy link

I think it'd be awesome if there was a way to define a function like how node-sass does: (from sass/node-sass#644)

sass.render({
  data: '#{headings(2,5)} { color: #08c; }',
  functions: {
    'headings($from: 0, $to: 6)': function(from, to) {
      var i, f = from.getValue(), t = to.getValue(),
          list = new sass.types.List(t - f + 1);

      for (i = f; i <= t; i++) {
        list.setValue(i - f, new sass.types.String('h' + i));
      }

      return list;
    }
  }
});

Right now, thanks to import hooks, some half dynamic functionality can be put into styles (like inserting the current date into a comment could be done by stuffing it into a variable in an imported "file") but custom functions could potentially allow for something like compass to be used by sass.js

@rodneyrehm
Copy link
Member

Yes, I have custom functions on the radar. What's keeping this from happening is my inability (and lack of time to learn) to figure out the marshaling:

We need to expose Sass_Value in some sort of C++ class, so we can have emscripten marshal the data structure automatically using WebIDL Binder. We need a two way binding (export to JS, import from JS), and for that WebIDL looks like the better option than embind.

Unlike node-sass' implementation, Sass.js will have to make functions work asnychronously, which is not as big of a problem, since we already figured out how to accomplish that using emterpreter for the Importer API.

Custom functions will happen, I'm just not sure when I'll get to land this. Anyone comfortable with C/C++ and emscripten can certainly have a go at it any time, though ;)

@mcampa
Copy link

mcampa commented Feb 14, 2017

Is there any progress on this issue? :)

@rodneyrehm
Copy link
Member

rodneyrehm commented Feb 15, 2017

Unfortunately not. The last attempt to figure this out was in early 2016 and there's been 0 effort since. Do you want to look into this?

@mcampa
Copy link

mcampa commented Feb 15, 2017

I would love to, but I'm not familiar with C/C++ or emscripten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants