Skip to content

Commit

Permalink
Prototyping template tag (wip) (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasnumber authored Jun 1, 2024
1 parent 43cb57e commit dcbd6fb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
File renamed without changes.
11 changes: 11 additions & 0 deletions dist/piq/utils/template-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// src/utils/template-tag.js
var html = (s, ...v) => {
return s.reduce((acc, str, i) => acc + str + (v[i] || ""), "");
};
var css = (s, ...v) => {
return s.reduce((acc, str, i) => acc + str + (v[i] || ""), "");
};
export {
css,
html
};
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<meta charset="UTF-8">
<title></title>
<!-- <script type="module" src="/dist/piq/core/piq.js"></script> -->
<!-- <script type="module" src="/dist/piq/utils/template-tag.js"></script> -->
<script type="module" src="/src/main.js"></script>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
rm -rf dist
mkdir dist

esbuild ./src/core/piq.js --bundle --format=esm --outfile=./dist/piq.dist.js
esbuild ./src/utils/template-tag.js ./src/core/piq.js --bundle --format=esm --outdir=./dist/piq
1 change: 1 addition & 0 deletions src/core/piq.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scopedStyle from '../utils/scoped-style.js';

/* main entry point */
class piq extends HTMLElement {

Expand Down
16 changes: 9 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import piq from '/src/core/piq.js';
// import piq from '../dist/piq.dist.js';
// import piq from '/src/core/piq.js';
// import {html, css} from '/src/utils/template-tag.js';
import piq from '../dist/piq/core/piq.js';
import {html, css} from '../dist/piq/utils/template-tag.js';

// Mock use case
class TheThing extends piq {
Expand All @@ -21,7 +23,7 @@ class TheThing extends piq {
};

style() {
return `
return css`
.child-class {
/*test scope*/
Expand Down Expand Up @@ -51,7 +53,7 @@ class TheThing extends piq {
};

template() {
return `
return html`
<div>===========fisrt level</div>
<well-then type="${this.data('type')}" label="789"></well-then>
<div class="test-name"> ${this.data('type')} </div>
Expand Down Expand Up @@ -86,8 +88,8 @@ class WellThen extends piq {
};

style() {
return `
${this.name()} {
return css`
{
display: block;
border: 1px solid orange;
padding: 1rem;
Expand All @@ -96,7 +98,7 @@ class WellThen extends piq {
};

template() {
return `
return html`
<div>====second level</div>
<div> ${this.data('type')} </div>
<div> ${this.data('label')} </div>
Expand Down
13 changes: 13 additions & 0 deletions src/utils/template-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const html = (s, ...v) => {
return s.reduce((acc, str, i) => acc + str + (v[i] || ''), '');
};

const css = (s, ...v) => {
return s.reduce((acc, str, i) => acc + str + (v[i] || ''), '');
};

export {
html,
css
}

0 comments on commit dcbd6fb

Please sign in to comment.