shoperb_liquid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +131 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +143 -0
- data/Rakefile +4 -0
- data/lib/shoperb_liquid/configuration.rb +169 -0
- data/lib/shoperb_liquid/drops/account_drop.rb +9 -0
- data/lib/shoperb_liquid/drops/address_drop.rb +121 -0
- data/lib/shoperb_liquid/drops/array_drop.rb +18 -0
- data/lib/shoperb_liquid/drops/attribute_drop.rb +21 -0
- data/lib/shoperb_liquid/drops/base.rb +65 -0
- data/lib/shoperb_liquid/drops/blog_category_drop.rb +56 -0
- data/lib/shoperb_liquid/drops/blog_post_drop.rb +46 -0
- data/lib/shoperb_liquid/drops/cart_drop.rb +42 -0
- data/lib/shoperb_liquid/drops/cart_item_drop.rb +111 -0
- data/lib/shoperb_liquid/drops/categories_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/category_drop.rb +110 -0
- data/lib/shoperb_liquid/drops/collection_drop.rb +117 -0
- data/lib/shoperb_liquid/drops/country_drop.rb +37 -0
- data/lib/shoperb_liquid/drops/currency_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/customer_credit_drop.rb +23 -0
- data/lib/shoperb_liquid/drops/customer_credits_drop.rb +18 -0
- data/lib/shoperb_liquid/drops/customer_drop.rb +108 -0
- data/lib/shoperb_liquid/drops/customer_group_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/gift_card_drop.rb +34 -0
- data/lib/shoperb_liquid/drops/image_drop.rb +27 -0
- data/lib/shoperb_liquid/drops/integration_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/integrations_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/language_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/link_drop.rb +53 -0
- data/lib/shoperb_liquid/drops/media_file_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/menu_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/menus_drop.rb +16 -0
- data/lib/shoperb_liquid/drops/meta_drop.rb +21 -0
- data/lib/shoperb_liquid/drops/order_drop.rb +148 -0
- data/lib/shoperb_liquid/drops/order_item_attribute_drop.rb +8 -0
- data/lib/shoperb_liquid/drops/order_item_attributes_drop.rb +19 -0
- data/lib/shoperb_liquid/drops/order_item_drop.rb +159 -0
- data/lib/shoperb_liquid/drops/order_return_drop.rb +43 -0
- data/lib/shoperb_liquid/drops/order_return_item_drop.rb +30 -0
- data/lib/shoperb_liquid/drops/order_return_item_entity_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/order_return_parcel_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/order_returns_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/orders_drop.rb +14 -0
- data/lib/shoperb_liquid/drops/page_drop.rb +26 -0
- data/lib/shoperb_liquid/drops/pages_drop.rb +12 -0
- data/lib/shoperb_liquid/drops/payment_card_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/payment_method_drop.rb +41 -0
- data/lib/shoperb_liquid/drops/payment_provider_drop.rb +23 -0
- data/lib/shoperb_liquid/drops/product_attribute_drop.rb +14 -0
- data/lib/shoperb_liquid/drops/product_collection_drop.rb +41 -0
- data/lib/shoperb_liquid/drops/product_collections_drop.rb +12 -0
- data/lib/shoperb_liquid/drops/product_drop.rb +195 -0
- data/lib/shoperb_liquid/drops/product_type_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/product_types_drop.rb +15 -0
- data/lib/shoperb_liquid/drops/products_drop.rb +44 -0
- data/lib/shoperb_liquid/drops/refund_drop.rb +22 -0
- data/lib/shoperb_liquid/drops/refund_item_drop.rb +18 -0
- data/lib/shoperb_liquid/drops/review_drop.rb +37 -0
- data/lib/shoperb_liquid/drops/search_drop.rb +45 -0
- data/lib/shoperb_liquid/drops/shipping_item_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/shipping_method_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/shipping_parcel_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/shop_drop.rb +81 -0
- data/lib/shoperb_liquid/drops/subscription_drop.rb +51 -0
- data/lib/shoperb_liquid/drops/subscription_plan_drop.rb +63 -0
- data/lib/shoperb_liquid/drops/theme_section_blocks_drop.rb +19 -0
- data/lib/shoperb_liquid/drops/theme_section_drop.rb +30 -0
- data/lib/shoperb_liquid/drops/theme_section_image_drop.rb +11 -0
- data/lib/shoperb_liquid/drops/theme_section_settings_drop.rb +40 -0
- data/lib/shoperb_liquid/drops/theme_settings_drop.rb +60 -0
- data/lib/shoperb_liquid/drops/url_drop.rb +218 -0
- data/lib/shoperb_liquid/drops/variant_attribute_drop.rb +8 -0
- data/lib/shoperb_liquid/drops/variant_drop.rb +206 -0
- data/lib/shoperb_liquid/drops/variants_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/vendor_drop.rb +77 -0
- data/lib/shoperb_liquid/drops/vendors_drop.rb +13 -0
- data/lib/shoperb_liquid/errors.rb +6 -0
- data/lib/shoperb_liquid/ext/array.rb +7 -0
- data/lib/shoperb_liquid/ext/context.rb +12 -0
- data/lib/shoperb_liquid/ext/models.rb +55 -0
- data/lib/shoperb_liquid/ext/template.rb +13 -0
- data/lib/shoperb_liquid/filters/asset_filters.rb +57 -0
- data/lib/shoperb_liquid/filters/collection_filters.rb +26 -0
- data/lib/shoperb_liquid/filters/datum_filters.rb +150 -0
- data/lib/shoperb_liquid/filters/extension_filters.rb +35 -0
- data/lib/shoperb_liquid/filters/html_filters.rb +46 -0
- data/lib/shoperb_liquid/filters/theme_filters.rb +22 -0
- data/lib/shoperb_liquid/filters/translate_filters.rb +16 -0
- data/lib/shoperb_liquid/filters/url_filters.rb +60 -0
- data/lib/shoperb_liquid/registers.rb +76 -0
- data/lib/shoperb_liquid/tags/cache_tag.rb +45 -0
- data/lib/shoperb_liquid/tags/form_tag.rb +47 -0
- data/lib/shoperb_liquid/tags/layout_tag.rb +21 -0
- data/lib/shoperb_liquid/tags/paginate_tag.rb +134 -0
- data/lib/shoperb_liquid/tags/products_filter_tag.rb +106 -0
- data/lib/shoperb_liquid/tags/section_tag.rb +113 -0
- data/lib/shoperb_liquid.rb +46 -0
- data/shoperb_liquid.gemspec +24 -0
- metadata +223 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
module Url
|
5
|
+
# paths to generate links
|
6
|
+
class GetDrop < Base
|
7
|
+
def initialize; end
|
8
|
+
|
9
|
+
def root
|
10
|
+
controller.store_root_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def products
|
14
|
+
controller.store_products_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def collections
|
18
|
+
controller.store_collections_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def cart
|
22
|
+
controller.store_cart_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def signup
|
26
|
+
controller.store_signup_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def login
|
30
|
+
controller.store_login_path
|
31
|
+
end
|
32
|
+
|
33
|
+
def logout
|
34
|
+
controller.store_logout_path
|
35
|
+
end
|
36
|
+
|
37
|
+
def account
|
38
|
+
controller.store_account_path
|
39
|
+
end
|
40
|
+
|
41
|
+
def recover
|
42
|
+
controller.store_recover_password_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset
|
46
|
+
controller.store_reset_password_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def orders
|
50
|
+
controller.store_orders_path
|
51
|
+
end
|
52
|
+
|
53
|
+
def addresses
|
54
|
+
controller.store_addresses_path
|
55
|
+
end
|
56
|
+
|
57
|
+
def new_address
|
58
|
+
controller.new_store_address_path
|
59
|
+
end
|
60
|
+
|
61
|
+
def search
|
62
|
+
controller.store_search_path
|
63
|
+
end
|
64
|
+
|
65
|
+
def blog
|
66
|
+
controller.store_blog_posts_path
|
67
|
+
end
|
68
|
+
|
69
|
+
def brands
|
70
|
+
controller.store_brands_path
|
71
|
+
end
|
72
|
+
alias :vendors :brands
|
73
|
+
|
74
|
+
def current_url
|
75
|
+
request.try(:url)
|
76
|
+
end
|
77
|
+
|
78
|
+
def canonical_url
|
79
|
+
controller.url_for(only_path: false)
|
80
|
+
end
|
81
|
+
|
82
|
+
def current_path
|
83
|
+
request.try(:path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def canonical_path
|
87
|
+
controller.url_for(only_path: true)
|
88
|
+
end
|
89
|
+
|
90
|
+
def current_host
|
91
|
+
request.try(:host)
|
92
|
+
end
|
93
|
+
|
94
|
+
def billing_payment_methods
|
95
|
+
controller.store_account_billing_payment_methods_path
|
96
|
+
end
|
97
|
+
|
98
|
+
def new_billing_payment_method
|
99
|
+
controller.add_store_account_billing_payment_methods_path
|
100
|
+
end
|
101
|
+
|
102
|
+
def account_subscriptions
|
103
|
+
controller.store_account_subscriptions_path
|
104
|
+
end
|
105
|
+
|
106
|
+
def account_subscription_plans
|
107
|
+
controller.store_account_subscription_plans_path
|
108
|
+
end
|
109
|
+
|
110
|
+
def account_create_subscription
|
111
|
+
controller.store_account_create_subscription_path
|
112
|
+
end
|
113
|
+
|
114
|
+
def order_returns
|
115
|
+
controller.store_order_returns_path
|
116
|
+
end
|
117
|
+
|
118
|
+
def new_order_returns
|
119
|
+
controller.new_store_order_return_path
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def request
|
125
|
+
controller.try(:request)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Paths to generate form actions
|
130
|
+
class PostDrop < Base
|
131
|
+
def initialize; end
|
132
|
+
|
133
|
+
def add_subscriber
|
134
|
+
controller.store_subscribers_add_path
|
135
|
+
end
|
136
|
+
|
137
|
+
def cart_add
|
138
|
+
controller.add_store_cart_path
|
139
|
+
end
|
140
|
+
|
141
|
+
def cart_checkout
|
142
|
+
controller.checkout_store_cart_path
|
143
|
+
end
|
144
|
+
|
145
|
+
def cart_update
|
146
|
+
val = controller.update_store_cart_path
|
147
|
+
val = val[0..-2] if val.ends_with?('/')
|
148
|
+
val
|
149
|
+
end
|
150
|
+
|
151
|
+
def signup
|
152
|
+
controller.store_signup_path
|
153
|
+
end
|
154
|
+
|
155
|
+
def new_login
|
156
|
+
controller.store_new_login_path
|
157
|
+
end
|
158
|
+
|
159
|
+
def account
|
160
|
+
controller.store_account_path
|
161
|
+
end
|
162
|
+
|
163
|
+
def password_request
|
164
|
+
controller.store_recover_password_path
|
165
|
+
end
|
166
|
+
|
167
|
+
def password_change
|
168
|
+
controller.store_upd_reset_password_path
|
169
|
+
end
|
170
|
+
|
171
|
+
def address_create
|
172
|
+
controller.store_addresses_path
|
173
|
+
end
|
174
|
+
|
175
|
+
def store_order_returns_path
|
176
|
+
controller.store_order_returns_path
|
177
|
+
end
|
178
|
+
|
179
|
+
def reviews
|
180
|
+
controller.store_reviews_path
|
181
|
+
end
|
182
|
+
|
183
|
+
def variants
|
184
|
+
controller.store_variants_path
|
185
|
+
end
|
186
|
+
|
187
|
+
def auth_input
|
188
|
+
value = controller.send(:form_authenticity_token) rescue nil
|
189
|
+
|
190
|
+
%(<input type="hidden" name="authenticity_token" value="#{value}"> <input autocomplete="nope" type="search" name="shoperb_first_last_name_1" value="" class="shoperb_authenticity_token" tabindex="-1" />
|
191
|
+
<style>
|
192
|
+
.shoperb_authenticity_token{
|
193
|
+
opacity: 0;
|
194
|
+
position: absolute;
|
195
|
+
top: 0;
|
196
|
+
left: 0;
|
197
|
+
height: 0;
|
198
|
+
width: 0;
|
199
|
+
z-index: -1;
|
200
|
+
}
|
201
|
+
</style>
|
202
|
+
)
|
203
|
+
end
|
204
|
+
|
205
|
+
def liquid_method_missing(method, *args)
|
206
|
+
if matches = method.to_s.match(/\Amulti_cart_add__(.+)/)
|
207
|
+
controller.add_store_multi_cart_path(matches[1])
|
208
|
+
elsif matches = method.to_s.match(/\Amulti_cart_checkout__(.+)/)
|
209
|
+
controller.checkout_store_multi_cart_path(matches[1])
|
210
|
+
elsif matches = method.to_s.match(/\multi_cart_update__(.+)/)
|
211
|
+
controller.update_store_multi_cart_path(matches[1])
|
212
|
+
else
|
213
|
+
super(method)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class VariantDrop < Base
|
5
|
+
def context=(context)
|
6
|
+
super(context)
|
7
|
+
@record.customer = current_customer
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
record.id
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
record.name
|
16
|
+
end
|
17
|
+
|
18
|
+
def price
|
19
|
+
record.price
|
20
|
+
end
|
21
|
+
|
22
|
+
def amount_step
|
23
|
+
record.amount_step
|
24
|
+
end
|
25
|
+
|
26
|
+
def amount_step_unit
|
27
|
+
record.amount_step_unit
|
28
|
+
end
|
29
|
+
|
30
|
+
def discount_price
|
31
|
+
# active price includes discount
|
32
|
+
record.active_price if discount?
|
33
|
+
end
|
34
|
+
|
35
|
+
def discount?
|
36
|
+
record.discount.present?
|
37
|
+
end
|
38
|
+
|
39
|
+
def discount_period?
|
40
|
+
record.has_discount_range?
|
41
|
+
end
|
42
|
+
|
43
|
+
def discount_start
|
44
|
+
record.formatted_discount_start
|
45
|
+
end
|
46
|
+
|
47
|
+
def discount_end
|
48
|
+
record.formatted_discount_end
|
49
|
+
end
|
50
|
+
|
51
|
+
def current_price
|
52
|
+
record.active_price
|
53
|
+
end
|
54
|
+
|
55
|
+
def compare_at
|
56
|
+
record.compare_at
|
57
|
+
end
|
58
|
+
def market_price
|
59
|
+
record.compare_at
|
60
|
+
end
|
61
|
+
|
62
|
+
def pkg_deposit
|
63
|
+
record.pkg_deposit
|
64
|
+
end
|
65
|
+
|
66
|
+
def gift_card_value
|
67
|
+
record.gift_card_value
|
68
|
+
end
|
69
|
+
|
70
|
+
def available?
|
71
|
+
record.available?(:warehouse)
|
72
|
+
end
|
73
|
+
|
74
|
+
def track_inventory?
|
75
|
+
record.track_inventory?
|
76
|
+
end
|
77
|
+
|
78
|
+
def allow_backorder?
|
79
|
+
record.allow_backorder?
|
80
|
+
end
|
81
|
+
|
82
|
+
def purchased?
|
83
|
+
if current_customer
|
84
|
+
current_customer.purchased_variant?(record)
|
85
|
+
else
|
86
|
+
false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def sku
|
91
|
+
record.sku
|
92
|
+
end
|
93
|
+
|
94
|
+
def barcode
|
95
|
+
record.barcode
|
96
|
+
end
|
97
|
+
|
98
|
+
def stock
|
99
|
+
record.track_inventory? ? try_int(record.stock(Cart.new)) : nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def weight
|
103
|
+
record.weight
|
104
|
+
end
|
105
|
+
|
106
|
+
def width
|
107
|
+
record.width
|
108
|
+
end
|
109
|
+
|
110
|
+
def height
|
111
|
+
record.height
|
112
|
+
end
|
113
|
+
|
114
|
+
def depth
|
115
|
+
record.depth
|
116
|
+
end
|
117
|
+
|
118
|
+
def digital
|
119
|
+
record.digital
|
120
|
+
end
|
121
|
+
|
122
|
+
def number_in_package
|
123
|
+
record.num_in_pack
|
124
|
+
end
|
125
|
+
alias :num_in_pack :number_in_package
|
126
|
+
|
127
|
+
def unit_price
|
128
|
+
return current_price if number_in_package.to_d.eql?(0)
|
129
|
+
current_price/number_in_package
|
130
|
+
end
|
131
|
+
|
132
|
+
def url
|
133
|
+
record.url
|
134
|
+
end
|
135
|
+
|
136
|
+
def options
|
137
|
+
record.variant_attributes.map(&:value)
|
138
|
+
end
|
139
|
+
|
140
|
+
def image
|
141
|
+
ImageDrop.new(record.image) if record.image
|
142
|
+
end
|
143
|
+
|
144
|
+
def images
|
145
|
+
CollectionDrop.new(record.images.sorted)
|
146
|
+
end
|
147
|
+
|
148
|
+
def attributes
|
149
|
+
CollectionDrop.new(record.variant_attributes)
|
150
|
+
end
|
151
|
+
|
152
|
+
def json
|
153
|
+
h = record.as_json(only: [:id, :sku, :name, :weight, :width, :height, :depth, :price])
|
154
|
+
h[:gift_card_value] if record.gift_card_value
|
155
|
+
h.merge!(
|
156
|
+
current_price: current_price,
|
157
|
+
has_discount: discount?,
|
158
|
+
discount_price: discount_price,
|
159
|
+
stock: stock
|
160
|
+
)
|
161
|
+
|
162
|
+
record.variant_attributes.each do |attr|
|
163
|
+
(h[:attributes] ||= []) << {
|
164
|
+
id: attr.id,
|
165
|
+
name: attr.name,
|
166
|
+
value: attr.value,
|
167
|
+
handle: attr.handle,
|
168
|
+
}
|
169
|
+
end
|
170
|
+
|
171
|
+
h.to_json
|
172
|
+
end
|
173
|
+
|
174
|
+
def cached_json
|
175
|
+
cache_key = ["liquid.drop", "variant_drop_json", record.cache_key]
|
176
|
+
ShoperbLiquid.config.cache.fetch(cache_key) { json }
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
def as_json
|
181
|
+
{
|
182
|
+
id:id,
|
183
|
+
product_id: record.product_id,
|
184
|
+
sku: sku,
|
185
|
+
weight: weight,
|
186
|
+
width: width,
|
187
|
+
height: height,
|
188
|
+
depth: depth,
|
189
|
+
price: price,
|
190
|
+
gift_card_value: gift_card_value,
|
191
|
+
stock: stock,
|
192
|
+
discount_price: discount_price,
|
193
|
+
discount: discount?,
|
194
|
+
current_price: current_price,
|
195
|
+
compare_at: compare_at,
|
196
|
+
pkg_deposit: pkg_deposit,
|
197
|
+
available: available?,
|
198
|
+
track_inventory: track_inventory?,
|
199
|
+
allow_backorder: allow_backorder?,
|
200
|
+
digital: digital,
|
201
|
+
url: url,
|
202
|
+
image: image&.url
|
203
|
+
}
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class VendorDrop < Base
|
5
|
+
def initialize(record)
|
6
|
+
@record = record || Vendor.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
record.id
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle
|
14
|
+
record.handle
|
15
|
+
end
|
16
|
+
|
17
|
+
def permalink
|
18
|
+
record.permalink
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
record.name
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
record.description
|
27
|
+
end
|
28
|
+
|
29
|
+
def code
|
30
|
+
record.code
|
31
|
+
end
|
32
|
+
|
33
|
+
def fax
|
34
|
+
record.fax
|
35
|
+
end
|
36
|
+
|
37
|
+
def phone
|
38
|
+
record.phone
|
39
|
+
end
|
40
|
+
|
41
|
+
def email
|
42
|
+
record.email
|
43
|
+
end
|
44
|
+
|
45
|
+
def website
|
46
|
+
record.website
|
47
|
+
end
|
48
|
+
|
49
|
+
def contact_name
|
50
|
+
record.contact_name
|
51
|
+
end
|
52
|
+
|
53
|
+
def contact_phone
|
54
|
+
record.contact_phone
|
55
|
+
end
|
56
|
+
|
57
|
+
def contact_email
|
58
|
+
record.contact_email
|
59
|
+
end
|
60
|
+
|
61
|
+
def image
|
62
|
+
ImageDrop.new(record.image) if record.image
|
63
|
+
end
|
64
|
+
|
65
|
+
def address
|
66
|
+
AddressDrop.new(record.address) if record.address
|
67
|
+
end
|
68
|
+
|
69
|
+
def products
|
70
|
+
ProductsDrop.new(record.products)
|
71
|
+
end
|
72
|
+
|
73
|
+
def url
|
74
|
+
controller.store_brand_path(record) if record.id
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Liquid
|
2
|
+
class Context
|
3
|
+
def handle_error(old_error, template = nil, line = nil)
|
4
|
+
e = old_error.is_a?(Liquid::Error) ? old_error : internal_error
|
5
|
+
e.template_name ||= template
|
6
|
+
e.line_number ||= line
|
7
|
+
ShoperbLiquid.config.error_notify(old_error, e.template_name, e.line_number)
|
8
|
+
errors.push(e)
|
9
|
+
exception_renderer.call(e).to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
module Models
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# some currently necessary
|
8
|
+
# models + some potentially
|
9
|
+
# necessary in future
|
10
|
+
MODELS = [
|
11
|
+
:Address,
|
12
|
+
:BlogPost,
|
13
|
+
:BlogCategory,
|
14
|
+
:Cart,
|
15
|
+
:CartItem,
|
16
|
+
:Category,
|
17
|
+
:Collection,
|
18
|
+
:Country,
|
19
|
+
:Currency,
|
20
|
+
:Customer,
|
21
|
+
:Discount,
|
22
|
+
:Image,
|
23
|
+
:Language,
|
24
|
+
:Link,
|
25
|
+
:MediaFile,
|
26
|
+
:Menu,
|
27
|
+
:Order,
|
28
|
+
:OrderItem,
|
29
|
+
:Page,
|
30
|
+
:PaymentMethod,
|
31
|
+
:Product,
|
32
|
+
:ProductAttribute,
|
33
|
+
:ProductType,
|
34
|
+
:ProductSearch,
|
35
|
+
:Shop,
|
36
|
+
:Theme,
|
37
|
+
:Variant,
|
38
|
+
:VariantAttribute,
|
39
|
+
:Vendor,
|
40
|
+
:CustomField,
|
41
|
+
:CustomerSubscriptionPlan,
|
42
|
+
].freeze
|
43
|
+
|
44
|
+
# Regardless whether client models are namespaced or not,
|
45
|
+
# we create same constansts under ShoperbLiquid namespace,
|
46
|
+
# so access to them would be easier from drops
|
47
|
+
def shadow
|
48
|
+
MODELS.each do |model_name|
|
49
|
+
namespace = ShoperbLiquid.config.models_namespace
|
50
|
+
absolute_klass_name = "::" + [namespace, model_name].compact.join("::")
|
51
|
+
ShoperbLiquid.const_set(model_name, absolute_klass_name.constantize)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ShoperbLiquid
|
2
|
+
module AssetFilters
|
3
|
+
include ActionView::Helpers::AssetTagHelper
|
4
|
+
|
5
|
+
def stylesheet_tag(url, media=:screen)
|
6
|
+
check_asset_defined_in_spec(url, :stylesheets)
|
7
|
+
|
8
|
+
tag :link, rel: :stylesheet, type: Mime[:css], media: media, href: url
|
9
|
+
end
|
10
|
+
|
11
|
+
def javascript_tag(url)
|
12
|
+
check_asset_defined_in_spec(url, :javascripts)
|
13
|
+
|
14
|
+
content_tag :script, "", type: Mime[:js], src: url
|
15
|
+
end
|
16
|
+
|
17
|
+
def icon_tag(url)
|
18
|
+
tags = ""
|
19
|
+
tags << tag(:link, rel: "icon", type: "image/vnd.microsoft.icon", href: url)
|
20
|
+
tags << "\n"
|
21
|
+
tags << tag(:link, rel: "shortcut icon", href: url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_tag(url, alt=nil, title=nil)
|
25
|
+
tag :img, alt: h(alt), src: url, title: h(title)
|
26
|
+
end
|
27
|
+
|
28
|
+
def style_tag(data, id=nil)
|
29
|
+
content_tag :style, data, type: "text/css", id: id
|
30
|
+
end
|
31
|
+
|
32
|
+
def asset_url(path)
|
33
|
+
ShoperbLiquid.config.file_system.absolute_asset_path(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
# legacy
|
37
|
+
def preview_asset_url(path)
|
38
|
+
asset_url(path)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def check_asset_defined_in_spec(url, type)
|
44
|
+
return unless ShoperbLiquid.env.theme_development?
|
45
|
+
|
46
|
+
relative_url = url.gsub(/\/system\/assets\/#{type}\//, "")
|
47
|
+
|
48
|
+
unless (compiled_assets[type] || []).include?(relative_url)
|
49
|
+
raise ShoperbLiquid::Error, "#{type.to_s.singularize.titleize} #{relative_url} is not defined in SPEC, but served"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def compiled_assets
|
54
|
+
@compiled_assets ||= (@context.registers[:theme].spec.try(:compile) || {}).symbolize_keys
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|