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
require(*tag-name*)
does not allow parserOptions
#1935
Comments
@bonpixel do you have any idea or suggestions about the syntax we need? I have no idea to pass the option through An easy and solid workaround is precompiling the tags into JavaScript files. |
@cognitom It seems to me that My thought here was this: Riot already provides a way to add let riot = require( 'riot' )({
parserOptions: {
style: {
includePaths: require( 'node-bourbon' ).includePaths
}
}
}); Do you agree? I do understand your point about pre-compiling the tag but I was hoping to avoid that. The main reason is that I will need to create a lot of glue code to make that possible. That is an option of course but will make what was otherwise a simple concept more complex. To provide a little more background information on what lead me to this "issue/enhancement": I am trying to do unit testing for components. Here is the example I was trying to go for:
"use strict";
let riot = require( 'riot' );
let cheerio = require( 'cheerio' );
let expect = require( 'expect.js' );
let comp = require( './myTag' ); // Here is where the error happens when the tag has a custom plugin like `bourbon`
describe( '<myTag> ::', () => {
let tag, $;
before( () => {
tag = riot.render( comp );
$ = cheerio.load( tag );
});
describe('Anchor', () => {
it( 'Contains an anchor', () => {
expect( $( 'a' ).length ).to.be( 1 );
});
it( 'Contains an alt tag', () => {
expect( $( 'a' ).attr( 'alt' ) ).to.be.ok();
});
it( 'Uses either a default or dynamic value for alt text', () => {
expect( $( 'a' ).attr( 'alt' ) ).to.be( 'My Alt Text' );
tag = riot.render( comp, { alt: 'Dynamic Value' });
$ = cheerio.load( tag );
expect( $( 'a' ).attr( 'alt' ) ).to.be( 'Dynamic Value' );
});
});
}); I wrote this because I want to be able to unit test components in isolation. The above code is really straightforward and readable which is awesome. I just run into trouble where |
As I have already mentioned here I would like to add riot.require|riot.register|riot.load to allow requiring tags also with options. I think I could work on it soon |
@GianlucaGuarini an official loader sounds like an excellent solution. I noticed too that it was deprecated in the Node docs but the documentation seemed to indicate that it wasn't really going to change. I like the idea of an official loader better though. for now, I came up with a hacky work around of extending the compile method: let riot = require( 'riot' );
let _ = require( 'lodash' );
let tmp = riot.compile;
riot.compile = function(){
// (src, opts, url)
var args = arguments;
return tmp.call(riot, args[0], _.extend({
parserOptions: {
style: {
includePaths: require( 'node-bourbon' ).includePaths
}
}
}, args[1]), args[2]);
}; Not my favorite thing to do, but it works. |
@bonpixel - We do something similar. We read the tag file from disk and together with our parser options, pass it into |
Guys you could try my patch I guess it should not be hard to include it in your workflow. 8f24714 I guess |
Describe your issue:
Requiring a tag via
require
does not allowparserOptions
to be set. This affects tags that require custom options to compile.More Background Below
Can you reproduce the issue?
Not via plunkr, this is a server-side issue.
On which browser/OS does the issue appear?
Node
Which version of Riot does it affect?
All
How would you tag this issue?
Background
I've been trying to utilize riot's ability for server-side rendering http://riotjs.com/guide/#server-side-rendering
BUT
myTag
in this example is also using a custom style type ofscss
and a node-sass pluginbourbon
.When I try to bring in the file via require, it fails since it doesn't know what
bourbon
isI can see that
require
here ultimately callsriot.compile
on the tagbut there is not a way to pass in
opts
with specificparserOptions
when using require.Is there another way that I can load a tag into a file server-side that would allow me to pass in
opts
or, better yet, is there a way that I can set theparserOptions
at a global level? (specifically I need to set theincludePaths
to include thebourbon
plugin path)The text was updated successfully, but these errors were encountered: