Home Reference Source Test

source/template.js

  1. import { prettify } from '@tech_query/node-toolkit';
  2.  
  3. import { identifierOf } from './utility';
  4.  
  5.  
  6. /**
  7. * @private
  8. *
  9. * @return {String}
  10. */
  11. export function index_html() {
  12.  
  13. return `<template>
  14. <style>
  15. h1 {
  16. color: lightblue;
  17. }
  18. </style>
  19.  
  20. <h1>Hello, WebCell !</h1>
  21. </template>`;
  22. }
  23.  
  24.  
  25. /**
  26. * @private
  27. *
  28. * @param {String} name
  29. * @param {String[]} [keys=[]]
  30. *
  31. * @return {String}
  32. */
  33. export function index_js(name, keys = [ ]) {
  34.  
  35. return prettify(`
  36. import { component${keys[0] ? ', mapProperty, mapData' : ''} } from 'web-cell';
  37.  
  38. import template from './index.html';
  39.  
  40.  
  41. @component({ template })
  42. export default class ${identifierOf(name, true)} extends HTMLElement {
  43.  
  44. constructor() { super().construct(); }
  45. ${
  46. keys[0] ? `
  47. @mapProperty
  48. static get observedAttributes() {
  49.  
  50. return ${JSON.stringify( keys )};
  51. }
  52.  
  53. @mapData
  54. attributeChangedCallback() { }` : ''}
  55. }`);
  56. }
  57.  
  58.  
  59. /**
  60. * @private
  61. *
  62. * @param {String} name
  63. * @param {String[]} page
  64. *
  65. * @return {String}
  66. */
  67. export function router_js(name, page) {
  68.  
  69. return prettify(`import { component } from 'web-cell';
  70.  
  71. import HTMLRouter, { load } from 'cell-router';
  72.  
  73.  
  74. @component()
  75. export default class ${identifierOf(name, true)}Router extends HTMLRouter {
  76. ${page.map(name => {
  77.  
  78. name = name.toLowerCase();
  79.  
  80. return `
  81. @load('/${name}')
  82. ${name}Page() { return '<page-${name} />'; }
  83. `;}).join('\n')}
  84. }`);
  85. }