logo

Grimgrains

Unnamed repository; edit this file 'description' to name the repository.
commit: 578ec2d981acf92313bb275d9af2575abdf29068
parent eeb430ed25cb24d17b707df0b65aacc91a7fe9cb
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 28 Nov 2019 09:22:51 -0500

Made name clickable

Diffstat:

Mlinks/main.css12++++++------
Mscripts/graph.js2+-
Mscripts/lib/riven.graph.js64++++++++++++++++++++++++++++++++--------------------------------
Mscripts/lib/riven.js36++++++++++++++++++------------------
Mscripts/lib/runic.js38+++++++++++++++++++-------------------
Mscripts/nodes/document.js2++
Mscripts/nodes/dom.js2++
Mscripts/nodes/indental.js20+++++++++++---------
Mscripts/nodes/query.js12+++++++-----
Mscripts/nodes/router.js12+++++++-----
Mscripts/nodes/template.js6++++--
Mscripts/templates/home.js42++++++++++++++++++++++--------------------
Mscripts/templates/ingredient.js106++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mscripts/templates/page.js4+++-
Mscripts/templates/recipe.js62++++++++++++++++++++++++++++++++------------------------------
Mscripts/templates/search.js8+++++---
Mscripts/templates/service.js74++++++++++++++++++++++++++++++++++++++------------------------------------
17 files changed, 263 insertions(+), 239 deletions(-)

