浏览代码

Add check-api tools

zhixin 6 年之前
父节点
当前提交
cfd6d5db24
共有 9 个文件被更改,包括 339 次插入184 次删除
  1. 2 0
      .npmignore
  2. 7 5
      site/docs/api/localizations.md
  3. 116 113
      site/docs/api/methods.md
  4. 36 30
      site/docs/api/table-options.md
  5. 3 34
      src/bootstrap-table.js
  6. 36 2
      src/constants/index.js
  7. 7 0
      tools/README.md
  8. 98 0
      tools/check-api.js
  9. 34 0
      tools/loader.mjs

+ 2 - 0
.npmignore

@@ -0,0 +1,2 @@
+tools
+site

+ 7 - 5
site/docs/api/localizations.md

@@ -74,6 +74,8 @@ $('#table').bootstrapTable({
 
 - **Default:** `'No matching records found'`
 
+## formatPaginationSwitch
+
 ## formatRefresh
 
 - **Parameter:** `undefined`
@@ -92,14 +94,14 @@ $('#table').bootstrapTable({
 
 - **Default:** `'Columns'`
 
-## formatAllRows
+## formatFullscreen
 
 - **Parameter:** `undefined`
 
-- **Default:** `'All'`
-
-## formatFullscreen
+- **Default:** `'Fullscreen'`
+## formatAllRows
 
 - **Parameter:** `undefined`
 
-- **Default:** `'Fullscreen'`
+- **Default:** `'All'`
+

+ 116 - 113
site/docs/api/methods.md

@@ -32,22 +32,6 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Return all selected rows contain search or filter, when no record selected, an empty array will return.
 
-## showAllColumns
-
-- **Parameter:** `undefined`
-
-- **Detail:**
-
-  Show All the columns.
-
-## hideAllColumns
-
-- **Parameter:** `undefined`
-
-- **Detail:**
-
-  Hide All the columns.
-
 ## getData
 
 - **Parameter:** `useCurrentPage`
@@ -56,14 +40,6 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Get the loaded data of table at the moment that this method is called. If you set the `useCurrentPage` to `true` the method will return the data in the current page.
 
-## getRowByUniqueId
-
-- **Parameter:** `id`
-
-- **Detail:**
-
-  Get data from table, the row that contains the `id` passed by parameter.
-
 ## load
 
 - **Parameter:** `data`
@@ -107,14 +83,6 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Remove all data from table.
 
-## removeByUniqueId
-
-- **Parameter:** `id`
-
-- **Detail:**
-
-  Remove data from table, the row that contains the `id` passed by parameter.
-
 ## insertRow
 
 - **Parameter:** `params`
@@ -137,6 +105,20 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `index`: the row index to be updated.
   * `row`: the new row data.
 
+## updateCell
+
+- **Parameter:** `params`
+
+- **Detail:**
+
+  Update one cell, the params contain following properties:
+
+  * `index`: the row index.
+  * `field`: the field name.
+  * `value`: the new field value.
+
+  To disable table re-initialization you can set `{reinit: false}`.
+
 ## updateByUniqueId
 
 - **Parameter:** `params`
@@ -148,17 +130,21 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `id`: a row id where the id should be the uniqueid field assigned to the table.
   * `row`: the new row data.
 
-## updateCellById
+## removeByUniqueId
 
-- **Parameter:** `params`
+- **Parameter:** `id`
 
 - **Detail:**
 
-  Update the cell specified by the id, each params contain following properties:
+  Remove data from table, the row that contains the `id` passed by parameter.
 
-  * `id`: row id where the id should be the uniqueid field assigned to the table.
-  * `field`: field name of the cell to be updated.
-  * `value`: new value of the cell.
+## getRowByUniqueId
+
+- **Parameter:** `id`
+
+- **Detail:**
+
+  Get data from table, the row that contains the `id` passed by parameter.
 
 ## showRow
 
@@ -203,59 +189,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `rowspan`: the rowspan count to be merged.
   * `colspan`: the colspan count to be merged.
 
-## updateCell
-
-- **Parameter:** `params`
-
-- **Detail:**
-
-  Update one cell, the params contain following properties:
-
-  * `index`: the row index.
-  * `field`: the field name.
-  * `value`: the new field value.
-
-  To disable table re-initialization you can set `{reinit: false}`.
-
-## refresh
-
-- **Parameter:** `params`
-
-- **Detail:**
-
-  Refresh the remote server data, you can set `{silent: true}` to refresh the data silently, and set `{url: newUrl, pageNumber: pageNumber, pageSize: pageSize}` to change the url (optional), page number (optional) and page size (optional). To supply query params specific to this request, set `{query: {foo: 'bar'}}`.
-
-## refreshOptions
-
-- **Parameter:** `options`
-
-- **Detail:**
-
-  Refresh the table `options`.
-
-## resetSearch
-
-- **Parameter:** `text`
-
-- **Detail:**
-
-  Set the search `text`.
-
-## showLoading
-
-- **Parameter:** `undefined`
-
-- **Detail:**
-
-  Show loading status.
-
-## hideLoading
-
-- **Parameter:** `undefined`
-
-- **Detail:**
-
-  Hide loading status.
+## refreshColumnTitle
 
 ## checkAll
 
@@ -319,6 +253,14 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `field`: name of the field used to find records.
   * `values`: array of values for rows to uncheck.
 
+## refresh
+
+- **Parameter:** `params`
+
+- **Detail:**
+
+  Refresh the remote server data, you can set `{silent: true}` to refresh the data silently, and set `{url: newUrl, pageNumber: pageNumber, pageSize: pageSize}` to change the url (optional), page number (optional) and page size (optional). To supply query params specific to this request, set `{query: {foo: 'bar'}}`.
+
 ## resetView
 
 - **Parameter:** `params`
@@ -345,13 +287,29 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Destroy the Bootstrap Table.
 
+## showLoading
+
+- **Parameter:** `undefined`
+
+- **Detail:**
+
+  Show loading status.
+
+## hideLoading
+
+- **Parameter:** `undefined`
+
+- **Detail:**
+
+  Hide loading status.
+
 ## showColumn
 
 - **Parameter:** `field`
 
 - **Detail:**
 
-  Show the specified `field` column.   
+  Show the specified `field` column.
   The parameter can be a string or a array of fields.
 
 ## hideColumn
@@ -360,7 +318,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
 - **Detail:**
 
-  Hide the specified `field` column.   
+  Hide the specified `field` column.
   The parameter can be a string or a array of fields.
 
 ## getHiddenColumns
@@ -379,50 +337,46 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Get visible columns.
 
-## scrollTo
+## showAllColumns
 
-- **Parameter:** `value|object`
+- **Parameter:** `undefined`
 
 - **Detail:**
 
-  - value
-    - Scroll to the number `value` position, the unit is `'px'`, set `'bottom'` means scroll to the bottom.
-  - object
-    -  Scroll to the unit (`px` or `rows (index starts by 0)`)   
-    Default: `{unit: 'px', value: 0}`
-    
-## getScrollPosition
+  Show All the columns.
+
+## hideAllColumns
 
 - **Parameter:** `undefined`
 
 - **Detail:**
 
-  Get the current scroll position, the unit is `'px'`.
+  Hide All the columns.
 
 ## filterBy
 
 - **Parameter:**
-    - `filter - An Object of filter`   
+    - `filter - An Object of filter`
     Default: `{}`
-    - `options - An Object of options`   
+    - `options - An Object of options`
     Default:
         ```
         {
             'filterAlgorithm': 'and'
         }
         ```
-       
+
 
 - **Detail:**
-  
-  (Can use only in client-side) Filter data in table.   
+
+  (Can use only in client-side) Filter data in table.
   There are multiple ways to filter:
   - Leave the options blank to use the `and` filter.
   - Set the `filterAlgorithm` (see at parameter) to `or` to use the `or` filter.
   - Pass a function to the `filterAlgorithm` (see at parameter) to use a `custom` filter.
-    
+
   #####Filter Algorithm
-  
+
   - And
     - Filter `{age: 10}` to show the data only age is equal to 10.  You can also filter with an array of values, as in: `{age: 10, hairColor: ['blue', 'red', 'green']}` to find data where age is equal to 10 and hairColor is either blue, red, or green.
   - Or
@@ -435,6 +389,26 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
     - Return `true` to keep the row and return `false` to filter the row.
 
 
+## scrollTo
+
+- **Parameter:** `value|object`
+
+- **Detail:**
+
+  - value
+    - Scroll to the number `value` position, the unit is `'px'`, set `'bottom'` means scroll to the bottom.
+  - object
+    -  Scroll to the unit (`px` or `rows (index starts by 0)`)
+    Default: `{unit: 'px', value: 0}`
+
+## getScrollPosition
+
+- **Parameter:** `undefined`
+
+- **Detail:**
+
+  Get the current scroll position, the unit is `'px'`.
+
 ## selectPage
 
 - **Parameter:** `page`
@@ -475,13 +449,21 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Toggle the card/table view.
 
-## toggleDetailView
+## refreshOptions
 
-- **Parameter:** `index`
+- **Parameter:** `options`
 
 - **Detail:**
 
-  Toggle the row that has the `index` passed by parameter if the detail view option is set to `true`.
+  Refresh the table `options`.
+
+## resetSearch
+
+- **Parameter:** `text`
+
+- **Detail:**
+
+  Set the search `text`.
 
 ## expandRow
 
@@ -499,6 +481,14 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
   Collapse the row that has the `index` passed by parameter if the detail view option is set to `true`.
 
+## toggleDetailView
+
+- **Parameter:** `index`
+
+- **Detail:**
+
+  Toggle the row that has the `index` passed by parameter if the detail view option is set to `true`.
+
 ## expandAllRows
 
 - **Detail:**
@@ -510,3 +500,16 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 - **Detail:**
 
   Collapse all rows if the detail view option is set to `true`.
+## updateFormatText
+
+## updateCellById
+
+- **Parameter:** `params`
+
+- **Detail:**
+
+  Update the cell specified by the id, each params contain following properties:
+
+  * `id`: row id where the id should be the uniqueid field assigned to the table.
+  * `field`: field name of the cell to be updated.
+  * `value`: new value of the cell.

+ 36 - 30
site/docs/api/table-options.md

@@ -306,12 +306,12 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Default:** `undefined`
 
+- **Example:** [From URL](https://examples.bootstrap-table.com/#welcomes/from-url.html)
+
 - **Error handling**
 
   To get loading errors please use [onLoadError](https://bootstrap-table.com/docs/api/events/#onloaderror)
 
-- **Example:** [From URL](https://examples.bootstrap-table.com/#welcomes/from-url.html)
-
 ## method
 
 - **Attribute:** `data-method`
@@ -460,6 +460,20 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Total/Data Field](https://examples.bootstrap-table.com/#options/total-data-field.html)
 
+## totalNotFilteredField
+
+- **Attribute:** `data-total-not-filtered-field`
+
+- **Type:** `string`
+
+- **Detail:**
+
+  The field from the json response which will used for showExtendedPagination.
+
+- **Default:** `totalNotFiltered`
+
+- **Example:** [Total Not Filtered Field](https://examples.bootstrap-table.com/#options/total-not-filtered-field.html)
+
 ## dataField
 
 - **Attribute:** `data-data-field`
@@ -517,20 +531,6 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Show Extended Pagination](https://examples.bootstrap-table.com/#options/show-extended-pagination.html)
 
-## totalNotFilteredField
-
-- **Attribute:** `data-total-not-filtered-field`
-
-- **Type:** `string`
-
-- **Detail:**
-
-  The field from the json response which will used for showExtendedPagination.
-
-- **Default:** `totalNotFiltered`
-
-- **Example:** [Total Not Filtered Field](https://examples.bootstrap-table.com/#options/total-not-filtered-field.html)
-
 ## paginationLoop
 
 - **Attribute:** `data-pagination-loop`
@@ -577,6 +577,8 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Default:** `0`
 
+## totalNotFiltered
+
 ## pageNumber
 
 - **Attribute:** `data-page-number`
@@ -1032,6 +1034,8 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Table Escape](https://examples.bootstrap-table.com/#options/table-escape.html)
 
+## filterOptions
+
 ## idField
 
 - **Attribute:** `data-id-field`
@@ -1206,6 +1210,20 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Detail View Icon](https://examples.bootstrap-table.com/#options/detail-view-icon.html)
 
+## detailViewByClick
+
+- **Attribute:** `data-detail-view-by-click`
+
+- **Type:** `Boolean`
+
+- **Detail:**
+
+  Set `true` to toggle the detail view, when a cell is clicked.
+
+- **Default:** `false`
+
+- **Example:** [Detail View Icon](https://examples.bootstrap-table.com/#options/detail-view-icon.html)
+
 ## detailFormatter
 
 - **Attribute:** `data-detail-formatter`
@@ -1234,20 +1252,6 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Detail Filter](https://examples.bootstrap-table.com/#options/detail-filter.html)
 
-## detailViewByClick
-
-- **Attribute:** `data-detail-view-by-click`
-
-- **Type:** `Boolean`
-
-- **Detail:**
-
-  Set `true` to toggle the detail view, when a cell is clicked.
-
-- **Default:** `false`
-
-- **Example:** [Detail View Icon](https://examples.bootstrap-table.com/#options/detail-view-icon.html)
-
 ## toolbar
 
 - **Attribute:** `data-toolbar`
@@ -1304,6 +1308,8 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Buttons Align](https://examples.bootstrap-table.com/#options/buttons-align.html)
 
+## buttonsPrefix
+
 ## buttonsClass
 
 - **Attribute:** `data-buttons-class`

+ 3 - 34
src/bootstrap-table.js

@@ -2680,43 +2680,12 @@ BootstrapTable.VERSION = Constants.VERSION
 BootstrapTable.DEFAULTS = Constants.DEFAULTS
 BootstrapTable.LOCALES = Constants.LOCALES
 BootstrapTable.COLUMN_DEFAULTS = Constants.COLUMN_DEFAULTS
+BootstrapTable.METHODS = Constants.METHODS
 BootstrapTable.EVENTS = Constants.EVENTS
 
 // BOOTSTRAP TABLE PLUGIN DEFINITION
 // =======================
 
-const allowedMethods = [
-  'getOptions',
-  'getSelections', 'getAllSelections', 'getData',
-  'load', 'append', 'prepend', 'remove', 'removeAll',
-  'insertRow', 'updateRow', 'updateCell',
-  'updateByUniqueId', 'removeByUniqueId',
-  'getRowByUniqueId', 'showRow', 'hideRow', 'getHiddenRows',
-  'mergeCells', 'refreshColumnTitle',
-  'checkAll', 'uncheckAll', 'checkInvert',
-  'check', 'uncheck',
-  'checkBy', 'uncheckBy',
-  'refresh',
-  'resetView',
-  'resetWidth',
-  'destroy',
-  'showLoading', 'hideLoading',
-  'showColumn', 'hideColumn',
-  'getHiddenColumns', 'getVisibleColumns',
-  'showAllColumns', 'hideAllColumns',
-  'filterBy',
-  'scrollTo',
-  'getScrollPosition',
-  'selectPage', 'prevPage', 'nextPage',
-  'togglePagination',
-  'toggleView',
-  'refreshOptions',
-  'resetSearch',
-  'expandRow', 'collapseRow', 'toggleDetailView',
-  'expandAllRows', 'collapseAllRows',
-  'updateFormatText', 'updateCellById'
-]
-
 $.BootstrapTable = BootstrapTable
 $.fn.bootstrapTable = function (option, ...args) {
   let value
@@ -2727,7 +2696,7 @@ $.fn.bootstrapTable = function (option, ...args) {
       typeof option === 'object' && option)
 
     if (typeof option === 'string') {
-      if (!allowedMethods.includes(option)) {
+      if (!Constants.METHODS.includes(option)) {
         throw new Error(`Unknown method: ${option}`)
       }
 
@@ -2757,7 +2726,7 @@ $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS
 $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS
 $.fn.bootstrapTable.events = BootstrapTable.EVENTS
 $.fn.bootstrapTable.locales = BootstrapTable.LOCALES
-$.fn.bootstrapTable.methods = allowedMethods
+$.fn.bootstrapTable.methods = BootstrapTable.METHODS
 $.fn.bootstrapTable.utils = Utils
 
 // BOOTSTRAP TABLE INIT

+ 36 - 2
src/constants/index.js

@@ -369,12 +369,44 @@ const COLUMN_DEFAULTS = {
   events: undefined
 }
 
+const METHODS = [
+  'getOptions',
+  'getSelections', 'getAllSelections', 'getData',
+  'load', 'append', 'prepend', 'remove', 'removeAll',
+  'insertRow', 'updateRow', 'updateCell',
+  'updateByUniqueId', 'removeByUniqueId',
+  'getRowByUniqueId', 'showRow', 'hideRow', 'getHiddenRows',
+  'mergeCells', 'refreshColumnTitle',
+  'checkAll', 'uncheckAll', 'checkInvert',
+  'check', 'uncheck',
+  'checkBy', 'uncheckBy',
+  'refresh',
+  'resetView',
+  'resetWidth',
+  'destroy',
+  'showLoading', 'hideLoading',
+  'showColumn', 'hideColumn',
+  'getHiddenColumns', 'getVisibleColumns',
+  'showAllColumns', 'hideAllColumns',
+  'filterBy',
+  'scrollTo',
+  'getScrollPosition',
+  'selectPage', 'prevPage', 'nextPage',
+  'togglePagination',
+  'toggleView',
+  'refreshOptions',
+  'resetSearch',
+  'expandRow', 'collapseRow', 'toggleDetailView',
+  'expandAllRows', 'collapseAllRows',
+  'updateFormatText', 'updateCellById'
+]
+
 const EVENTS = {
   'all.bs.table': 'onAll',
-  'click-cell.bs.table': 'onClickCell',
-  'dbl-click-cell.bs.table': 'onDblClickCell',
   'click-row.bs.table': 'onClickRow',
   'dbl-click-row.bs.table': 'onDblClickRow',
+  'click-cell.bs.table': 'onClickCell',
+  'dbl-click-cell.bs.table': 'onDblClickCell',
   'sort.bs.table': 'onSort',
   'check.bs.table': 'onCheck',
   'uncheck.bs.table': 'onUncheck',
@@ -413,6 +445,8 @@ export default {
 
   COLUMN_DEFAULTS,
 
+  METHODS,
+
   EVENTS,
 
   LOCALES: {

+ 7 - 0
tools/README.md

@@ -0,0 +1,7 @@
+# Tools
+
+## check-api
+
+```
+node --experimental-modules --loader ./loader.mjs check-api.js
+```

+ 98 - 0
tools/check-api.js

@@ -0,0 +1,98 @@
+import fs from 'fs'
+import Constants from '../src/constants/index.js'
+
+class API {
+  constructor () {
+    this.init()
+    this.check()
+  }
+
+  check () {
+    const file = `../site/docs/api/${this.file}`
+    const md = {}
+    const content = fs.readFileSync(file).toString()
+    const lines = content.split('## ')
+    const outLines = lines.slice(0, 1)
+
+    console.log(`Checking file: ${file}`)
+
+    for (const item of lines.slice(1)) {
+      md[item.split('\n')[0]] = item
+    }
+
+    const mds = Object.keys(md)
+    for (const [i, key] of this.options.entries()) {
+      if (md[key]) {
+        outLines.push(md[key])
+        const details = md[key].split('\n\n- ')
+
+        for (let i = 0; i < this.attributes.length; i++) {
+          const name = this.attributes[i]
+          if (this.ignore && this.ignore[key] && this.ignore[key].includes(name)) {
+            continue
+          }
+          if (!details[i + 1] || details[i + 1].indexOf(`**${name}:**`) === -1) {
+            console.log(`${key} missing ${name}`)
+          }
+        }
+      } else {
+        outLines.push(key + '\n\n')
+      }
+    }
+
+    fs.writeFile(file, outLines.join('## '), () => {})
+  }
+}
+
+class TableOptions extends API {
+  init () {
+    this.file = 'table-options.md'
+    this.options = Object.keys(Constants.DEFAULTS).filter(it => {
+      return !/^(on|format)[A-Z]/.test(it)
+    })
+    this.options.unshift('-')
+    this.attributes = ['Attribute', 'Type', 'Detail', 'Default', 'Example']
+    this.ignore = {
+      totalRows: ['Example'],
+      totalNotFiltered: ['Example']
+    }
+  }
+}
+
+class ColumnOptions extends API {
+  init () {
+    this.file = 'column-options.md'
+    this.options = Object.keys(Constants.COLUMN_DEFAULTS)
+    this.attributes = ['Attribute', 'Type', 'Detail', 'Default']// , 'Example']
+  }
+}
+
+class Methods extends API {
+  init () {
+    this.file = 'methods.md'
+    this.options = Constants.METHODS
+    this.attributes = ['Parameter', 'Detail']// , 'Example']
+  }
+}
+
+class Events extends API {
+  init () {
+    this.file = 'events.md'
+    this.options = Object.values(Constants.EVENTS)
+    this.attributes = ['jQuery Event', 'Parameter', 'Detail']
+  }
+}
+
+class Localizations extends API {
+  init () {
+    this.file = 'localizations.md'
+    this.options = Object.keys(Constants.LOCALES.en)
+    this.attributes = ['Parameter', 'Default']
+  }
+}
+
+new TableOptions()
+new ColumnOptions()
+new Methods()
+new Events()
+new Localizations()

+ 34 - 0
tools/loader.mjs

@@ -0,0 +1,34 @@
+import path from 'path'
+import process from 'process'
+import Module from 'module'
+
+const builtins = Module.builtinModules
+const JS_EXTENSIONS = new Set(['.js', '.mjs'])
+
+const baseURL = new URL('file://')
+baseURL.pathname = `${process.cwd()}/`
+
+export function resolve (specifier, parentModuleURL = baseURL, defaultResolve) {
+  if (builtins.includes(specifier)) {
+    return {
+      url: specifier,
+      format: 'builtin'
+    }
+  }
+  if (/^\.{0,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
+    // For node_modules support:
+    // return defaultResolve(specifier, parentModuleURL);
+    throw new Error(
+      `imports must begin with '/', './', or '../'; '${specifier}' does not`)
+  }
+  const resolved = new URL(specifier, parentModuleURL)
+  const ext = path.extname(resolved.pathname)
+  if (!JS_EXTENSIONS.has(ext)) {
+    throw new Error(
+      `Cannot load file with non-JavaScript file extension ${ext}.`)
+  }
+  return {
+    url: resolved.href,
+    format: 'esm'
+  }
+}