nickclaw / alexa-ssml

JSX for Alexa Skills Kit SSML
MIT License
13 stars 1 forks source link

Is it possible to use this in pure Javascript? #9

Open violivei opened 8 years ago

violivei commented 8 years ago

Hello,

I'm very excited in using alexa-ssml in my project. However, I'm having troubles setting up in pure Javascript. What exactly am I missing? Can you provide guidance?

Thanks and Regards.

nickclaw commented 8 years ago

It is, mostly. You won't get to use the cool tags like you would using a build tool like babel, but you can still get the benefits of validation, custom tags, and easy ssml creation with pure JavaScript. I'll comment with some examples later tonight.

nickclaw commented 8 years ago

So basically if you're using babel. It'll convert to the jsx to pure javascript. This means the following code means the same thing.

/** @jsx ssml */
import {ssml, renderToString } from 'alexa-ssml';  

function CustomTag(props) {
    return <p>Hello World</p>
}

const string = renderToString(
    <speak>
        <CustomTag foo="bar" />
    </speak>
);
var alexaSsml = require('alexa-ssml');
var ssml = alexaSsml.ssml;
var renderToString = alexaSsml.renderToString;

function CustomTag(props) {
    return ssml('p', null, ['Hello World']);
}

const string = renderToString(
   ssml('speak', null, [
         ssml(CustomTag, { foo: 'bar' }) 
   ]);
);

Does that make sense @violivei