Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Convert back to render modifiers #375

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Convert back to render modifiers
RobbieTheWagner committed Oct 18, 2021
commit 70ca2f455edf776ef0a71fcbd006b4eb14d3bd1a
3 changes: 2 additions & 1 deletion addon/components/code-inline.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<code
...attributes
class="{{this.languageClass}}"
{{create-ref "codeElement" bucket=this tracked=true}}
{{did-insert this.setPrismCode}}
{{did-update this.setPrismCode this.code @language}}
>
{{~! ~}}{{this.prismCode}}{{~! ~}}
</code>
40 changes: 20 additions & 20 deletions addon/components/code-inline.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/* global Prism */
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { htmlSafe } from '@ember/template';
import { tracked } from '@glimmer/tracking';
import { assert } from '@ember/debug';
import { trackedRef } from 'ember-ref-bucket';

export default class CodeInlineComponent extends Component {
@trackedRef('codeElement') codeElement;
@tracked prismCode = '';

get code() {
const code = this.args.code;

assert(
"ember-prism's <CodeBlock/> and <CodeInline/> components require a `code` parameter to be passed in.",
code !== undefined
);
if (Prism?.plugins?.NormalizeWhitespace) {
return Prism.plugins.NormalizeWhitespace.normalize(code);
}

return code;
}

@@ -27,26 +30,23 @@ export default class CodeInlineComponent extends Component {
return `language-${this.language}`;
}

get prismCode() {
let prismCode = '';

if (this.codeElement) {
const code = this.code;
const language = this.language;
const grammar = Prism.languages[language];

if (code && language && grammar) {
prismCode = htmlSafe(Prism.highlight(code, grammar, language));
}
@action
setPrismCode(element) {
const code = this.code;
const language = this.language;
const grammar = Prism.languages[language];

// Force plugin initialization, required for Prism.highlight usage.
// See https://github.com/PrismJS/prism/issues/1234
Prism.hooks.run('complete', {
code,
element: this.codeElement,
});
if (code && language && grammar) {
this.prismCode = htmlSafe(Prism.highlight(code, grammar, language));
} else {
this.prismCode = '';
}

return prismCode;
// Force plugin initialization, required for Prism.highlight usage.
// See https://github.com/PrismJS/prism/issues/1234
Prism.hooks.run('complete', {
code,
element,
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@
"test:ember-compatibility": "ember try:each"
},
"dependencies": {
"@ember/render-modifiers": "^2.0.0",
"ember-auto-import": "^2.1.0",
"ember-cli-babel": "^7.26.6",
"ember-cli-htmlbars": "^5.7.1",
"ember-cli-node-assets": "^0.2.2",
"ember-ref-bucket": "^3.1.0",
"prismjs": "^1.22.0",
"prismjs-glimmer": "^1.1.1"
},
91 changes: 16 additions & 75 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@
browserslist "^4.16.6"
semver "^6.3.0"

"@babel/helper-create-class-features-plugin@^7.14.5", "@babel/helper-create-class-features-plugin@^7.15.0", "@babel/helper-create-class-features-plugin@^7.5.5", "@babel/helper-create-class-features-plugin@^7.8.3":
"@babel/helper-create-class-features-plugin@^7.14.5", "@babel/helper-create-class-features-plugin@^7.15.0", "@babel/helper-create-class-features-plugin@^7.5.5":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.15.0.tgz#c9a137a4d137b2d0e2c649acf536d7ba1a76c0f7"
integrity sha512-MdmDXgvTIi4heDVX/e9EFfeGpugqm9fobBVg/iioE8kueXrOHdRDe36FAY7SnE9xXLVeYCoJR/gdrBEIHRC83Q==
@@ -339,7 +339,7 @@
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/plugin-syntax-logical-assignment-operators" "^7.10.4"

"@babel/plugin-proposal-nullish-coalescing-operator@^7.14.5", "@babel/plugin-proposal-nullish-coalescing-operator@^7.4.4":
"@babel/plugin-proposal-nullish-coalescing-operator@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.14.5.tgz#ee38589ce00e2cc59b299ec3ea406fcd3a0fdaf6"
integrity sha512-gun/SOnMqjSb98Nkaq2rTKMwervfdAoz6NphdY0vTfuzMfryj+tDGb2n6UkDKwez+Y8PZDhE3D143v6Gepp4Hg==
@@ -374,7 +374,7 @@
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/plugin-syntax-optional-catch-binding" "^7.8.3"

"@babel/plugin-proposal-optional-chaining@^7.14.5", "@babel/plugin-proposal-optional-chaining@^7.6.0":
"@babel/plugin-proposal-optional-chaining@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.14.5.tgz#fa83651e60a360e3f13797eef00b8d519695b603"
integrity sha512-ycz+VOzo2UbWNI1rQXxIuMOzrDdHGrI23fRiz/Si2R4kv2XZQ1BK8ccdHwehMKBlcH/joGW/tzrUmo67gbJHlQ==
@@ -514,7 +514,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.14.5"

"@babel/plugin-syntax-typescript@^7.14.5", "@babel/plugin-syntax-typescript@^7.2.0", "@babel/plugin-syntax-typescript@^7.8.3":
"@babel/plugin-syntax-typescript@^7.14.5", "@babel/plugin-syntax-typescript@^7.2.0":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.14.5.tgz#b82c6ce471b165b5ce420cf92914d6fb46225716"
integrity sha512-u6OXzDaIXjEstBRRoBCQ/uKQKlbuaeE5in0RvWdA4pN6AhqxTIwUsnHPU1CFZA/amYObMsuWhYfRl3Ch90HD0Q==
@@ -799,15 +799,6 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-typescript" "^7.2.0"

"@babel/plugin-transform-typescript@~7.8.0":
version "7.8.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.8.7.tgz#48bccff331108a7b3a28c3a4adc89e036dc3efda"
integrity sha512-7O0UsPQVNKqpHeHLpfvOG4uXmlw+MOxYvUv6Otc9uH5SYMIxvF6eBdjkWvC3f9G+VXe0RsNExyAQBeTRug/wqQ==
dependencies:
"@babel/helper-create-class-features-plugin" "^7.8.3"
"@babel/helper-plugin-utils" "^7.8.3"
"@babel/plugin-syntax-typescript" "^7.8.3"

"@babel/plugin-transform-unicode-escapes@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.14.5.tgz#9d4bd2a681e3c5d7acf4f57fa9e51175d91d0c6b"
@@ -1007,6 +998,15 @@
mkdirp "^1.0.4"
silent-error "^1.1.1"

"@ember/render-modifiers@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@ember/render-modifiers/-/render-modifiers-2.0.0.tgz#7106928078c6463bc6ee3cbffb6d71dbb8602145"
integrity sha512-FbvowKEnYx102MaNMrePBC7RCmuf3BaqPKbp6QP7S6oJaDMuLrGblXW4TxOrE93C6II+6D4QNB4WFGuPeQ3ZBg==
dependencies:
ember-cli-babel "^7.26.6"
ember-compatibility-helpers "^1.2.5"
ember-modifier-manager-polyfill "^1.2.0"

"@ember/test-helpers@^2.2.5":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@ember/test-helpers/-/test-helpers-2.5.0.tgz#1503e4fdf12451d591e41f69d0b2c1db8a431017"
@@ -4777,7 +4777,7 @@ ember-cli-get-component-path-option@^1.0.0:
resolved "https://registry.yarnpkg.com/ember-cli-get-component-path-option/-/ember-cli-get-component-path-option-1.0.0.tgz#0d7b595559e2f9050abed804f1d8eff1b08bc771"
integrity sha1-DXtZVVni+QUKvtgE8djv8bCLx3E=

ember-cli-htmlbars@^5.3.1, ember-cli-htmlbars@^5.7.1:
ember-cli-htmlbars@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-5.7.1.tgz#eb5b88c7d9083bc27665fb5447a9b7503b32ce4f"
integrity sha512-9laCgL4tSy48orNoQgQKEHp93MaqAs9ZOl7or5q+8iyGGJHW6sVXIYrVv5/5O9HfV6Ts8/pW1rSoaeKyLUE+oA==
@@ -4912,26 +4912,6 @@ ember-cli-typescript@^2.0.2:
stagehand "^1.0.0"
walk-sync "^1.0.0"

ember-cli-typescript@^3.1.3:
version "3.1.4"
resolved "https://registry.yarnpkg.com/ember-cli-typescript/-/ember-cli-typescript-3.1.4.tgz#21d6ccd670d1f2e34c9cce68c6e32c442f46806b"
integrity sha512-HJ73kL45OGRmIkPhBNFt31I1SGUvdZND+LCH21+qpq3pPlFpJG8GORyXpP+2ze8PbnITNLzwe5AwUrpyuRswdQ==
dependencies:
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.4.4"
"@babel/plugin-proposal-optional-chaining" "^7.6.0"
"@babel/plugin-transform-typescript" "~7.8.0"
ansi-to-html "^0.6.6"
broccoli-stew "^3.0.0"
debug "^4.0.0"
ember-cli-babel-plugin-helpers "^1.0.0"
execa "^3.0.0"
fs-extra "^8.0.0"
resolve "^1.5.0"
rsvp "^4.8.1"
semver "^6.3.0"
stagehand "^1.0.0"
walk-sync "^2.0.0"

ember-cli-version-checker@^2.1.2:
version "2.2.0"
resolved "https://registry.yarnpkg.com/ember-cli-version-checker/-/ember-cli-version-checker-2.2.0.tgz#47771b731fe0962705e27c8199a9e3825709f3b3"
@@ -5063,7 +5043,7 @@ ember-cli@~3.27.0:
workerpool "^6.0.3"
yam "^1.0.0"

ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.0, ember-compatibility-helpers@^1.2.1, ember-compatibility-helpers@^1.2.4:
ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.0, ember-compatibility-helpers@^1.2.1, ember-compatibility-helpers@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/ember-compatibility-helpers/-/ember-compatibility-helpers-1.2.5.tgz#b8363b1d5b8725afa9a4fe2b2986ac28626c6f23"
integrity sha512-7cddkQQp8Rs2Mqrj0xqZ0uO7eC9tBCKyZNcP2iE1RxQqOGPv8fiPkj1TUeidUB/Qe80lstoVXWMEuqqhW7Yy9A==
@@ -5073,7 +5053,7 @@ ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.0, ember-co
fs-extra "^9.1.0"
semver "^5.4.1"

ember-destroyable-polyfill@^2.0.2, ember-destroyable-polyfill@^2.0.3:
ember-destroyable-polyfill@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/ember-destroyable-polyfill/-/ember-destroyable-polyfill-2.0.3.tgz#1673ed66609a82268ef270a7d917ebd3647f11e1"
integrity sha512-TovtNqCumzyAiW0/OisSkkVK93xnVF4NRU6+FN0ubpfwEOpRrmM2RqDwXI6YAChCgSHON1cz0DfQStpA1Gjuuw==
@@ -5119,19 +5099,6 @@ ember-modifier-manager-polyfill@^1.2.0:
ember-cli-version-checker "^2.1.2"
ember-compatibility-helpers "^1.2.0"

ember-modifier@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ember-modifier/-/ember-modifier-2.1.2.tgz#62d18faedf972dcd9d34f90d5321fbc943d139b1"
integrity sha512-3Lsu1fV1sIGa66HOW07RZc6EHISwKt5VA5AUnFss2HX6OTfpxTJ2qvPctt2Yt0XPQXJ4G6BQasr/F35CX7UGJA==
dependencies:
ember-cli-babel "^7.22.1"
ember-cli-normalize-entity-name "^1.0.0"
ember-cli-string-utils "^1.1.0"
ember-cli-typescript "^3.1.3"
ember-compatibility-helpers "^1.2.4"
ember-destroyable-polyfill "^2.0.2"
ember-modifier-manager-polyfill "^1.2.0"

ember-page-title@^6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/ember-page-title/-/ember-page-title-6.2.2.tgz#980838c44e96cba1d00f42435d707936af627324"
@@ -5154,16 +5121,6 @@ ember-qunit@^5.1.4:
silent-error "^1.1.1"
validate-peer-dependencies "^1.2.0"

ember-ref-bucket@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ember-ref-bucket/-/ember-ref-bucket-3.1.0.tgz#c3aa3923bdedcf782923bf24e31a17fdd2f68a02"
integrity sha512-oO+Igh8G1UHcf7gEJdbElz/xJHjTds64DXfd+c189rHuKJ4dYMI2m2BkHPermeyUe6ZNEFwlkVe9lYm2rvmcaw==
dependencies:
ember-cli-babel "^7.22.1"
ember-cli-htmlbars "^5.3.1"
ember-destroyable-polyfill "^2.0.2"
ember-modifier "^2.1.1"

ember-resolver@^8.0.2:
version "8.0.3"
resolved "https://registry.yarnpkg.com/ember-resolver/-/ember-resolver-8.0.3.tgz#40f243aa58281bf195c695fe84a6b291e204690a"
@@ -5794,22 +5751,6 @@ execa@^2.0.0:
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"

execa@^3.0.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-3.4.0.tgz#c08ed4550ef65d858fac269ffc8572446f37eb89"
integrity sha512-r9vdGQk4bmCuK1yKQu1KTwcT2zwfWdbdaXfCtAh+5nU/4fSX+JAb7vZGvI5naJrQlvONrEB20jeruESI69530g==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
human-signals "^1.1.1"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.0"
onetime "^5.1.0"
p-finally "^2.0.0"
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"

execa@^4.0.2, execa@^4.0.3:
version "4.1.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"