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.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rubocop.yml +131 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +143 -0
  7. data/Rakefile +4 -0
  8. data/lib/shoperb_liquid/configuration.rb +169 -0
  9. data/lib/shoperb_liquid/drops/account_drop.rb +9 -0
  10. data/lib/shoperb_liquid/drops/address_drop.rb +121 -0
  11. data/lib/shoperb_liquid/drops/array_drop.rb +18 -0
  12. data/lib/shoperb_liquid/drops/attribute_drop.rb +21 -0
  13. data/lib/shoperb_liquid/drops/base.rb +65 -0
  14. data/lib/shoperb_liquid/drops/blog_category_drop.rb +56 -0
  15. data/lib/shoperb_liquid/drops/blog_post_drop.rb +46 -0
  16. data/lib/shoperb_liquid/drops/cart_drop.rb +42 -0
  17. data/lib/shoperb_liquid/drops/cart_item_drop.rb +111 -0
  18. data/lib/shoperb_liquid/drops/categories_drop.rb +13 -0
  19. data/lib/shoperb_liquid/drops/category_drop.rb +110 -0
  20. data/lib/shoperb_liquid/drops/collection_drop.rb +117 -0
  21. data/lib/shoperb_liquid/drops/country_drop.rb +37 -0
  22. data/lib/shoperb_liquid/drops/currency_drop.rb +17 -0
  23. data/lib/shoperb_liquid/drops/customer_credit_drop.rb +23 -0
  24. data/lib/shoperb_liquid/drops/customer_credits_drop.rb +18 -0
  25. data/lib/shoperb_liquid/drops/customer_drop.rb +108 -0
  26. data/lib/shoperb_liquid/drops/customer_group_drop.rb +17 -0
  27. data/lib/shoperb_liquid/drops/gift_card_drop.rb +34 -0
  28. data/lib/shoperb_liquid/drops/image_drop.rb +27 -0
  29. data/lib/shoperb_liquid/drops/integration_drop.rb +25 -0
  30. data/lib/shoperb_liquid/drops/integrations_drop.rb +17 -0
  31. data/lib/shoperb_liquid/drops/language_drop.rb +17 -0
  32. data/lib/shoperb_liquid/drops/link_drop.rb +53 -0
  33. data/lib/shoperb_liquid/drops/media_file_drop.rb +29 -0
  34. data/lib/shoperb_liquid/drops/menu_drop.rb +25 -0
  35. data/lib/shoperb_liquid/drops/menus_drop.rb +16 -0
  36. data/lib/shoperb_liquid/drops/meta_drop.rb +21 -0
  37. data/lib/shoperb_liquid/drops/order_drop.rb +148 -0
  38. data/lib/shoperb_liquid/drops/order_item_attribute_drop.rb +8 -0
  39. data/lib/shoperb_liquid/drops/order_item_attributes_drop.rb +19 -0
  40. data/lib/shoperb_liquid/drops/order_item_drop.rb +159 -0
  41. data/lib/shoperb_liquid/drops/order_return_drop.rb +43 -0
  42. data/lib/shoperb_liquid/drops/order_return_item_drop.rb +30 -0
  43. data/lib/shoperb_liquid/drops/order_return_item_entity_drop.rb +13 -0
  44. data/lib/shoperb_liquid/drops/order_return_parcel_drop.rb +29 -0
  45. data/lib/shoperb_liquid/drops/order_returns_drop.rb +13 -0
  46. data/lib/shoperb_liquid/drops/orders_drop.rb +14 -0
  47. data/lib/shoperb_liquid/drops/page_drop.rb +26 -0
  48. data/lib/shoperb_liquid/drops/pages_drop.rb +12 -0
  49. data/lib/shoperb_liquid/drops/payment_card_drop.rb +29 -0
  50. data/lib/shoperb_liquid/drops/payment_method_drop.rb +41 -0
  51. data/lib/shoperb_liquid/drops/payment_provider_drop.rb +23 -0
  52. data/lib/shoperb_liquid/drops/product_attribute_drop.rb +14 -0
  53. data/lib/shoperb_liquid/drops/product_collection_drop.rb +41 -0
  54. data/lib/shoperb_liquid/drops/product_collections_drop.rb +12 -0
  55. data/lib/shoperb_liquid/drops/product_drop.rb +195 -0
  56. data/lib/shoperb_liquid/drops/product_type_drop.rb +25 -0
  57. data/lib/shoperb_liquid/drops/product_types_drop.rb +15 -0
  58. data/lib/shoperb_liquid/drops/products_drop.rb +44 -0
  59. data/lib/shoperb_liquid/drops/refund_drop.rb +22 -0
  60. data/lib/shoperb_liquid/drops/refund_item_drop.rb +18 -0
  61. data/lib/shoperb_liquid/drops/review_drop.rb +37 -0
  62. data/lib/shoperb_liquid/drops/search_drop.rb +45 -0
  63. data/lib/shoperb_liquid/drops/shipping_item_drop.rb +29 -0
  64. data/lib/shoperb_liquid/drops/shipping_method_drop.rb +25 -0
  65. data/lib/shoperb_liquid/drops/shipping_parcel_drop.rb +25 -0
  66. data/lib/shoperb_liquid/drops/shop_drop.rb +81 -0
  67. data/lib/shoperb_liquid/drops/subscription_drop.rb +51 -0
  68. data/lib/shoperb_liquid/drops/subscription_plan_drop.rb +63 -0
  69. data/lib/shoperb_liquid/drops/theme_section_blocks_drop.rb +19 -0
  70. data/lib/shoperb_liquid/drops/theme_section_drop.rb +30 -0
  71. data/lib/shoperb_liquid/drops/theme_section_image_drop.rb +11 -0
  72. data/lib/shoperb_liquid/drops/theme_section_settings_drop.rb +40 -0
  73. data/lib/shoperb_liquid/drops/theme_settings_drop.rb +60 -0
  74. data/lib/shoperb_liquid/drops/url_drop.rb +218 -0
  75. data/lib/shoperb_liquid/drops/variant_attribute_drop.rb +8 -0
  76. data/lib/shoperb_liquid/drops/variant_drop.rb +206 -0
  77. data/lib/shoperb_liquid/drops/variants_drop.rb +13 -0
  78. data/lib/shoperb_liquid/drops/vendor_drop.rb +77 -0
  79. data/lib/shoperb_liquid/drops/vendors_drop.rb +13 -0
  80. data/lib/shoperb_liquid/errors.rb +6 -0
  81. data/lib/shoperb_liquid/ext/array.rb +7 -0
  82. data/lib/shoperb_liquid/ext/context.rb +12 -0
  83. data/lib/shoperb_liquid/ext/models.rb +55 -0
  84. data/lib/shoperb_liquid/ext/template.rb +13 -0
  85. data/lib/shoperb_liquid/filters/asset_filters.rb +57 -0
  86. data/lib/shoperb_liquid/filters/collection_filters.rb +26 -0
  87. data/lib/shoperb_liquid/filters/datum_filters.rb +150 -0
  88. data/lib/shoperb_liquid/filters/extension_filters.rb +35 -0
  89. data/lib/shoperb_liquid/filters/html_filters.rb +46 -0
  90. data/lib/shoperb_liquid/filters/theme_filters.rb +22 -0
  91. data/lib/shoperb_liquid/filters/translate_filters.rb +16 -0
  92. data/lib/shoperb_liquid/filters/url_filters.rb +60 -0
  93. data/lib/shoperb_liquid/registers.rb +76 -0
  94. data/lib/shoperb_liquid/tags/cache_tag.rb +45 -0
  95. data/lib/shoperb_liquid/tags/form_tag.rb +47 -0
  96. data/lib/shoperb_liquid/tags/layout_tag.rb +21 -0
  97. data/lib/shoperb_liquid/tags/paginate_tag.rb +134 -0
  98. data/lib/shoperb_liquid/tags/products_filter_tag.rb +106 -0
  99. data/lib/shoperb_liquid/tags/section_tag.rb +113 -0
  100. data/lib/shoperb_liquid.rb +46 -0
  101. data/shoperb_liquid.gemspec +24 -0
  102. metadata +223 -0
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class CustomerDrop < Base
5
+ def id
6
+ record&.id
7
+ end
8
+
9
+ def name
10
+ record&.name
11
+ end
12
+
13
+ def first_name
14
+ record.first_name
15
+ end
16
+
17
+ def last_name
18
+ record.last_name
19
+ end
20
+
21
+ def email
22
+ record.email
23
+ end
24
+
25
+ def accepts_newsletter?
26
+ record.newsletter
27
+ end
28
+
29
+ def registred?
30
+ record.active?
31
+ end
32
+
33
+ def discount_pct
34
+ record.discount_pct
35
+ end
36
+
37
+ def last_billing_address
38
+ AddressDrop.new(record.last_bill_address)
39
+ end
40
+
41
+ def last_shipping_address
42
+ AddressDrop.new(record.last_ship_address)
43
+ end
44
+
45
+ def addresses
46
+ CollectionDrop.new(record.addresses)
47
+ end
48
+
49
+ def orders
50
+ OrdersDrop.new(record.orders.sorted)
51
+ end
52
+
53
+ def customer_credits
54
+ CustomerCreditsDrop.new(record.credits)
55
+ end
56
+
57
+ def logged_in?
58
+ record && record.id.present?
59
+ end
60
+
61
+ def recommended_products
62
+ ProductsDrop.new(record.recommended_products)
63
+ end
64
+
65
+ def customer_groups
66
+ record.customer_groups
67
+ end
68
+
69
+ def company?
70
+ record.company?
71
+ end
72
+
73
+ def personal?
74
+ !record.company?
75
+ end
76
+
77
+ def company_name
78
+ record.company_name
79
+ end
80
+
81
+ def vat_number
82
+ record.vat_number
83
+ end
84
+
85
+ def existing_order_returns
86
+ record.existing_order_returns
87
+ end
88
+
89
+ # returns a hash with order id and order with not returned items
90
+ def new_order_returns
91
+ record.new_order_returns
92
+ end
93
+
94
+ def order_returns
95
+ puts "Deprecation Note: Please use new_order_returns method"
96
+ record.new_order_returns
97
+ end
98
+
99
+ # @retturn Integer number of items user hasn't returned
100
+ def not_returned_items
101
+ record.not_returned_items
102
+ end
103
+
104
+ def active_subscriptions
105
+ CollectionDrop.new(record.subscriptions.active)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class CustomerGroupDrop < Base
5
+ def id
6
+ record&.id
7
+ end
8
+
9
+ def name
10
+ record&.name
11
+ end
12
+
13
+ def handle
14
+ record.handle
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class GiftCardDrop < Base
5
+
6
+ def id
7
+ record.id
8
+ end
9
+
10
+ def code
11
+ record.code
12
+ end
13
+
14
+ def status
15
+ record.status
16
+ end
17
+
18
+ def expires_at
19
+ record.expires_at
20
+ end
21
+
22
+ def amount
23
+ record.amount
24
+ end
25
+
26
+ def amount_left
27
+ record.amount_left
28
+ end
29
+
30
+ def owner_email
31
+ record.owner_email
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ImageDrop < Base
5
+ def width
6
+ record.original_width || record.width
7
+ end
8
+
9
+ def height
10
+ record.original_height || record.height
11
+ end
12
+
13
+ def url
14
+ record.url
15
+ end
16
+
17
+ def aspect_ratio
18
+ height * 1.0 / width
19
+ end
20
+
21
+ def liquid_method_missing(method, *args)
22
+ if image = record.image_sizes.detect { |s| s.name == method.to_s }
23
+ ImageDrop.new(image)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class IntegrationDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def name
10
+ record.name
11
+ end
12
+
13
+ def handle
14
+ record.handle
15
+ end
16
+
17
+ def code_layout
18
+ Liquid::Template.parse(record.code["layout"]).render({ "record" => record.settings })
19
+ end
20
+
21
+ def count
22
+ integrations.count
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class IntegrationsDrop < CollectionDrop
5
+ def head
6
+ collection["head"]
7
+ end
8
+
9
+ def start_body
10
+ collection["start_body"]
11
+ end
12
+
13
+ def end_body
14
+ collection["end_body"]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class LanguageDrop < Base
5
+ def name
6
+ record.name
7
+ end
8
+
9
+ def code
10
+ record.code
11
+ end
12
+
13
+ def active?
14
+ record.active?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class LinkDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def url
10
+ record.path(responder: controller)
11
+ end
12
+
13
+ def index_action?
14
+ record.index_action?
15
+ end
16
+
17
+ def menu
18
+ record.menu
19
+ end
20
+
21
+ def name
22
+ record.name
23
+ end
24
+
25
+ def handle
26
+ record.handle
27
+ end
28
+
29
+ def object?
30
+ !record.entity.nil?
31
+ end
32
+
33
+ def object
34
+ record.entity
35
+ end
36
+
37
+ def parent
38
+ record.parent
39
+ end
40
+
41
+ def children
42
+ CollectionDrop.new(record.children)
43
+ end
44
+
45
+ def style
46
+ record.style.try(:underscore)
47
+ end
48
+
49
+ def children?
50
+ record.children.any?
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class MediaFileDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def mime
10
+ record.mime
11
+ end
12
+
13
+ def extension
14
+ record.extension
15
+ end
16
+
17
+ def filename
18
+ record.filename
19
+ end
20
+
21
+ def url
22
+ record.url
23
+ end
24
+
25
+ def image?
26
+ record.image?
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class MenuDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def name
10
+ record.name
11
+ end
12
+
13
+ def handle
14
+ record.handle
15
+ end
16
+
17
+ def links
18
+ CollectionDrop.new(record.links)
19
+ end
20
+
21
+ def root_links
22
+ CollectionDrop.new(record.links.where(parent_id: nil))
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class MenusDrop < CollectionDrop
5
+ def links
6
+ CollectionDrop.new(Link.all)
7
+ end
8
+
9
+ private
10
+
11
+ def collection
12
+ @collection = Menu.all if @collection.empty?
13
+ @collection
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class MetaDrop < Base
5
+ def initialize(record)
6
+ @record = record if record.respond_to?(:has_meta_attributes?)
7
+ end
8
+
9
+ def title
10
+ record.try(:meta_title).blank? ? shop.try(:meta_title) : record.meta_title
11
+ end
12
+
13
+ def description
14
+ record.try(:meta_description).blank? ? shop.try(:meta_description) : record.meta_description
15
+ end
16
+
17
+ def keywords
18
+ record.try(:meta_keywords).blank? ? shop.try(:meta_keywords) : record.meta_keywords
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderDrop < Base
5
+ def name
6
+ "#" + record.number
7
+ end
8
+
9
+ def id
10
+ record.id
11
+ end
12
+
13
+ def number
14
+ record.number
15
+ end
16
+
17
+ def token
18
+ record.token
19
+ end
20
+
21
+ def email
22
+ record.email
23
+ end
24
+
25
+ def total
26
+ record.total
27
+ end
28
+
29
+ def total_items
30
+ record.total_items
31
+ end
32
+
33
+ def total_wo_discount
34
+ record.total_wo_discount
35
+ end
36
+
37
+ def taxation_percentage
38
+ record.taxation_percentage
39
+ end
40
+
41
+ def subtotal
42
+ record.subtotal
43
+ end
44
+
45
+ def subtotal_wo_discount
46
+ record.subtotal_wo_discount
47
+ end
48
+
49
+ def total_shipping
50
+ record.total_shipping
51
+ end
52
+
53
+ def total_taxes
54
+ record.total_taxes
55
+ end
56
+
57
+ def requires_shipping?
58
+ record.require_shipping?
59
+ end
60
+
61
+ def requires_taxation?
62
+ record.require_taxation?
63
+ end
64
+
65
+ def created_at
66
+ record.created_at
67
+ end
68
+
69
+ def state
70
+ record.state
71
+ end
72
+
73
+ def notes
74
+ record.notes
75
+ end
76
+
77
+ def discount_code
78
+ record.discount_code
79
+ end
80
+
81
+ def neto_discount
82
+ record.neto_discount
83
+ end
84
+
85
+ def bruto_discount
86
+ record.bruto_discount
87
+ end
88
+
89
+ def shipping_method
90
+ record.shipping_method.try(:to_liquid)
91
+ end
92
+
93
+ def payment_method
94
+ record.payment_method.try(:to_liquid)
95
+ end
96
+
97
+ def payment_method_name
98
+ record.payment_method.name
99
+ end
100
+
101
+ def billing_address
102
+ AddressDrop.new(record.bill_address)
103
+ end
104
+
105
+ def shipping_address?
106
+ !!record.ship_address
107
+ end
108
+
109
+ def shipping_address
110
+ AddressDrop.new(record.ship_address)
111
+ end
112
+
113
+ def items
114
+ CollectionDrop.new(record.items)
115
+ end
116
+
117
+ def shipping_items
118
+ CollectionDrop.new(record.shipping_items)
119
+ end
120
+
121
+ def refunds
122
+ CollectionDrop.new(record.refunds)
123
+ end
124
+
125
+ def customer
126
+ CustomerDrop.new(record.customer)
127
+ end
128
+
129
+ def currency
130
+ CurrencyDrop.new(record.currency)
131
+ end
132
+
133
+ def url
134
+ controller.store_order_path(number)
135
+ end
136
+
137
+ def payment_url
138
+ unless record.payment_method.succeed?
139
+ routes.store_checkout_order_url(
140
+ id: record.checkout.token,
141
+ state: :payment,
142
+ host: shop.domain
143
+ )
144
+ end
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'attribute_drop'
4
+
5
+ module ShoperbLiquid
6
+ class OrderItemAttributeDrop < AttributeDrop
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module ShoperbLiquid
3
+ class OrderItemAttributesDrop < CollectionDrop
4
+ def initialize(collection=nil)
5
+ @collection = (collection || OrderItemAttribute.none)
6
+ end
7
+
8
+ def from_variant
9
+ @collection = @collection.from_variant
10
+ self
11
+ end
12
+
13
+ def from_product
14
+ @collection = @collection.from_product
15
+ self
16
+ end
17
+
18
+ end
19
+ end