Skip to content

Commit 370423a

Browse files
committed
add css, make fretboardSVG.js to separate svg files
Signed-off-by: Ca Chen <[email protected]>
1 parent 2ea3e59 commit 370423a

23 files changed

+331
-384
lines changed

package-lock.json

Lines changed: 17 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vendor/fretboard/css/i.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vendor/fretboard/fretboard.js

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
import {
2-
dotEmpty,
3-
dotEmpty_h,
4-
dot,
5-
dot_h,
6-
dotWideLeft,
7-
dotWideRight,
8-
dotWideMiddle,
9-
string_o,
10-
string_x,
11-
fretb_vert_4,
12-
fretb_vert_5,
13-
fretb_vert_7,
14-
fretb_vert_9,
15-
fretb_vert_12,
16-
fretb_vert_15,
17-
fretb_horiz_5,
18-
fretb_horiz_6,
19-
fretb_horiz_7,
20-
} from './fretboardSVG.js'
1+
import dotEmpty from './svg/dotEmpty.svg'
2+
import dotEmpty_h from './svg/dotEmpty_h.svg'
3+
import dot from './svg/dot.svg'
4+
import dot_h from './svg/dot_h.svg'
5+
import dotWideLeft from './svg/dotWideLeft.svg'
6+
import dotWideRight from './svg/dotWideRight.svg'
7+
import dotWideMiddle from './svg/dotWideMiddle.svg'
8+
import string_o from './svg/string_o.svg'
9+
import string_x from './svg/string_x.svg'
10+
import './css/i.css'
2111

2212
const switchList_v = {
2313
'o': `<div class='cell dot'>${dot}</div>`,
@@ -38,68 +28,51 @@ const switchList_h = {
3828
' ': `<div class='cell empty'>${dotEmpty_h}</div>`
3929
}
4030

41-
export const renderFretBoard = (content) => {
31+
let getArgument = (argName, content) => {
32+
let lineOfContent = content.data.split('\n')
4233

43-
let fretboardHTML = $('<div class="fretboard_instance"></div>')
44-
if (content.includes('title:')) {
45-
const getTitle = content.split('\n', 1)[0].split('title:')[1].trim()
46-
$(fretboardHTML).append($(`<div class="title">${getTitle}</div>`))
47-
content = content.split('\n').slice(1).join('\n')
34+
let argv = ''
35+
let indexOfArg = ''
36+
let idx = ''
37+
for (idx in lineOfContent) {
38+
if (lineOfContent[idx].startsWith(argName)) {
39+
argv = lineOfContent[idx].split(argName)[1].trim()
40+
break
41+
}
4842
}
4943

50-
let fretType = ''
51-
if (content.startsWith('type:')) {
52-
fretType = content.split('\n', 1)[0].split('type:')[1].trim().split(' ')
53-
content = content.split('\n').slice(1).join('\n')
54-
}
44+
lineOfContent.splice(idx, 1)
45+
content.data = lineOfContent.join('\n')
5546

56-
let fretb_orientation = fretType[0].startsWith('v') ? 'vert' : 'horiz'
57-
let fretb_len = fretType[0].substring(1)
47+
return argv
48+
}
5849

59-
// TODO: to get svg dynamically
60-
let fretb_bg = ''
61-
switch (fretb_len) {
62-
case '4':
63-
fretb_bg = fretb_vert_4
64-
break
65-
case '5':
66-
if (fretb_orientation === 'vert')
67-
fretb_bg = fretb_vert_5
68-
else
69-
fretb_bg = fretb_horiz_5
70-
break
71-
case '6':
72-
fretb_bg = fretb_horiz_6
73-
break
74-
case '7':
75-
if (fretb_orientation === 'vert')
76-
fretb_bg = fretb_vert_7
77-
else
78-
fretb_bg = fretb_horiz_7
79-
break
80-
case '9':
81-
fretb_bg = fretb_vert_9
82-
break
83-
case '12':
84-
fretb_bg = fretb_vert_12
85-
break
86-
case '15':
87-
fretb_bg = fretb_vert_15
88-
break
89-
}
50+
export const renderFretBoard = (data) => {
51+
let fretboardHTML = $('<div class="fretboard_instance"></div>')
52+
53+
// parsing arguments
54+
let content = { 'data': data }
55+
let getTitle = getArgument('title:', content)
56+
let fretType = getArgument('type:', content).split(' ')
57+
content = content.data
58+
59+
$(fretboardHTML).append($(`<div class="title">${getTitle}</div>`))
9060

9161
// create fretboard background HTML
92-
let fretb_class = fretType[0][0] + ' ' + fretType[0]
62+
let fretb_orientation = fretType && fretType[0].startsWith('v') ? 'vert' : 'horiz'
63+
let fretb_len = fretType && fretType[0].substring(1)
64+
let fretb_class = fretType && fretType[0][0] + ' ' + fretType[0]
9365
let nut = (fretType[1] && fretType[1] === 'noNut')?'noNut':''
9466
let svgHTML = $(`<div class="svg_wrapper ${fretb_class} ${nut}"></div>`)
67+
let fretb_bg = require(`./svg/fretb_${fretb_orientation}_${fretb_len}.svg`)
9568
$(svgHTML).append($(fretb_bg))
9669

9770
// create cells HTML
9871
let cellsHTML = $('<div class="cells"></div>')
99-
let switchList = fretb_orientation === 'vert' ? switchList_v : switchList_h
100-
let contentCell = content.split('')
72+
let switchList = fretb_orientation && fretb_orientation === 'vert' ? switchList_v : switchList_h
73+
let contentCell = content && content.split('')
10174
// Go through each ASCII character...
102-
contentCell.forEach(char => {
75+
contentCell && contentCell.forEach(char => {
10376
if (switchList[char] !== undefined) {
10477
cellsHTML.append($(switchList[char]));
10578
}

0 commit comments

Comments
 (0)