注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Computer Science

I Pressed My Words Here. Will You Read ?

 
 
 

日志

 
 

用JavaScript编写、解析及生成 对象框架组件文档(一)文档编写篇  

2012-07-10 20:51:25|  分类: My Projects |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
首先选择JavaScript的函数结合JSON数据格式描述对象的属性、事件、方法。
这种描述方式的优点:
灵活,可以实现对应框架中组件对象的文档间的继承/重写。

不足:以JSON格式描述的对象文档,若要输出成更加人性化的文本格式,需要输出者自己编写/修改输出程序。

————————————

文档示例:
   1 var getDocument = function() {
   2         var v = {};
   3         v.log = "Document for recording comps.";
   4         v.baseLocation = 'js/comps/';
   5         v.config = {};
   6         // 基本通用方法
   7         var components = $.extend({}, {
   8                 commonAttributes: {
   9 +------372 lines: 'border': function(compNameStr) {
 381                 }
 382                 ,commonEvents: {
 383 +------ 36 lines: 'beforeshow': function() {
 419                 }
 420                 ,commonFunctions: {
 421 +------792 lines: 'draw': function(compNameStr) {
1213                 }
1214         });
1215         v = $.extend({}, v, {
1216                 components: components
1217         });
1218         // 组件/注册组件及其属性类型
1219         components = $.extend({}, components, {
1220                 'comp': {
1221 +------  5 lines: fileName: 'ui.js'
1226                 }
1227                 ,'button': {
1228 +------  5 lines: fileName: 'ui-comp-Button.js'
1233                 }
1234                 ,'datepicker': {
1235 +------  5 lines: fileName: 'ui-comp-Datepicker.js'
1240                 }
1241                 ,'dialog': {
1242 +------  5 lines: fileName: 'ui-comp-Dialog.js'
1247                 }
1248                 ,'fileupload': {
1249 +------  5 lines: fileName: 'ui-comp-Fileupload.js'
1254                 }
1255                 ,'footer': {
1256 +------  5 lines: fileName: 'ui-comp-Footer.js'
1261                 }
1262                 ,'form': {
1263 +------  5 lines: fileName: 'ui-comp-Form.js'
1268                 }
1269                 ,'formcontrols': {
1270 +------  5 lines: fileName: 'ui-comp-Formcontrols.js'
1275                 }
1276                 ,'frametab': {
1277 +------  5 lines: fileName: 'ui-comp-FrameTab.js'
1282                 }
1283                 ,'header': {
1284 +------  5 lines: fileName: 'ui-comp-Header.js'
1289                 }
1290                 ,'loader': {
1291 +------  5 lines: fileName: 'ui-comp-Loader.js'
1296                 }
1297                 ,'nav': {
1298 +------  5 lines: fileName: 'ui-comp-Navjs'
1303                 }
1304                 ,'radiocheck': {
1305 +------  5 lines: fileName: 'ui-comp-Radiocheck.js'
1310                 }
1311                 ,'select': {
1312 +------  5 lines: fileName: 'ui-comp-Select.js'
1317                 }
1318                 ,'tab': {
1319 +------  5 lines: filename: 'ui-comp-Tab.js'
1324                 }
1325                 ,'table': {
1326 +------  5 lines: filename: 'ui-comp-Table.js'
1331                 }
1332                 ,'template': {
1333 +------  5 lines: fileName: 'ui-comp-Template.js'
1338                 }
1339                 ,'textarea': {
1340 +------  5 lines: fileName: 'ui-comp-Textarea.js'
1345                 }
1346                 ,'textinput': {
1347 +------  5 lines: fileName: 'ui-comp-Textinput.js'
1352                 }
1353                 ,'toolbar': {
1354 +------  5 lines: fileName: 'ui-comp-Toolbar.js'
1359                 }
1360                 ,'tree': {
1361 +------  5 lines: fileName: 'ui-comp-Tree.js'
1366                 }
1367                 ,'ratingbar': {
1368                         fileName: 'ui-comp-RatingBar.js'
1369                         ,name: 'RatingBar'
1370                         ,attributes: {}
1371                         ,events: {}
1372                         ,functions: {}
1373                 }
1374         });
1375
1376         //循环初始化函数
1377         for (var compName in components) {
1378                 var compObj = components[compName];
1379                 switch (compName) {
1380                 case 'comp':
1381 +------141 lines: function extendComp() {
1522                 case 'button':
1523 +------140 lines: function extendButton() {
1663                 case 'datepicker':
1664 +------148 lines: function extendDatepicker() {
1812                 case 'dialog':
1813 +------127 lines: function extendDailog() {
1940                 case 'fileupload':
1941 +------ 17 lines: function fileupload() {
1958                 case 'footer':
1959 +------ 19 lines: function extendFooter() {
1978                 case 'form':
1979 +------279 lines: function extendForm() {
2258                 case 'formcontrols':
2259 +------210 lines: function extendFormcontrols() {
2469                 case 'frametab':
2470 +------ 59 lines: function extendFrameTab() {
2529                 case 'header':
2530 +------ 34 lines: function extendHeader() {
2564                 case 'loader':
2565 +------ 78 lines: function extendLoader() {
2643                 case 'nav':
2644 +------ 81 lines: function extendNav() {
2725                 case 'radiocheck':
2726 +------ 70 lines: function extendRadiocheck() {
2796                 case 'select':
2797 +------167 lines: function extendSelect() {
2964                 case 'tab':
2965 +------ 84 lines: function extendTab() {
3049                 case 'table':
3050 +------754 lines: function extendTable() {
3804                 case 'template':
3805 +------ 22 lines: function extendTemplate() {
3827                 case 'textarea':
3828 +------ 43 lines: function extendTextarea() {
3871                 case 'textinput':
3872 +------ 98 lines: function extendTextinput() {
3970                 case 'toolbar':
3971 +------ 19 lines: function extendToolbar() {
3990                 case 'tree':
3991 +------515 lines: function extendTree() {
4506                 case 'ratingbar':
4507                         function extendRatingBar() {
4508                                 extendComp();
4509                                 for (var compProp in compObj) {
4510                                         var propObj = compObj[compProp];
4511                                         switch (compProp) {
4512                                         case 'attributes':
4513 +------------168 lines: propObj['id'] = {
4681                                         case 'events':
4682                                                 break;
4683                                         case 'functions':
4684 +------------185 lines: propObj['_prepareTextValues'] = {
4869                                         default:
4870                                                 break;
4871                                         }
4872                                 }
4873                         };
4874                         break;
4875                 default:
4876                         break;
4877                 }
4878         }
4879         //循环调用函数
4880         for (var compName in components) {
4881                 var compObj = components[compName];
4882                 switch (compName) {
4883                 case 'comp':
4884 +------  2 lines: extendComp();
4886                 case 'button':
4887 +------  2 lines: extendButton();
4889                 case 'datepicker':
4890 +------  2 lines: extendDatepicker();
4892                 case 'dialog':
4893 +------  2 lines: extendDailog();
4895                 case 'fileupload':
4896
4897                         break;
4898                 case 'footer':
4899 +------  2 lines: extendFooter();
4901                 case 'form':
4902 +------  2 lines: extendForm();
4904                 case 'formcontrols':
4905 +------  2 lines: extendFormcontrols();
4907                 case 'frametab':
4908 +------  2 lines: extendFrameTab();
4910                 case 'header':
4911 +------  2 lines: extendHeader();
4913                 case 'loader':
4914 +------  2 lines: extendLoader();
4916                 case 'nav':
4917 +------  2 lines: extendNav();
4919                 case 'radiocheck':
4920 +------  2 lines: extendRadiocheck();
4922                 case 'select':
4923 +------  2 lines: extendSelect();
4925                 case 'tab':
4926 +------  2 lines: extendTab();
4928                 case 'table':
4929 +------  2 lines: extendTable();
4931                 case 'template':
4932 +------  2 lines: extendTemplate();
4934                 case 'textarea':
4935 +------  2 lines: extendTextarea();
4937                 case 'textinput':
4938 +------  2 lines: extendTextinput();
4940                 case 'tree':
4941 +------  2 lines: extendTree();
4943                 case 'ratingbar':
4944                         extendRatingBar();
4945                         break;
4946                 default:
4947                         break;
4948                 }
4949         }
4950
4951         v = $.extend({}, v, {
4952                 components: components
4953         });
4954         delete components;
4955
4956         v = $.extend({}, v, {
4957                 zh_cn: {
4958                         log: '记录'
4959                         ,baseLocation: '(文件)基准位置'
4960                         ,components: '组件'
4961                         ,commonFunctions: '通用接口'
4962                         ,usage: '用途'
4963                         ,comment: '注释'
4964                         ,'arguments': '参数'
4965                         ,'return': '返回值'
4966                         ,type: '类型'
4967                         ,fileName: '文件名称'
4968                         ,name: '名称'
4969                         ,renamedFunctions: '被重命名的函数'
4970                         ,originalName: '原名称'
4971                         ,addedFunctions: '增加的函数'
4972                         ,modifiedFunctions: '被修改的函数'
4973                         ,modifications: '变化'
4974                         ,validValues: '有意义的值'
4975                         ,renamedAttributes: '被重命名的属性'
4976                         ,addedAttributes: '增加的属性'
4977                         ,necessity: '必要性'
4978                         ,reference: '牵涉'
4979                         ,dependence: '依赖'
4980                         ,defaultValue: '默认值'
4981                         ,specialValue: '特定值'
4982                         ,addedEvents: '增加的事件'
4983                         ,'function()': 'function()'
4984                         ,'true': '真'
4985                         ,'false': '假'
4986                 }
4987         });
4988
4989         v = $.extend({}, v, {
4990                 symbol: {
4991                         is: ':'
4992                         ,or: ';'
4993                         ,newLine: '<br/>'
4994                         ,newParagraph:''
4995                         ,indent: '&nbsp;&nbsp;&nbsp;&nbsp;'
4996                         ,domStart:'<div onclick="toggleVisiable(event,this)" style="display:inline">'
4997                         ,domEnd:'</div>'
4998                         ,':': ':'
4999                         ,'{}': '空对象'
5000                         ,'{': '<div onclick="toggleVisiable(event,this)" style="display:inline"><br/>' //<br/>
5001                         ,'}': '</div><br/>' //<br/>
5002                         ,'[]': '空数组'
5003                         ,'[': ' '
5004                         ,']': ' '
5005                         ,'"': '"'
5006                         ,'"': '"'
5007                         ,',': ','
5008                 }
5009         });
5010         return v;
5011 }
5012 
————————————————————
  评论这张
 
阅读(939)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017