enviar plantillas a env.js

This commit is contained in:
f 2021-10-28 10:00:00 -03:00
parent eea2dc801b
commit 867d746244
11 changed files with 27 additions and 25 deletions

View file

@ -16,6 +16,6 @@ layout: default
data-controller="cart-payment-methods" data-controller="cart-payment-methods"
data-cart-payment-methods-next-url="{{ site.confirmation.url }}" data-cart-payment-methods-next-url="{{ site.confirmation.url }}"
data-cart-payment-methods-back-url="{{ site.shipment.url }}" data-cart-payment-methods-back-url="{{ site.shipment.url }}"
data-cart-payment-methods-template="assets/templates/payment_methods.html"> data-cart-payment-methods-template="payment_methods">
</div> </div>
</section> </section>

View file

@ -12,7 +12,6 @@ export default class extends CartBaseController {
if (!this.template) return if (!this.template) return
if (this.storage.cart) { if (this.storage.cart) {
const order = this.cart.data.attributes const order = this.cart.data.attributes
const products = this.products const products = this.products
const site = await this.site() const site = await this.site()
@ -29,16 +28,14 @@ export default class extends CartBaseController {
} }
render (data = {}) { render (data = {}) {
fetch(this.template).then(r => r.text()).then(template => { this.engine.parseAndRender(this.template, data).then(html => this.orderTarget.innerHTML = html)
this.engine.parseAndRender(template, data).then(html => this.orderTarget.innerHTML = html)
})
}
get template () {
return this.element.dataset.template
} }
get clear () { get clear () {
return this.element.dataset.clear return this.element.dataset.clear
} }
get template () {
return window.templates[this.element.dataset.template]
}
} }

View file

@ -25,8 +25,7 @@ export default class extends CartBaseController {
} }
async render (data = {}) { async render (data = {}) {
const request = await fetch(this.data.get('template')) const template = window.templates[this.data.get('template')]
const template = await request.text()
this.element.innerHTML = await this.engine.parseAndRender(template, data) this.element.innerHTML = await this.engine.parseAndRender(template, data)

View file

@ -102,8 +102,7 @@ export default class extends CartBaseController {
} }
async render (data = {}) { async render (data = {}) {
const request = await fetch(this.data.get('template')) const template = window.templates[this.data.get('template')]
const template = await request.text()
this.methodsTarget.innerHTML = await this.engine.parseAndRender(template, data) this.methodsTarget.innerHTML = await this.engine.parseAndRender(template, data)
this.ratesTarget.addEventListener('formdata', event => this.processShippingRate(event.formData)) this.ratesTarget.addEventListener('formdata', event => this.processShippingRate(event.formData))

View file

@ -24,15 +24,6 @@ export default class extends Controller {
this.show() this.show()
} }
/*
* Gets the template path from a name
*
* @return [String]
*/
template (name) {
return this.data.get('templates') + name + '.html'
}
/* /*
* Shows the notification * Shows the notification
*/ */

View file

@ -43,9 +43,9 @@ export default class extends CartBaseController {
* Download the item template and render the order * Download the item template and render the order
*/ */
render (data = {}) { render (data = {}) {
fetch(this.data.get('itemTemplate')).then(r => r.text()).then(template => { const template = window.templates[this.data.get('itemTemplate')]
this.engine.parseAndRender(template, data).then(html => this.cartTarget.innerHTML = html)
}) this.engine.parseAndRender(template, data).then(html => this.cartTarget.innerHTML = html)
} }
/* /*

View file

@ -1,3 +1,4 @@
{%- raw -%}
{% for product in products %} {% for product in products %}
<div <div
class="border-bottom row no-gutters align-items-center justify-content-center mb-3 mb-md-0 pb-3 pb-md-0" class="border-bottom row no-gutters align-items-center justify-content-center mb-3 mb-md-0 pb-3 pb-md-0"
@ -63,3 +64,4 @@
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{%- endraw -%}

View file

@ -1,3 +1,4 @@
{%- raw -%}
<form id="coupon" data-controller="cart-coupon" data-action="cart-coupon#apply"></form> <form id="coupon" data-controller="cart-coupon" data-action="cart-coupon#apply"></form>
<form <form
@ -60,3 +61,4 @@
</div> </div>
</div> </div>
</form> </form>
{%- endraw -%}

View file

@ -1,3 +1,4 @@
{%- raw -%}
<div class="alert alert-{{ type }} alert-dismissible" role="alert" data-controller="cart"> <div class="alert alert-{{ type }} alert-dismissible" role="alert" data-controller="cart">
{{ content }} {{ content }}
@ -9,3 +10,4 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
{%- endraw -%}

View file

@ -1,3 +1,4 @@
{%- raw -%}
<form <form
data-action="cart-shipping#payment" data-action="cart-shipping#payment"
data-target="cart-shipping.rates"> data-target="cart-shipping.rates">
@ -34,3 +35,4 @@
</div> </div>
</div> </div>
</form> </form>
{%- endraw -%}

8
env.js
View file

@ -23,8 +23,16 @@ window.site = {
{%- endcomment -%} {%- endcomment -%}
{%- capture alert %}{% include_relative assets/templates/alert.html %}{% endcapture -%} {%- capture alert %}{% include_relative assets/templates/alert.html %}{% endcapture -%}
{%- capture results %}{% include_relative assets/templates/results.html %}{% endcapture -%} {%- capture results %}{% include_relative assets/templates/results.html %}{% endcapture -%}
{%- capture cart %}{% include_relative assets/templates/cart.html %}{% endcapture -%}
{%- capture payment_methods %}{% include_relative assets/templates/payment_methods.html %}{% endcapture -%}
{%- capture recover_order %}{% include_relative assets/templates/recover_order.html %}{% endcapture -%}
{%- capture shipping_methods %}{% include_relative assets/templates/shipping_methods.html %}{% endcapture -%}
window.templates = { window.templates = {
"alert": {{ alert | jsonify }}, "alert": {{ alert | jsonify }},
"results": {{ results | jsonify }}, "results": {{ results | jsonify }},
"cart": {{ cart | jsonify }},
"payment_methods": {{ payment_methods | jsonify }},
"recover_order": {{ recover_order | jsonify }},
"shipping_methods": {{ shipping_methods | jsonify }},
} }