Skip to content

Commit

Permalink
Remove rules.mk and rename info.json -> keyboard.json
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark committed Jun 20, 2024
1 parent 96bec53 commit 30525e0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 49 deletions.
12 changes: 5 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<script setup>
import { ref } from 'vue'
import { kbfInfoJson, kbfKeymapC } from '@/kbf-parse'
import { kbfKeyboardJson, kbfKeymapC } from '@/kbf-parse'
import InputCard from '@/components/InputCard.vue'
import OutputCard from '@/components/OutputCard.vue'
const zipFilename = ref('keyboard')
const info = ref(null)
const keyboard = ref(null)
const keymap = ref(null)
const rules = ref('# This file intentionally left blank\n')
function parseKbf(filename, o) {
zipFilename.value = filename.substring(0, filename.lastIndexOf('.'))
info.value = kbfInfoJson(o.keyboard)
keyboard.value = kbfKeyboardJson(o.keyboard)
keymap.value = kbfKeymapC(o.keyboard)
}
</script>
Expand All @@ -26,11 +25,10 @@ function parseKbf(filename, o) {
<div class="container mt-3">
<InputCard @loaded-kbf="parseKbf" />
<OutputCard
v-if="info != null"
v-if="keyboard != null"
:zip-filename="zipFilename"
:info="info"
:keyboard="keyboard"
:keymap="keymap"
:rules="rules"
/>
<footer class="text-muted mb-5">
<hr />
Expand Down
41 changes: 11 additions & 30 deletions src/components/OutputCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@ const props = defineProps({
type: String,
required: true
},
info: {
keyboard: {
type: Object,
required: true
},
keymap: {
type: String,
required: true
},
rules: {
type: String,
required: true
}
})
const prettyInfo = computed(() => {
if (props.info) {
const prettyKeyboard = computed(() => {
if (props.keyboard) {
return (
JSON.stringify(props.info, null, ' ')
JSON.stringify(props.keyboard, null, ' ')
// Place layout keys on a single line
.replace(/\n {20,}/g, ' ')
.replace(/\n {16,}\}/g, ' }')
Expand All @@ -50,8 +46,7 @@ const prettyInfo = computed(() => {
async function downloadZip() {
const zip = new JSZip()
zip.file('info.json', prettyInfo.value)
zip.file('rules.mk', props.rules)
zip.file('keyboard.json', prettyKeyboard.value)
zip.folder('keymaps').folder('default').file('keymap.c', props.keymap)
const content = await zip.generateAsync({
Expand All @@ -68,18 +63,18 @@ async function downloadZip() {
<ul class="nav nav-tabs mb-3">
<li class="nav-item">
<button
id="tab-info"
id="tab-keyboard"
class="nav-link text-end active"
type="button"
data-bs-toggle="tab"
data-bs-target="#tab-pane-info"
data-bs-target="#tab-pane-keyboard"
>
info.json
keyboard.json
</button>
</li>
<li class="nav-item">
<button
id="tab-info"
id="tab-keymap"
class="nav-link text-end"
type="button"
data-bs-toggle="tab"
Expand All @@ -88,32 +83,18 @@ async function downloadZip() {
keymap.c
</button>
</li>
<li class="nav-item">
<button
id="tab-info"
class="nav-link text-end"
type="button"
data-bs-toggle="tab"
data-bs-target="#tab-pane-rules"
>
rules.mk
</button>
</li>
<li class="nav-item ms-auto">
<button class="btn btn-sm btn-outline-success" @click="downloadZip">Download ZIP</button>
</li>
</ul>
</div>
<div class="tab-content">
<div id="tab-pane-info" class="tab-pane fade show active">
<CodeView language="json" :code="prettyInfo" />
<div id="tab-pane-keyboard" class="tab-pane fade show active">
<CodeView language="json" :code="prettyKeyboard" />
</div>
<div id="tab-pane-keymap" class="tab-pane fade">
<CodeView language="cpp" :code="keymap" />
</div>
<div id="tab-pane-rules" class="tab-pane fade">
<CodeView language="makefile" :code="rules" />
</div>
</div>
</div>
</template>
20 changes: 10 additions & 10 deletions src/kbf-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ function parseLayout(o) {
})
}

function kbfInfoJson(o) {
let infoJson = {
function kbfKeyboardJson(o) {
let keyboardJson = {
keyboard_name: o.settings.name,
manufacturer: '',
url: '',
Expand All @@ -413,27 +413,27 @@ function kbfInfoJson(o) {
}

if (o.pins.led) {
infoJson.backlight = parseBacklight(o)
keyboardJson.backlight = parseBacklight(o)
}

if (o.pins.rgb) {
infoJson.rgblight = parseRGBlight(o)
infoJson.ws2812 = parseWS2812(o)
keyboardJson.rgblight = parseRGBlight(o)
keyboardJson.ws2812 = parseWS2812(o)
}

if (o.pins.caps || o.pins.num || o.pins.scroll) {
infoJson.indicators = parseIndicators(o)
keyboardJson.indicators = parseIndicators(o)
}

infoJson.layouts = {
keyboardJson.layouts = {
LAYOUT: {
layout: parseLayout(o)
}
}

infoJson.meta = 'https://noroadsleft.github.io/kbf_qmk_converter/'
keyboardJson.meta = 'https://noroadsleft.github.io/kbf_qmk_converter/'

return infoJson
return keyboardJson
}

function parseSimpleLayerKey(key) {
Expand Down Expand Up @@ -656,4 +656,4 @@ ${layers.join(',\n')}
`
}

export { kbfInfoJson, kbfKeymapC }
export { kbfKeyboardJson, kbfKeymapC }
2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import 'bootstrap/dist/css/bootstrap.min.css'
import hljs from 'highlight.js/lib/core'
import cpp from 'highlight.js/lib/languages/cpp'
import json from 'highlight.js/lib/languages/json'
import makefile from 'highlight.js/lib/languages/makefile'

import 'highlight.js/styles/stackoverflow-light.css'

import hljsVuePlugin from '@highlightjs/vue-plugin'

hljs.registerLanguage('cpp', cpp)
hljs.registerLanguage('json', json)
hljs.registerLanguage('makefile', makefile)

createApp(App).use(hljsVuePlugin).mount('#app')

0 comments on commit 30525e0

Please sign in to comment.