在html中转换es6语法,reacterminator

reacterminator

871e2dbbb6e09e85d062d09dc231171b.png

68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f706f657469632f726561637465726d696e61746f722e7376673f6272616e63683d6d6173746572

68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f726561637465726d696e61746f722e737667

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532302532302546302539462539332541362546302539462539412538302d73656d616e7469632d2d72656c656173652d6531303037392e737667

68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f706f657469632f726561637465726d696e61746f722e737667

node> = 6.0.0

用法

如何使用 reacterminator?

Reacterminator将html转换为es6响应组件。

首先,用几个简单的数据属性注释你的html标记,这是 reacterminator。

例如,可以将 data-component-name 属性添加到 html,以便reacterminator知道它是一个React组件://file: example.html

然后让reacterminator完成这项工作:$ reacterminator convert example.html

将在'./components/Unicorn.jsx'处生成名为'unicorn.jsx'的文件,其中包含以下内容:import React from 'react';

export default class Unicorn extends React.Component {

render() {

return (

);

}

}

npm i -g reacterminator

你可以使用 reacterminator 或者 rt。Usage: reacterminator [options] [command]

Commands:

convert|c convert html files into react component files.

generate|g generate custom files.

help [cmd] display help for [cmd]

Convert html files to react components

Options:

-h, --help output usage information

-V, --version output the version number

Examples:

$ reacterminator c design.html

$ reacterminator c design/

$ reacterminator g components/MyCustom

Notes:

If the input is a folder, files ending with -ignore.html will be ignored.

node/**

* convert html to react components

*

* @param {Object} input

* {('path'|'string')} input.type

* {string} input.content

* When input.type is 'string', input.content is the html content.

* When input.type is 'path', input.content specifies the path.

* The path can be a directory or a file.

*

* @param {Object} options

* {boolean} [options.generateFiles=false]

* {string} [options.outputPath='./components']

* {boolean} [options.recursive=false]

* When options.recursive is true, reacterminator will find. html files recursivly

* and convert them into react components.

* When false, reacterminator will only find the. html files

* in the current directory.

**/

var reacterminator = require('reacterminator');

var components = reacterminator(

{

type: 'string',

content: '

},

{

generatefiles: false,

}

);

console.log(components.Unicorn.formattedFileSnippet)

//import React from 'react';

//

//export default class Unicorn extends React.Component {

//render() {

//return (

//

//);

//}

//}

工作流在阅读中写规范

编写测试

实现( 请按 npm run test:watch:mocha 操作 TDD )

在执行 PR ( npm test ) 之前确保以下各项linting传递

测试通过

100%覆盖

设置安装正确的node 版本nvm install #. nvmrc is used to specify node version

nvm use确保你可以运行这里命令:npm run test

//Coverall will give you an error since your local is not a travis-ci environment.

//That is OK.

资源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值