Skip to content

Commit

Permalink
Added interpunct support to replace hyphens.
Browse files Browse the repository at this point in the history
  • Loading branch information
mudgen committed May 31, 2020
1 parent 1e62ef0 commit 7052e1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
21 changes: 11 additions & 10 deletions docs/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,22 @@ const contentNav =
),
div.class`mt-6 pl-3`(
/* Place this tag where you want the button to render. */
a.class`github-button`.href`https://github.com/mudgen/webscript`
["data-size"]`large`
["data-show-count"]`true`
["aria-label"]`Star Webscript on GitHub``Star`,
a.class`github-button`
.href`https://github.com/mudgen/webscript`
.data·size`large`
.data·show·count`true`
.aria·label`Star Webscript on GitHub``Star`,
div.class`mt-2`(
a.class`github-button`.href`https://github.com/sponsors/mudgen`
["data-size"]`large`
["data-icon"]`octicon-heart`
["ariaLabel"]`Sponsor @ntkme on GitHub``Sponsor`
.data·size`large`
.data·icon`octicon-heart`
.aria·label`Sponsor @mudgen on GitHub``Sponsor`
),
div.class`mt-2`(
a.class`twitter-follow-button`.href`https://twitter.com/mudgen?ref_src=twsrc%5Etfw`
["data-size"]`large`
["data-show-count"]`false`
["data-show-screen-name"]`false`
.data·size`large`
.data·show·count`false`
.data·show·screen·name`false`
`Follow @mudgen`
)
),
Expand Down
4 changes: 3 additions & 1 deletion html2webscript/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ function out(o, indent) {
}
}

let hyphen = new RegExp("-","g");

function camelCase(hyphenText) {
return hyphenText.split("-")
.map((text, index) => {
Expand Down Expand Up @@ -375,7 +377,7 @@ function traverse(element) {
else {
let name = a.name;
if (name.indexOf('-') > -1) {
name = camelCase(name);
name = name.replace(hyphen, "·");
}
o.attrs.push(`.${name}\`${a.value}\``);
}
Expand Down
5 changes: 5 additions & 0 deletions src/webscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function templateValues(args) {
return result;
}

let interpunct = new RegExp("·","g");

function createInitialBuilder(constructor, type) {
function setPropertyValue(...args) {
let [value] = args;
Expand Down Expand Up @@ -73,6 +75,9 @@ function createInitialBuilder(constructor, type) {
return setPropsValues;
}
else if (typeof prop === "string") {
if(prop.indexOf("·") !== -1) {
prop = prop.replace(interpunct, "-");
}
if (prop.endsWith("Value") && prop.length > 5) {
return target.__element_info__.props[prop.slice(0, -5)];
}
Expand Down

0 comments on commit 7052e1e

Please sign in to comment.