Skip to content

Commit

Permalink
Added language support to Code field
Browse files Browse the repository at this point in the history
  • Loading branch information
rslanzi committed Mar 14, 2021
1 parent 8d7437e commit 4f087a4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactoring
- Tests

## [0.2.1] - 2021-03-14
### Added
- Code language support.

### Changed
- Language link style
- Stripe HTML from index field

## [0.2.0] - 2021-03-14
### Added
- Code field support.
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<a
class="inline-block font-bold cursor-pointer mr-2 animate-text-color select-none"
:class="{ 'text-60': localeKey !== currentLocale, 'text-primary border-b-2': localeKey === currentLocale }"
:class="{ 'text-60': localeKey !== currentLocale, 'text-primary': localeKey === currentLocale }"
:key="`a-${localeKey}`"
v-for="(locale, localeKey) in field.locales"
@click="changeTab(localeKey)"
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template slot="field">
<a
class="inline-block font-bold cursor-pointer mr-2 animate-text-color select-none"
:class="{ 'text-60': localeKey !== currentLocale, 'text-primary border-b-2': localeKey === currentLocale }"
:class="{ 'text-60': localeKey !== currentLocale, 'text-primary': localeKey === currentLocale }"
:key="`a-${localeKey}`"
v-for="(locale, localeKey) in field.locales"
@click="changeTab(localeKey)"
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<span v-html="value"></span>
<span>{{ value | striphtml }}</span>
</template>

<script>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/Slug/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template slot="field">
<a
class="inline-block font-bold cursor-pointer mr-2 animate-text-color select-none"
:class="{ 'text-60': localeKey !== currentLocale, 'text-primary border-b-2': localeKey === currentLocale }"
:class="{ 'text-60': localeKey !== currentLocale, 'text-primary': localeKey === currentLocale }"
:key="`a-${localeKey}`"
v-for="(locale, localeKey) in field.locales"
@click="changeTab(localeKey)"
Expand Down
9 changes: 8 additions & 1 deletion resources/js/field.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Nova.booting((Vue, router, store) => {
Vue.config.devtools = true;
// Vue.config.devtools = true;

Vue.filter('striphtml', function (value) {
var div = document.createElement("div");
div.innerHTML = value;
var text = div.textContent || div.innerText || "";
return text;
});

Vue.component('index-nova-translatable', require('./components/IndexField'))
Vue.component('detail-nova-translatable', require('./components/DetailField'))
Expand Down
15 changes: 15 additions & 0 deletions src/NovaTranslatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ public function code()
return $this->withMeta(['code' => true]);
}

/**
* Define the language syntax highlighting mode for the field.
*
* @param string $language
* @return $this
*/
public function language($language)
{
if ($this->fieldType == 'code') {
return $this->options(['mode' => $language]);
}

return $this;
}

/**
* Use as JSON field.
*/
Expand Down

0 comments on commit 4f087a4

Please sign in to comment.