Completed
Push — master ( 273a12...880c09 )
by
unknown
02:14
created

src/cli/cms/templates/encodeAbeTagAsComment.js   A

Complexity

Total Complexity 7
Complexity/F 7

Size

Lines of Code 37
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
c 1
b 0
f 0
nc 1
mnd 3
bc 6
fnc 1
dl 0
loc 37
rs 10
bpm 6
cpm 7
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
C encodeAbeTagAsComment.js ➔ encodeAbeTagAsComment 0 28 7
1
import {
2
  cmsData
3
} from '../../'
4
5
/**
6
 * Encode / Escape && add data-abe attributs
7
 * @param  {String} block
8
 * @return {String} escaped string
9
 */
10
export default function encodeAbeTagAsComment(block){
11
  var matchAbe = block.match(/>\s*\{\{abe .*\}\}/g)
12
  if(matchAbe){
13
    for (var i = 0; i < matchAbe.length; i++){
14
      var getattr = cmsData.regex.getAttr(matchAbe[i], 'key').replace('.', '[0]-')
15
      block = block.replace(
16
        matchAbe[i],
17
        ' data-abe-' + cmsData.regex.validDataAbe(getattr) + '="'  + getattr + '" >'
18
      )
19
    }
20
  }
21
  matchAbe = block.match(/( [A-Za-z0-9\-\_]+="*{{.*?}})/g)
22
  if(matchAbe){
23
    for (var i = 0; i < matchAbe.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 13. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
24
      if(typeof matchAbe !== 'undefined' && matchAbe !== null){
25
        var getattr = cmsData.regex.getAttr(matchAbe[i], 'key').replace('.', '[0]-')
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable getattr already seems to be declared on line 14. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
26
        var matchattr = (matchAbe[i].split('=')[0]).trim()
27
        block = block.replace(
28
            matchAbe[i],
29
            ' data-abe-attr-' + cmsData.regex.validDataAbe(getattr) + '="'  + matchattr + '"' +
30
            ' data-abe-' + cmsData.regex.validDataAbe(getattr) + '="'  + getattr + '" ' + matchAbe[i]
31
          )
32
          .replace(/\{\{\abe.*?}\}/, '')
33
      }
34
    }
35
  }
36
  return escape(block)
37
}