Browse Source

Merge pull request #5165 from wenzhixin/improved-tools

Improved tools (check if the examples are valid)
文翼 5 years ago
parent
commit
c502a273eb

+ 3 - 0
.travis.yml

@@ -9,6 +9,9 @@ jobs:
       node_js:
         - 12
       name: "Lint src and check docs"
+      before_install:
+        - cd tools
+        - git clone --depth=1 https://github.com/wenzhixin/bootstrap-table-examples
       script: npm run pre-commit
       if: type = pull_request
 

+ 1 - 1
site/docs/api/column-options.md

@@ -254,7 +254,7 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
 
 - **Default:** `undefined`
 
-- **Example:** [Column Formatter](https://examples.bootstrap-table.com/#column-options/format.html)
+- **Example:** [Column Formatter](https://examples.bootstrap-table.com/#column-options/formatter.html)
 
 ## halign
 

+ 2 - 2
site/docs/api/methods.md

@@ -190,7 +190,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `unfiltered`: if set to true the method will include all data (unfiltered).
   * `formatted`: get the formatted value from the defined [formatter](https://bootstrap-table.com/docs/api/column-options/#formatter).
 
-- **Example:** [Get Data](https://examples.bootstrap-table.com/#methods/getData.html)
+- **Example:** [Get Data](https://examples.bootstrap-table.com/#methods/get-data.html)
 
 ## getHiddenColumns
 
@@ -461,7 +461,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
     -  Scroll to the unit (`px` or `rows (index starts by 0)`)
     Default: `{unit: 'px', value: 0}`
 
-- **Example:** [Scroll To](https://examples.bootstrap-table.com/#methods/scorll-to.html)
+- **Example:** [Scroll To](https://examples.bootstrap-table.com/#methods/scroll-to.html)
 
 ## selectPage
 

+ 2 - 20
site/docs/api/table-options.md

@@ -267,7 +267,7 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Default:** `undefined`
 
-- **Example:** [Custom Order](https://examples.bootstrap-table.com/#options/custom-order.html)
+- **Example:** [Custom Order](https://examples.bootstrap-table.com/#options/custom-sort.html)
 
 ## data
 
@@ -510,22 +510,6 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Table Height](https://examples.bootstrap-table.com/#options/table-height.html)
 
-## html
-
-- **Attribute:** `data-html`
-
-- **Type:** `Object`
-
-- **Detail:**
-
-  Defines some html of the table.
-
-- **Default:**
-
-  Too much code, please checkout the source code of the `index.js`
-
-- **Example:** [Table Html](https://examples.bootstrap-table.com/#options/table-html.html)
-
 ## iconSize
 
 - **Attribute:** `data-icon-size`
@@ -1649,7 +1633,7 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Default:** `undefined`
 
-- **Example:** [getRowByUniqueId](https://examples.bootstrap-table.com/#methods/getRowByUniqueId.html)
+- **Example:** [getRowByUniqueId](https://examples.bootstrap-table.com/#methods/get-row-by-unique-id.html)
 
 ## url
 
@@ -1702,8 +1686,6 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Default:** `undefined`
 
-- **Example:** [Virtual Scroll Item Height](https://examples.bootstrap-table.com/#options/virtual-scroll-item-height.html)
-
 ## visibleSearch
 
 - **Attribute:** `visible-search`

+ 0 - 1
src/constants/index.js

@@ -292,7 +292,6 @@ const DEFAULTS = {
   buttonsPrefix: CONSTANTS.classes.buttonsPrefix,
   buttonsClass: CONSTANTS.classes.buttons,
   icons: CONSTANTS.icons,
-  html: CONSTANTS.html,
   iconSize: undefined,
   iconsPrefix: CONSTANTS.iconsPrefix, // glyphicon or fa(font-awesome)
   loadingFontSize: 'auto',

+ 32 - 2
tools/check-api.js

@@ -4,6 +4,20 @@ const fs = require('fs')
 const chalk = require('chalk')
 const Constants = require('../src/constants/index.js').default
 let errorSum = 0
+const exampleFilesFolder = './bootstrap-table-examples/'
+const exampleFilesFound = fs.existsSync(exampleFilesFolder)
+let exampleFiles = []
+if (exampleFilesFound) {
+  exampleFiles = [
+    ...fs.readdirSync(exampleFilesFolder + 'welcomes'),
+    ...fs.readdirSync(exampleFilesFolder + 'options'),
+    ...fs.readdirSync(exampleFilesFolder + 'column-options'),
+    ...fs.readdirSync(exampleFilesFolder + 'methods')
+  ]
+} else {
+  console.log((chalk.yellow(chalk.bold('Warning: ') + 'Cant check if example files are correct formatted and have a valid url.')))
+  console.log((chalk.yellow(chalk.bold('Warning: ') + 'To enable that check, please clone the "bootstrap-table-examples" repository in the tools folder or create a symlink (if you already cloned the repository on an other path).')))
+}
 
 class API {
   constructor () {
@@ -23,6 +37,7 @@ class API {
     const lines = content.split('## ')
     const outLines = lines.slice(0, 1)
     const errors = []
+    const exampleRegex = /\[.*\]\(.*\/(.*\.html)\)/m
 
     for (const item of lines.slice(1)) {
       md[item.split('\n')[0]] = item
@@ -39,7 +54,21 @@ class API {
           if (this.ignore && this.ignore[key] && this.ignore[key].includes(name)) {
             continue
           }
-          if (!details[i + 1] || details[i + 1].indexOf(`**${name}:**`) === -1) {
+
+          const tmpDetails = details[i + 1].trim()
+          if (name === 'Example' && exampleFilesFound) {
+            const matches = exampleRegex.exec(tmpDetails)
+            if (!matches) {
+              errors.push(chalk.red(`[${key}] missing or wrong formatted example`, `"${tmpDetails}"`))
+              continue
+            }
+
+            if (!exampleFiles.includes(matches[1])) {
+              errors.push(chalk.red(`[${key}] example '${matches[1]}' could not be found`))
+            }
+          }
+
+          if (!tmpDetails || tmpDetails.indexOf(`**${name}:**`) === -1) {
             errors.push(chalk.red(`[${key}] missing '${name}'`))
           }
         }
@@ -72,7 +101,8 @@ class TableOptions extends API {
     this.attributes = ['Attribute', 'Type', 'Detail', 'Default', 'Example']
     this.ignore = {
       totalRows: ['Example'],
-      totalNotFiltered: ['Example']
+      totalNotFiltered: ['Example'],
+      virtualScrollItemHeight: ['Example']
     }
   }
 }