Skip to content

Commit

Permalink
added kebab-case component support - Tencent#242
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy authored and dlhandsome committed Aug 16, 2017
1 parent 5dcbaa8 commit 4332017
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/wepy-cli/src/compile-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export default {
comPrefix: {},
comCount: 0,
getPrefix (prefix) {
return prefix;
if (this.comPrefix[prefix])
return this.comPrefix[prefix];
this.comPrefix[prefix] = this.comCount++;
if (!this.comPrefix[prefix]) {
this.comPrefix[prefix] = util.camelize(prefix || '');;
}
return this.comPrefix[prefix];
},
getTemplate (content) {
Expand Down
2 changes: 1 addition & 1 deletion packages/wepy-cli/src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
return loader.loadPlugin(plugins);
},

wepyUpdate(required = '1.5.6') {
wepyUpdate(required = '1.5.8') {
let pkgfile = path.join(util.currentDir, 'node_modules', 'wepy', 'package.json');
let pkg;
try {
Expand Down
15 changes: 15 additions & 0 deletions packages/wepy-cli/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ const utils = {
}
return fs.statSync(p).isDirectory();
},
/**
* Hyphenate a camelCase string.
*/
hyphenate (str) {
return str
.replace(/([^-])([A-Z])/g, '$1-$2')
.replace(/([^-])([A-Z])/g, '$1-$2')
.toLowerCase();
},
/**
* Camelize a hyphen-delimited string.
*/
camelize (str) {
return str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : '');
},
/**
* xml dom 对 TEXT_NODE 和 ATTRIBUTE_NODE 进行转义。
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/wepy/src/base.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import event from './event';
import util from './util';

const PAGE_EVENT = ['onLoad', 'onReady', 'onShow', 'onHide', 'onUnload', 'onPullDownRefresh', 'onReachBottom', 'onShareAppMessage'];
const APP_EVENT = ['onLaunch', 'onShow', 'onHide', 'onError'];


let $bindEvt = (config, com, prefix) => {
com.$prefix = prefix;
com.$prefix = util.camelize(prefix || '');
Object.getOwnPropertyNames(com.components || {}).forEach((name) => {
let cClass = com.components[name];
let child = new cClass();
Expand Down
15 changes: 15 additions & 0 deletions packages/wepy/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ export default {
});
}
return rst;
},
/**
* Hyphenate a camelCase string.
*/
hyphenate (str) {
return str
.replace(/([^-])([A-Z])/g, '$1-$2')
.replace(/([^-])([A-Z])/g, '$1-$2')
.toLowerCase();
},
/**
* Camelize a hyphen-delimited string.
*/
camelize (str) {
return str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : '');
}
};

Expand Down

0 comments on commit 4332017

Please sign in to comment.