diff --git a/links/main.css b/links/main.css @@ -71,11 +71,11 @@ h1,h2,h3,h4 { font-weight: normal; font-family: 'alte_haas_grotesk_bold'; margin #view #core #content ul.ingredients { display: inline-block; margin-right:15px; font-size:0; padding-left:20px; margin-bottom:30px; } #view #core #content ul.ingredients h3 { margin-left:-20px; } #view #core #content ul.ingredients li.ingredient { width: 100px;margin-left:-20px;min-height: 210px;display: inline-block;text-align: center;vertical-align: top;border: 2px dashed transparent;border-radius: 10px; } -#view #core #content ul.ingredients li.ingredient:hover t.name { text-decoration: underline; } -#view #core #content ul.ingredients li.ingredient.missing t.name { font-style: italic } +#view #core #content ul.ingredients li.ingredient:hover span.name { text-decoration: underline; } +#view #core #content ul.ingredients li.ingredient.missing span.name { font-style: italic } #view #core #content ul.ingredients li.ingredient img { max-width: 100%; display: block } -#view #core #content ul.ingredients li.ingredient t.name { display: block; font-family: 'alte_haas_grotesk_bold'; font-size:14px; margin-bottom: 5px;padding:0px 10px } -#view #core #content ul.ingredients li.ingredient t.quantity { display: block; font-size:12px; } +#view #core #content ul.ingredients li.ingredient span.name { display: block; font-family: 'alte_haas_grotesk_bold'; font-size:14px; margin-bottom: 5px;padding:0px 10px } +#view #core #content ul.ingredients li.ingredient span.quantity { display: block; font-size:12px; } #view #core #content .page ul { margin:0px 0px 30px;} #view #core #content .page ul li { line-height: 24px; position: relative; padding-left:15px;} @@ -86,8 +86,8 @@ h1,h2,h3,h4 { font-weight: normal; font-family: 'alte_haas_grotesk_bold'; margin #view #core #related li { width: calc((100% / 3) - 10px); float:left; overflow: hidden;} #view #core #related li:nth-child(1), #view #core #related li:nth-child(2) { margin-right:15px;} #view #core #related li a.photo { border-radius: 2px; display: block; height:160px; background-size:cover; margin-bottom:15px; background-position: center } -#view #core #related li t.name { display: block; font-family: 'alte_haas_grotesk_bold'; font-size:16px; margin-bottom: 5px; text-transform: capitalize; line-height: 30px } -#view #core #related li t.details { display: block; font-family: 'alte_haas_grotesk_regular'; font-size:14px; text-transform: capitalize; line-height: 30px; line-height: 18px } +#view #core #related li span.name { display: block; font-family: 'alte_haas_grotesk_bold'; font-size:16px; margin-bottom: 5px; text-transform: capitalize; line-height: 30px } +#view #core #related li span.details { display: block; font-family: 'alte_haas_grotesk_regular'; font-size:14px; text-transform: capitalize; line-height: 30px; line-height: 18px } #view #core #content #recipes { columns:3; font-size:14px; font-weight: bold} #view #core #content #recipes li { display: block } diff --git a/scripts/graph.js b/scripts/graph.js @@ -37,7 +37,7 @@ function graph () { Ø('core').create({ x: 10, y: 11 }, DomNode), Ø('content').create({ x: 10, y: 16 }, DomNode), Ø('related').create({ x: 14, y: 16 }, DomNode, 'ul'), - Ø('footer').create({ x: 6, y: 11 }, DomNode, 'wr', `<a onclick="Ø('query').bang('about')">Grimgrains</a> © 2014—2019<br/><a href='http://100r.co/' target='_blank'>Hundred Rabbits</a>`) + Ø('footer').create({ x: 6, y: 11 }, DomNode, 'wr', '<a onclick="Ø(\'query\').bang(\'about\')">Grimgrains</a> © 2014—2019<br/><a href=\'http://100r.co/\' target=\'_blank\'>Hundred Rabbits</a>') ]) // Model diff --git a/scripts/lib/riven.graph.js b/scripts/lib/riven.graph.js @@ -1,7 +1,7 @@ function Riven_Graph () { Riven.call(this) - let GRID_SIZE = 20 + const GRID_SIZE = 20 this.el = document.createElementNS('http://www.w3.org/2000/svg', 'svg') document.body.appendChild(this.el) @@ -9,11 +9,11 @@ function Riven_Graph () { this.graph = function () { let html = '' for (id in this.network) { - let node = this.network[id] + const node = this.network[id] html += draw_routes(node) } for (id in this.network) { - let node = this.network[id] + const node = this.network[id] html += draw_node(node) } this.el.innerHTML = html @@ -22,10 +22,10 @@ function Riven_Graph () { function draw_routes (node) { let html = '' for (id in node.ports) { - let port = node.ports[id] - let pos = port ? get_port_position(port) : { x: 0, y: 0 } + const port = node.ports[id] + const pos = port ? get_port_position(port) : { x: 0, y: 0 } for (route_id in port.routes) { - let route = port.routes[route_id] + const route = port.routes[route_id] if (!route) { continue } html += route ? draw_connection(port, route) : '' } @@ -34,7 +34,7 @@ function Riven_Graph () { } function draw_node (node) { - let rect = get_rect(node) + const rect = get_rect(node) return ` <g class='node ${node.is_mesh ? 'mesh' : ''}' id='node_${node.id}'> @@ -54,12 +54,12 @@ function Riven_Graph () { } function draw_glyph (node) { - let rect = get_rect(node) + const rect = get_rect(node) return !node.is_mesh && node.glyph ? `<path class='glyph' transform="translate(${rect.x + (GRID_SIZE / 4)},${rect.y - (GRID_SIZE / 4)}) scale(0.1)" d='${node.glyph}'/>` : '' } function draw_port (port) { - let pos = port ? get_port_position(port) : { x: 0, y: 0 } + const pos = port ? get_port_position(port) : { x: 0, y: 0 } return `<g id='${port.host.id}_port_${port.id}'>${(port.type == PORT_TYPES.request || port.type == PORT_TYPES.answer) ? `<path d='${draw_diamond(pos)}' class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? 'route' : ''}' />` : `<circle cx='${pos.x}' cy="${pos.y}" r="${parseInt(GRID_SIZE / 6)}" class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? 'route' : ''}'/>`}</g>` } @@ -73,9 +73,9 @@ function Riven_Graph () { function is_bidirectional (a, b) { for (id in a.ports.output.routes) { - let route_a = a.ports.output.routes[id] + const route_a = a.ports.output.routes[id] for (id in a.ports.request.routes) { - let route_b = a.ports.request.routes[id] + const route_b = a.ports.request.routes[id] if (route_a.host.id == route_b.host.id) { return true } @@ -85,11 +85,11 @@ function Riven_Graph () { } function draw_connection_output (a, b) { - let pos_a = get_port_position(a) - let pos_b = get_port_position(b) - let pos_m = middle(pos_a, pos_b) - let pos_c1 = { x: (pos_m.x + (pos_a.x + GRID_SIZE)) / 2, y: pos_a.y } - let pos_c2 = { x: (pos_m.x + (pos_b.x - GRID_SIZE)) / 2, y: pos_b.y } + const pos_a = get_port_position(a) + const pos_b = get_port_position(b) + const pos_m = middle(pos_a, pos_b) + const pos_c1 = { x: (pos_m.x + (pos_a.x + GRID_SIZE)) / 2, y: pos_a.y } + const pos_c2 = { x: (pos_m.x + (pos_b.x - GRID_SIZE)) / 2, y: pos_b.y } let path = '' @@ -103,11 +103,11 @@ function Riven_Graph () { } function draw_connection_request (a, b) { - let pos_a = get_port_position(a) - let pos_b = get_port_position(b) - let pos_m = middle(pos_a, pos_b) - let pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } - let pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } + const pos_a = get_port_position(a) + const pos_b = get_port_position(b) + const pos_m = middle(pos_a, pos_b) + const pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } + const pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } let path = '' @@ -121,11 +121,11 @@ function Riven_Graph () { } function draw_connection_bidirectional (a, b) { - let pos_a = get_port_position(a) - let pos_b = get_port_position(b) - let pos_m = middle(pos_a, pos_b) - let pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } - let pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } + const pos_a = get_port_position(a) + const pos_b = get_port_position(b) + const pos_m = middle(pos_a, pos_b) + const pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 } + const pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 } let path = '' @@ -137,12 +137,12 @@ function Riven_Graph () { } function draw_diamond (pos) { - let r = GRID_SIZE / 6 + const r = GRID_SIZE / 6 return `M${pos.x - (r)},${pos.y} L${pos.x},${pos.y - (r)} L${pos.x + (r)},${pos.y} L${pos.x},${pos.y + (r)} Z` } function get_port_position (port) { - let rect = get_rect(port.host) + const rect = get_rect(port.host) let offset = { x: 0, y: 0 } if (port.type == PORT_TYPES.output) { offset = { x: GRID_SIZE * 2, y: GRID_SIZE / 2 } @@ -157,14 +157,14 @@ function Riven_Graph () { } function get_rect (node) { - let rect = node.rect + const rect = node.rect let x = node.rect.x * GRID_SIZE let y = node.rect.y * GRID_SIZE - let w = node.rect.w * GRID_SIZE - let h = node.rect.h * GRID_SIZE + const w = node.rect.w * GRID_SIZE + const h = node.rect.h * GRID_SIZE if (node.parent) { - let offset = get_rect(node.parent) + const offset = get_rect(node.parent) x += offset.x y += offset.y } diff --git a/scripts/lib/riven.js b/scripts/lib/riven.js @@ -8,10 +8,10 @@ function Riven () { // QUERY function Ø (s, network = RIVEN.network) { - let id = s.toLowerCase() + const id = s.toLowerCase() if (id.indexOf(' ') > -1) { - let node_id = id.split(' ')[0] - let port_id = id.split(' ')[1] + const node_id = id.split(' ')[0] + const port_id = id.split(' ')[1] return network[node_id] && network[node_id].ports[port_id] ? network[node_id].ports[port_id] : null } else if (network[id]) { return network[id] @@ -38,7 +38,7 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } this.create = function (pos = { x: 0, y: 0 }, type = Node, ...params) { - let node = new type(this.id, rect, ...params) + const node = new type(this.id, rect, ...params) this.rect.x = pos.x this.rect.y = pos.y node.setup() @@ -47,7 +47,7 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } this.mesh = function (pos, n) { - let node = new Mesh(this.id, pos) + const node = new Mesh(this.id, pos) node.rect.x = pos.x node.rect.y = pos.y node.setup() @@ -92,9 +92,9 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { this.signal = function (target) { for (port_id in this.ports) { - let port = this.ports[port_id] + const port = this.ports[port_id] for (route_id in port.routes) { - let route = port.routes[route_id] + const route = port.routes[route_id] if (!route || !route.host || route.host.id != target.toLowerCase()) { continue } return route.host } @@ -106,16 +106,16 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { this.send = function (payload) { for (route_id in this.ports.output.routes) { - let route = this.ports.output.routes[route_id] + const route = this.ports.output.routes[route_id] if (!route) { continue } route.host.receive(payload) } } this.receive = function (q) { - let port = this.ports.output + const port = this.ports.output for (route_id in port.routes) { - let route = port.routes[route_id] + const route = port.routes[route_id] if (route) { route.host.receive(q) } @@ -133,11 +133,11 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } this.request = function (q) { - let payload = {} + const payload = {} for (route_id in this.ports.request.routes) { - let route = this.ports.request.routes[route_id] + const route = this.ports.request.routes[route_id] if (!route) { continue } - let answer = route.host.answer(q) + const answer = route.host.answer(q) if (!answer) { continue } payload[route.host.id] = answer } @@ -167,9 +167,9 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { this.setup = function () {} this.update = function () { - let bounds = { x: 0, y: 0 } + const bounds = { x: 0, y: 0 } for (id in this.children) { - let node = this.children[id] + const node = this.children[id] bounds.x = node.rect.x > bounds.x ? node.rect.x : bounds.x bounds.y = node.rect.y > bounds.y ? node.rect.y : bounds.y } @@ -179,9 +179,9 @@ function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) { } } -let PORT_TYPES = { default: 'default', input: 'input', output: 'output', request: 'request', answer: 'answer' } -let ROUTE_TYPES = { default: 'default', request: 'request' } -let NODE_GLYPHS = { +const PORT_TYPES = { default: 'default', input: 'input', output: 'output', request: 'request', answer: 'answer' } +const ROUTE_TYPES = { default: 'default', request: 'request' } +const NODE_GLYPHS = { default: 'M150,60 L150,60 L60,150 L150,240 L240,150 Z', router: 'M60,120 L60,120 L150,120 L240,60 M60,150 L60,150 L240,150 M60,180 L60,180 L150,180 L240,240', parser: 'M60,60 L60,60 L240,60 M120,120 A30,30 0 0,1 150,150 M150,150 A30,30 0 0,0 180,180 M180,180 L180,180 L240,180 M120,120 L120,120 L60,120 M60,240 L60,240 L240,240 M240,120 L240,120 L180,120 M60,180 L60,180 L120,180', diff --git a/scripts/lib/runic.js b/scripts/lib/runic.js @@ -16,7 +16,7 @@ function Runic (raw) { '=': { glyph: '=', tag: 'h3', class: '' }, '+': { glyph: '+', tag: 'hs', class: '' }, '>': { glyph: '>', tag: '', class: '' }, - '$': { glyph: '>', tag: '', class: '' } + $: { glyph: '>', tag: '', class: '' } } this.stash = { @@ -27,7 +27,7 @@ function Runic (raw) { this.all.push({ rune: rune, item: item }) }, pop: function () { - let copy = this.copy(this.all) + const copy = this.copy(this.all) this.all = [] return copy }, @@ -43,8 +43,8 @@ function Runic (raw) { } this.media = function (val) { - let service = val.split(' ')[0] - let id = val.split(' ')[1] + const service = val.split(' ')[0] + const id = val.split(' ')[1] if (service == 'itchio') { return `<iframe frameborder="0" src="https://itch.io/embed/${id}?link_color=000000" width="600" height="167"></iframe>` @@ -59,15 +59,15 @@ function Runic (raw) { if (!raw) { return '' } let html = '' - let lines = !Array.isArray(raw) ? raw.split('\n') : raw + const lines = !Array.isArray(raw) ? raw.split('\n') : raw for (id in lines) { - let char = lines[id].substr(0, 1).trim().toString() - let rune = this.runes[char] - let trail = lines[id].substr(1, 1) + const char = lines[id].substr(0, 1).trim().toString() + const rune = this.runes[char] + const trail = lines[id].substr(1, 1) if (char == '$') { html += '<p>' + Ø('operation').request(lines[id].substr(2)).to_markup() + '</p>'; continue } if (char == '%') { html += this.media(lines[id].substr(2)); continue } - let line = lines[id].substr(2).to_markup() + const line = lines[id].substr(2).to_markup() if (!line || line.trim() == '') { continue } if (!rune) { console.log(`Unknown rune:${char} : ${line}`) } if (trail != ' ') { console.warn('Runic', 'Non-rune[' + trail + '] at:' + id + '(' + line + ')'); continue } @@ -81,13 +81,13 @@ function Runic (raw) { } this.render_stash = function () { - let rune = this.stash.rune - let stash = this.stash.pop() + const rune = this.stash.rune + const stash = this.stash.pop() let html = '' for (id in stash) { - let rune = stash[id].rune - let line = stash[id].item + const rune = stash[id].rune + const line = stash[id].item html += rune.wrap ? `<${rune.sub}><${rune.wrap}>${line.replace(/\|/g, `</${rune.wrap}><${rune.wrap}>`).trim()}</${rune.wrap}></${rune.sub}>` : `<${rune.sub}>${line}</${rune.sub}>` } return `<${rune.tag} class='${rune.class}'>${html}</${rune.tag}>` @@ -127,16 +127,16 @@ String.prototype.to_markup = function () { html = html.replace(/{\*/g, '<b>').replace(/\*}/g, '</b>') html = html.replace(/{\#/g, "<code class='inline'>").replace(/\#}/g, '</code>') - let parts = html.split('{{') + const parts = html.split('{{') for (id in parts) { - let part = parts[id] + const part = parts[id] if (part.indexOf('}}') == -1) { continue } - let content = part.split('}}')[0] + const content = part.split('}}')[0] if (content.substr(0, 1) == '$') { html = html.replace(`{{${content}}}`, Ø('operation').request(content.replace('$', ''))); continue } // if(content.substr(0,1) == "%"){ html = html.replace(`{{${content}}}`, this.media(content)); continue; } - let target = content.indexOf('|') > -1 ? content.split('|')[1] : content - let name = content.indexOf('|') > -1 ? content.split('|')[0] : content - let external = (target.indexOf('https:') > -1 || target.indexOf('http:') > -1 || target.indexOf('dat:') > -1) + const target = content.indexOf('|') > -1 ? content.split('|')[1] : content + const name = content.indexOf('|') > -1 ? content.split('|')[0] : content + const external = (target.indexOf('https:') > -1 || target.indexOf('http:') > -1 || target.indexOf('dat:') > -1) html = html.replace(`{{${content}}}`, external ? `<a href='${target}' class='external' target='_blank'>${name}</a>` : `<a class='local' href="#${target.to_url()}" onclick="Ø('query').bang('${target}')">${name}</a>`) } return html diff --git a/scripts/nodes/document.js b/scripts/nodes/document.js @@ -1,3 +1,5 @@ +'use strict' + function DocumentNode (id, rect, ...params) { Node.call(this, id, rect) diff --git a/scripts/nodes/dom.js b/scripts/nodes/dom.js @@ -1,3 +1,5 @@ +'use strict' + function DomNode (id, rect, ...params) { Node.call(this, id, rect) diff --git a/scripts/nodes/indental.js b/scripts/nodes/indental.js @@ -1,3 +1,5 @@ +'use strict' + function IndentalNode (id, rect, type) { Node.call(this, id, rect) @@ -23,10 +25,10 @@ function IndentalNode (id, rect, type) { function build (lines, type) { // Assoc lines - let stack = {} + const stack = {} let target = lines[0] for (id in lines) { - let line = lines[id] + const line = lines[id] if (line.skip) { continue } target = stack[line.indent - 2] if (target) { target.children.push(line) } @@ -34,21 +36,21 @@ function IndentalNode (id, rect, type) { } // Format - let h = {} + const h = {} for (id in lines) { - let line = lines[id] + const line = lines[id] if (line.skip || line.indent > 0) { continue } - let key = line.content.toUpperCase() + const key = line.content.toUpperCase() h[key] = type ? new type(key, format(line)) : format(line) } return h } function format (line) { - let a = [] - let h = {} + const a = [] + const h = {} for (id in line.children) { - let child = line.children[id] + const child = line.children[id] if (child.key) { h[child.key.toUpperCase()] = child.value } else if (child.children.length == 0 && child.content) { a.push(child.content) } else { h[child.content.toUpperCase()] = format(child) } } return a.length > 0 ? a : h @@ -67,4 +69,4 @@ function IndentalNode (id, rect, type) { } } -let DATABASE = {} +const DATABASE = {} diff --git a/scripts/nodes/query.js b/scripts/nodes/query.js @@ -1,3 +1,5 @@ +'use strict' + function QueryNode (id, rect) { Node.call(this, id, rect) @@ -5,7 +7,7 @@ function QueryNode (id, rect) { this.label = 'query' this.bang = function (input = window.location.hash) { - let target = input.to_url() === '' ? 'home' : input.to_url() + const target = input.to_url() === '' ? 'home' : input.to_url() Ø('view').el.className = `${target.to_path()} loading` @@ -22,12 +24,12 @@ function QueryNode (id, rect) { } } -let detectBackOrForward = function (onBack, onForward) { - hashHistory = [window.location.hash] - historyLength = window.history.length +const detectBackOrForward = function (onBack, onForward) { + let hashHistory = [window.location.hash] + let historyLength = window.history.length return function () { - let hash = window.location.hash; let length = window.history.length + const hash = window.location.hash; const length = window.history.length if (hashHistory.length && historyLength == length) { if (hashHistory[hashHistory.length - 2] == hash) { hashHistory = hashHistory.slice(0, -1) diff --git a/scripts/nodes/router.js b/scripts/nodes/router.js @@ -1,13 +1,15 @@ +'use strict' + function RouterNode (id, rect) { Node.call(this, id, rect) this.glyph = NODE_GLYPHS.router this.receive = function (q) { - let target = q.indexOf(':') > -1 ? q.split(':')[0].replace(/\+/g, ' ') : q.replace(/\+/g, ' ') - let params = q.indexOf(':') > -1 ? q.split(':')[1] : null - let db = this.request('database').database - let data = find(target.toUpperCase(), db) + const target = q.indexOf(':') > -1 ? q.split(':')[0].replace(/\+/g, ' ') : q.replace(/\+/g, ' ') + const params = q.indexOf(':') > -1 ? q.split(':')[1] : null + const db = this.request('database').database + const data = find(target.toUpperCase(), db) this.label = `${this.id}|${target}|${params}` @@ -26,7 +28,7 @@ function RouterNode (id, rect) { if (parseInt(key) > 0) { return null } for (id in db) { - let table = db[id] + const table = db[id] if (table[key]) { return { type: id, result: table[key] } } diff --git a/scripts/nodes/template.js b/scripts/nodes/template.js @@ -1,3 +1,5 @@ +'use strict' + function TemplateNode (id, rect) { Node.call(this, id, rect) @@ -6,8 +8,8 @@ function TemplateNode (id, rect) { this.cache = null this.receive = function (q) { - let assoc = this.signal(q.type ? q.type.slice(0, -1) : 'page') - let payload = assoc.answer(q) + const assoc = this.signal(q.type ? q.type.slice(0, -1) : 'page') + const payload = assoc.answer(q) this.send(payload) this.label = `template:${assoc.id}` diff --git a/scripts/templates/home.js b/scripts/templates/home.js @@ -1,22 +1,24 @@ +'use strict' + function HomeTemplate (id, rect) { Node.call(this, id, rect) this.glyph = NODE_GLYPHS.render this.answer = function (q) { - let ingredients = find_ingredients(q.tables.recipes) + const ingredients = find_ingredients(q.tables.recipes) - ingredients['coffee'] = 1 + ingredients.coffee = 1 - let sorted_ingredients = sort_ingredients(ingredients) + const sorted_ingredients = sort_ingredients(ingredients) - let html = ` + const html = ` ${make_ingredients(sorted_ingredients, q.tables.ingredients)} <h1>Recipes</h1> ${make_recipes(q.tables.recipes)} ` return { - title: `GrimGrains — Home`, + title: 'GrimGrains — Home', view: { core: { content: html, @@ -27,11 +29,11 @@ function HomeTemplate (id, rect) { } function find_ingredients (recipes) { - let h = {} + const h = {} for (id in recipes) { - let recipe = recipes[id] + const recipe = recipes[id] for (id in recipe.INGR) { - let category = recipe.INGR[id] + const category = recipe.INGR[id] for (name in category) { h[name] = h[name] ? h[name] + 1 : 1 } @@ -41,9 +43,9 @@ function HomeTemplate (id, rect) { } function sort_ingredients (ingredients) { - let a = [] + const a = [] for (name in ingredients) { - let value = ingredients[name] + const value = ingredients[name] a.push([name, value]) } a.sort(function (a, b) { @@ -55,20 +57,20 @@ function HomeTemplate (id, rect) { function make_ingredients (ingredients, table) { let html = '' for (id in ingredients) { - let name = ingredients[id][0] + const name = ingredients[id][0] html += ` <li class='ingredient${!table[name] ? ' missing' : ''}'> <a href='#${name.to_url()}' onclick="Ø('query').bang('${name}')"> <img src='media/ingredients/${name.to_path()}.png'/> + <span class='name'>${name.capitalize()}</span> </a> - <t class='name'>${name.capitalize()}</t> </li>` } return `<ul class='ingredients'>${html}</ul>` } function count_ingredients (recipe) { - let ingredients = {} + const ingredients = {} for (cat in recipe.INGR) { for (id in recipe.INGR[cat]) { ingredients[id] = 1 @@ -82,22 +84,22 @@ function HomeTemplate (id, rect) { // Sort by tag - let categorized = {} + const categorized = {} - for (name in recipes) { - let recipe = recipes[name] + for (const name in recipes) { + const recipe = recipes[name] if (!categorized[recipe.TAGS[0]]) { categorized[recipe.TAGS[0]] = [] } recipe.name = name categorized[recipe.TAGS[0]].push(recipe) } - for (cat in categorized) { - let recipes = categorized[cat] + for (const cat in categorized) { + const recipes = categorized[cat] html += `<h3>${cat.capitalize()}</h3>` html += "<ul style='margin-bottom:15px'>" for (id in recipes) { - let recipe = recipes[id] - if(recipe.HIDE){ continue; } + const recipe = recipes[id] + if (recipe.HIDE) { continue } html += `<li><a href="#${recipe.name.to_url()}" onclick="Ø('query').bang('${recipe.name.capitalize()}')">${recipe.name.capitalize()}</a></li>` } html += '</ul>' diff --git a/scripts/templates/ingredient.js b/scripts/templates/ingredient.js @@ -1,3 +1,5 @@ +'use strict' + function IngredientTemplate (id, rect) { Node.call(this, id, rect) @@ -6,7 +8,7 @@ function IngredientTemplate (id, rect) { // Create the recipe body this.answer = function (t) { - let ingredient = t.result + const ingredient = t.result return { title: `GrimGrains — ${t.name.capitalize()}`, @@ -31,77 +33,77 @@ function IngredientTemplate (id, rect) { html += `${make_similar(name, recipes, all_ingredients)}` return html } - + function make_parents (ingredient) { let html = '' - if (!ingredient.PARENT) {return html} + if (!ingredient.PARENT) { return html } html += "<h2>Parent Ingredients</h2><ul class='ingredients'>" - let parents = ingredient.PARENT.split(",") + const parents = ingredient.PARENT.split(',') for (id in parents) { - let name = parents[id].trim() + const name = parents[id].trim() html += ` <li class='ingredient'> <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> <img src='media/ingredients/${name.to_path()}.png'/> + <span class='name'>${name.capitalize()}</span> </a> - <t class='name'>${name.capitalize()}</t> </li>` } - html += "</ul>" + html += '</ul>' return html } - + function make_children (ingredient, all_ingredients) { let html = '' - let child_ingredients = find_child_ingredients(ingredient, all_ingredients) - if (child_ingredients.length == 0) {return html} - + const child_ingredients = find_child_ingredients(ingredient, all_ingredients) + if (child_ingredients.length == 0) { return html } + html += "<h2>Child Ingredients</h2><ul class='ingredients'>" for (id in child_ingredients) { - let name = child_ingredients[id] + const name = child_ingredients[id] html += ` <li class='ingredient'> <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> <img src='media/ingredients/${name.to_path()}.png'/> + <span class='name'>${name.capitalize()}</span> </a> - <t class='name'>${name.capitalize()}</t> </li>` } - - html += "</ul>" + + html += '</ul>' return html } function make_similar (search_name, recipes, all_ingredients) { let html = '' - let ingredients = find_ingredients(recipes) - let similar_ingredients = find_similar_ingredients(search_name, ingredients, all_ingredients) + const ingredients = find_ingredients(recipes) + const similar_ingredients = find_similar_ingredients(search_name, ingredients, all_ingredients) for (id in similar_ingredients) { if (similar_ingredients[id][1] < 1) { break } - let name = similar_ingredients[id][0] + const name = similar_ingredients[id][0] if (name.toLowerCase() == search_name.toLowerCase()) { continue } html += ` <li class='ingredient'> <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> <img src='media/ingredients/${name.to_path()}.png'/> + <span class='name'>${name.capitalize()}</span> </a> - <t class='name'>${name.capitalize()}</t> </li>` } return similar_ingredients.length >= 1 ? `<h2>Related Ingredients</h2><ul class='ingredients'>${html}<hr /></ul>` : '' } function find_ingredients (recipes) { - let h = {} + const h = {} for (id in recipes) { - let recipe = recipes[id] + const recipe = recipes[id] for (id in recipe.INGR) { - let category = recipe.INGR[id] + const category = recipe.INGR[id] for (name in category) { h[name] = h[name] ? h[name] + 1 : 1 } @@ -111,14 +113,14 @@ function IngredientTemplate (id, rect) { } function find_similar_ingredients (name, ingredients, all_ingredients) { - let a = [] - - let children = find_child_ingredients(name, all_ingredients) + const a = [] + + const children = find_child_ingredients(name, all_ingredients) for (id in ingredients) { - if (children.includes(id.toLowerCase())) {continue} - let words = id.toLowerCase().split(' ') - let index = similarity(name.toLowerCase().split(' '), words) + if (children.includes(id.toLowerCase())) { continue } + const words = id.toLowerCase().split(' ') + const index = similarity(name.toLowerCase().split(' '), words) if (index > 0) { a.push([id, index]) } @@ -130,14 +132,14 @@ function IngredientTemplate (id, rect) { return a.reverse() } - + function find_child_ingredients (search_name, all_ingredients) { - let a = [] - + const a = [] + for (name in all_ingredients) { - let ingr = all_ingredients[name] + const ingr = all_ingredients[name] if (!ingr.PARENT) { continue } - let parents = ingr.PARENT.split(",").map(function (name) {return name.trim().toLowerCase()}) + const parents = ingr.PARENT.split(',').map(function (name) { return name.trim().toLowerCase() }) if (parents.includes(search_name.toLowerCase())) { a.push(name.toLowerCase()) } @@ -148,10 +150,10 @@ function IngredientTemplate (id, rect) { function similarity (a, b) { let score = 0 - for (a_id in a) { - let word_a = a[a_id] - for (b_id in b) { - let word_b = b[b_id] + for (const a_id in a) { + const word_a = a[a_id] + for (const b_id in b) { + const word_b = b[b_id] score += word_a == word_b ? 1 : 0 } } @@ -163,13 +165,13 @@ function IngredientTemplate (id, rect) { let count = 0 for (id in recipes) { - let recipe = recipes[id] - let name = id + const recipe = recipes[id] + const name = id html += ` <li class='recipe'> <a onclick="Ø('query').bang('${name}')" class='photo' href='#${name.to_url()}' style='background-image:url(media/recipes/${name.to_path()}.jpg)'></a> - <t class='name'>${name.capitalize()}</t> - <t class='details'><b>${recipe.TIME} minutes</b><br />${count_ingredients(recipe)} ingredients<br />${recipe.INST.length} steps</t> + <span class='name'>${name.capitalize()}</span> + <span class='details'><b>${recipe.TIME} minutes</b><br />${count_ingredients(recipe)} ingredients<br />${recipe.INST.length} steps</span> </li>` if (count > 1) { break } count += 1 @@ -182,12 +184,12 @@ function IngredientTemplate (id, rect) { } function related_recipes (name, recipes) { - let h = {} + const h = {} for (id in recipes) { - let recipe = recipes[id] - for (i in recipe.INGR) { - let ingredients = recipe.INGR[i] - for (n in ingredients) { + const recipe = recipes[id] + for (const i in recipe.INGR) { + const ingredients = recipe.INGR[i] + for (const n in ingredients) { if (n.indexOf(name.toUpperCase()) < 0) { continue } h[id] = recipes[id] } @@ -197,9 +199,9 @@ function IngredientTemplate (id, rect) { } function related_ingredients (name, tag, ingredients) { - let a = [] - for (id in ingredients) { - let ingredient = ingredients[id] + const a = [] + for (const id in ingredients) { + const ingredient = ingredients[id] if (!ingredient.TAGS || ingredient.TAGS.indexOf(tag) < 0 || id == name) { continue } a.push(id) } @@ -207,9 +209,9 @@ function IngredientTemplate (id, rect) { } function count_ingredients (recipe) { - let ingredients = {} - for (cat in recipe.INGR) { - for (id in recipe.INGR[cat]) { + const ingredients = {} + for (const cat in recipe.INGR) { + for (const id in recipe.INGR[cat]) { ingredients[id] = 1 } } diff --git a/scripts/templates/page.js b/scripts/templates/page.js @@ -1,3 +1,5 @@ +'use strict' + function PageTemplate (id, rect) { Node.call(this, id, rect) @@ -15,7 +17,7 @@ function PageTemplate (id, rect) { return this.signal('search').answer(q) } - let page = q.result + const page = q.result return { title: `GrimGrains — ${q.name.capitalize()}`, view: { diff --git a/scripts/templates/recipe.js b/scripts/templates/recipe.js @@ -1,3 +1,5 @@ +'use strict' + function RecipeTemplate (id, rect) { Node.call(this, id, rect) @@ -7,7 +9,7 @@ function RecipeTemplate (id, rect) { this.answer = function (t) { let name = t.name - if (t.result && t.result.TITLE) {name = t.result.TITLE} + if (t.result && t.result.TITLE) { name = t.result.TITLE } return { title: `GrimGrains — ${name.capitalize()}`, view: { @@ -23,8 +25,8 @@ function RecipeTemplate (id, rect) { } function make_content (q) { - let recipe = q.result - let name = recipe.TITLE || q.name + const recipe = q.result + const name = recipe.TITLE || q.name let html = '' html += ` @@ -45,12 +47,12 @@ function RecipeTemplate (id, rect) { function make_instructions (recipe) { let html = '' - html += `<h2>Instructions</h2>` + html += '<h2>Instructions</h2>' let count = 1 - for (cat in recipe.INST) { + for (const cat in recipe.INST) { html += `<h3>Step ${count}: ${cat.capitalize()}</h3>` - let category = recipe.INST[cat].map(convertTemperatures) + const category = recipe.INST[cat].map(convertTemperatures) html += new Runic(category).toString() count += 1 } @@ -61,8 +63,8 @@ function RecipeTemplate (id, rect) { function make_warnings (recipe, all_ingredients) { let html = '' - for (cat in recipe.INGR) { - for (id in recipe.INGR[cat]) { + for (const cat in recipe.INGR) { + for (const id in recipe.INGR[cat]) { if (all_ingredients[id].WARN) { const warn = all_ingredients[id].WARN html += ` @@ -95,18 +97,18 @@ function RecipeTemplate (id, rect) { function make_related (q) { let html = '' - let recipe = q.result - let recipes = find_related(q.name, recipe, q.tables.recipes) + const recipe = q.result + const recipes = find_related(q.name, recipe, q.tables.recipes) let count = 0 for (id in recipes) { - let name = recipes[id][0] - let recipe = q.tables.recipes[name] + const name = recipes[id][0] + const recipe = q.tables.recipes[name] html += ` <li class='recipe'> <a class='photo' onclick="Ø('query').bang('${name}')" href='#${name.to_url()}' style='background-image:url(media/recipes/${name.to_path()}.jpg)'></a> - <t class='name'>${name.capitalize()}</t> - <t class='details'><b>${recipe.TIME} minutes</b><br />${count_ingredients(recipe)} ingredients<br />${Object.keys(recipe.INST).length} step${Object.keys(recipe.INST).length > 1 ? 's' : ''}</t> + <span class='name'>${name.capitalize()}</span> + <span class='details'><b>${recipe.TIME} minutes</b><br />${count_ingredients(recipe)} ingredients<br />${Object.keys(recipe.INST).length} step${Object.keys(recipe.INST).length > 1 ? 's' : ''}</span> </li>` if (count > 1) { break } count += 1 @@ -115,9 +117,9 @@ function RecipeTemplate (id, rect) { } function count_ingredients (recipe) { - let ingredients = {} - for (cat in recipe.INGR) { - for (id in recipe.INGR[cat]) { + const ingredients = {} + for (const cat in recipe.INGR) { + for (const id in recipe.INGR[cat]) { ingredients[id] = 1 } } @@ -125,10 +127,10 @@ function RecipeTemplate (id, rect) { } function find_related (name, target, recipes) { - let a = [] + const a = [] for (id in recipes) { - let recipe = recipes[id] - let index = similarity(target.TAGS, recipe.TAGS) + const recipe = recipes[id] + const index = similarity(target.TAGS, recipe.TAGS) if (id.toLowerCase() != name.toLowerCase()) { a.push([id, index]) } @@ -142,32 +144,32 @@ function RecipeTemplate (id, rect) { function make_ingredients (categories) { let html = '' for (id in categories) { - let elements = categories[id] + const elements = categories[id] - html += `<ul class='ingredients'>` + html += '<ul class=\'ingredients\'>' html += Object.keys(categories).length > 1 ? `<h3>${id.capitalize()}</h3>` : '' for (name in elements) { - let element = elements[name] + const element = elements[name] html += ` <li class='ingredient'> <a onclick="Ø('query').bang('${name}')" href='#${name.to_url()}'> <img src='media/ingredients/${name.to_path()}.png'/> </a> - <t class='name'>${name.capitalize()}</t> - <t class='quantity'>${element}</t> + <span class='name'>${name.capitalize()}</span> + <span class='quantity'>${element}</span> </li>` } - html += `<hr /></ul>` + html += '<hr /></ul>' } return html } function similarity (a, b) { let score = 0 - for (a_id in a) { - let tag_a = a[a_id] - for (b_id in b) { - let tag_b = b[b_id] + for (const a_id in a) { + const tag_a = a[a_id] + for (const b_id in b) { + const tag_b = b[b_id] score += tag_a.toLowerCase() == tag_b.toLowerCase() ? 1 : 0 } } diff --git a/scripts/templates/search.js b/scripts/templates/search.js @@ -1,3 +1,5 @@ +'use strict' + function SearchTemplate (id, rect) { Node.call(this, id, rect) @@ -6,10 +8,10 @@ function SearchTemplate (id, rect) { // Create the search body this.answer = function (q) { - let html = '' + const html = '' return { - title: `GrimGrains — Search`, + title: 'GrimGrains — Search', view: { header: { search: 'search' @@ -33,7 +35,7 @@ function SearchTemplate (id, rect) { <h2 class='serving'>404</h2> <hr /> <p>Did you mean <a onclick="Ø('query').bang('${similar[0].word.toLowerCase()}')" href='#${similar[0].word.toLowerCase().to_url()}'>${similar[0].word.toLowerCase()}</a>, <a onclick="Ø('query').bang('${similar[1].word.toLowerCase()}')" href='#${similar[1].word.toLowerCase().to_url()}'>${similar[1].word.toLowerCase()}</a>, or <a onclick="Ø('query').bang('${similar[2].word.toLowerCase()}')" href='#${similar[2].word.toLowerCase().to_url()}'>${similar[2].word.toLowerCase()}</a>?</p> - <p>To create this page, open an issue or pull request ${"{{on GitHub|https://github.com/hundredrabbits/Grimgrains}}".to_markup()}.</p>` + <p>To create this page, open an issue or pull request ${'{{on GitHub|https://github.com/hundredrabbits/Grimgrains}}'.to_markup()}.</p>` return html } diff --git a/scripts/templates/service.js b/scripts/templates/service.js @@ -1,17 +1,19 @@ +'use strict' + function ServiceTemplate (id, rect) { Node.call(this, id, rect) this.glyph = NODE_GLYPHS.render this.answer = function (q) { - let recipe_ingredients = find_ingredients(q.tables.recipes) + const recipe_ingredients = find_ingredients(q.tables.recipes) - let html = ` + const html = ` ${make_pageless(recipe_ingredients, q.tables.ingredients)} ${make_unused(recipe_ingredients, q.tables.ingredients)} ` return { - title: `GrimGrains — Service Panel`, + title: 'GrimGrains — Service Panel', view: { core: { content: html, @@ -22,90 +24,90 @@ function ServiceTemplate (id, rect) { } function find_ingredients (recipes) { - let h = [] + const h = [] for (id in recipes) { - let recipe = recipes[id] + const recipe = recipes[id] for (id in recipe.INGR) { - let category = recipe.INGR[id] + const category = recipe.INGR[id] for (name in category) { - if (!h.includes(name.toLowerCase())) {h.push(name.toLowerCase())} + if (!h.includes(name.toLowerCase())) { h.push(name.toLowerCase()) } } } } return h } - + function make_pageless (used, pages) { - let pageless = find_pageless(used, pages) - let html = "" + const pageless = find_pageless(used, pages) + let html = '' for (id in pageless) { html += ` <li class='ingredient missing'> <a href='#${pageless[id].to_url()}' onclick="Ø('query').bang('${pageless[id]}')"> <img src='media/ingredients/${pageless[id].to_path()}.png'/> + <span class='name'>${pageless[id].capitalize()}</span> </a> - <t class='name'>${pageless[id].capitalize()}</t> </li>` } - if (html == "") {return `<h2>No Ingredients Without Pages!</h2>`} + if (html == '') { return '<h2>No Ingredients Without Pages!</h2>' } return `<h2>Ingredients Without Pages</h2><ul class='ingredients'>${html}</ul>` } - + function find_pageless (used, pages) { - let pageless = [] - + const pageless = [] + for (id in used) { - let name = used[id].toUpperCase() - if (!pages[name]) {pageless.push(name)} + const name = used[id].toUpperCase() + if (!pages[name]) { pageless.push(name) } } - + return pageless } - + function make_unused (used, pages) { - let unused = find_unused(used, pages) - let html = "" - + const unused = find_unused(used, pages) + let html = '' + for (id in unused) { html += ` <li class='ingredient'> <a href='#${unused[id].to_url()}' onclick="Ø('query').bang('${unused[id]}')"> <img src='media/ingredients/${unused[id].to_path()}.png'/> + <span class='name'>${unused[id].capitalize()}</span> </a> - <t class='name'>${unused[id].capitalize()}</t> </li>` } - if (html == "") {return `<h2>No Unused Ingredients!</h2>`} + if (html == '') { return '<h2>No Unused Ingredients!</h2>' } return `<h2>Unused Ingredients</h2><ul class='ingredients'>${html}</ul>` } - + function find_unused (used, pages) { - let unused = [] - + const unused = [] + for (name in pages) { - if (!used.includes(name.toLowerCase())) {unused.push(name)} + if (!used.includes(name.toLowerCase())) { unused.push(name) } } - + return unused } function make_ingredients (ingredients, table) { let html = '' for (id in ingredients) { - let name = ingredients[id][0] + const name = ingredients[id][0] html += ` <li class='ingredient${!table[name] ? ' missing' : ''}'> <a href='#${name.to_url()}' onclick="Ø('query').bang('${name}')"> <img src='media/ingredients/${name.to_path()}.png'/> + <span class='name'>${name.capitalize()}</span> </a> - <t class='name'>${name.capitalize()}</t> </li>` } return `<ul class='ingredients'>${html}</ul>` } function count_ingredients (recipe) { - let ingredients = {} + const ingredients = {} for (cat in recipe.INGR) { for (id in recipe.INGR[cat]) { ingredients[id] = 1 @@ -119,21 +121,21 @@ function ServiceTemplate (id, rect) { // Sort by tag - let categorized = {} + const categorized = {} for (name in recipes) { - let recipe = recipes[name] + const recipe = recipes[name] if (!categorized[recipe.TAGS[0]]) { categorized[recipe.TAGS[0]] = [] } recipe.name = name categorized[recipe.TAGS[0]].push(recipe) } for (cat in categorized) { - let recipes = categorized[cat] + const recipes = categorized[cat] html += `<h3>${cat.capitalize()}</h3>` html += "<ul style='margin-bottom:15px'>" for (id in recipes) { - let recipe = recipes[id] + const recipe = recipes[id] html += `<li><a href="#${recipe.name.to_url()}" onclick="Ø('query').bang('${recipe.name.capitalize()}')">${recipe.name.capitalize()}</a></li>` } html += '</ul>'