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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ProductTypeDrop < Base
5
+ def initialize(record)
6
+ @record = record || ProductType.new
7
+ end
8
+
9
+ def id
10
+ record.id
11
+ end
12
+
13
+ def name
14
+ record.name
15
+ end
16
+
17
+ def handle
18
+ record.handle
19
+ end
20
+
21
+ def products
22
+ ProductsDrop.new(record.products.includes(:variants))
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ProductTypesDrop < CollectionDrop
5
+ private
6
+
7
+ def collection
8
+ @collection = ProductType.all if @collection.empty?
9
+ @collection
10
+ end
11
+ end
12
+ end
13
+
14
+
15
+
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ProductsDrop < CollectionDrop
5
+ def initialize(collection=nil)
6
+ @collection = (collection || Product).active.preload(
7
+ :product_attributes, :variants, images: [:image_sizes]
8
+ )
9
+ end
10
+
11
+ def random
12
+ ProductDrop.new(collection.random)
13
+ end
14
+
15
+
16
+ def liquid_method_missing(method, *args)
17
+ if matches = method.to_s.match(/(add_)?order_by_(.*)_(asc|desc)/i)
18
+ order = matches[3]
19
+ rel = collection
20
+ rel = rel.reorder("") unless matches[1] # remove sort if "add_" not added
21
+ @collection = case matches[2]
22
+ when "created"
23
+ rel.by_created(order)
24
+ when "updated"
25
+ rel.by_updated(order)
26
+ when "name"
27
+ rel.by_name(order)
28
+ when "price"
29
+ rel.by_price(order)
30
+ when "product_type"
31
+ rel.by_product_type(order)
32
+ when "tags"
33
+ rel.by_tags(order)
34
+ when "handle"
35
+ rel.by_handle(order)
36
+ else
37
+ collection
38
+ end and self
39
+ else
40
+ super(method)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class RefundDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+ def state
9
+ record.state
10
+ end
11
+ def amount
12
+ record.amount
13
+ end
14
+ def reason
15
+ record.reason
16
+ end
17
+
18
+ def items
19
+ CollectionDrop.new(record.refund_items)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class RefundItemDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+ def count
9
+ record.count
10
+ end
11
+ def order_item_id
12
+ record.order_item_id
13
+ end
14
+ def order_item
15
+ OrderDrop.new(record.order_item)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ReviewDrop < Base
5
+ def initialize(record)
6
+ @record = record || Review.new
7
+ end
8
+
9
+ def id
10
+ record.id
11
+ end
12
+
13
+ def title
14
+ record.title
15
+ end
16
+
17
+ def body
18
+ record.body
19
+ end
20
+
21
+ def rating
22
+ record.rating
23
+ end
24
+
25
+ def created_at
26
+ record.created_at
27
+ end
28
+
29
+ def customer
30
+ CustomerDrop.new(record.customer)
31
+ end
32
+
33
+ def product
34
+ ProductDrop.new(record.product)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class SearchDrop < Base
5
+ def initialize(word="", options={})
6
+ @record = ProductSearch.new(word: word, **options.to_h)
7
+ end
8
+
9
+ def paginate(page=1, search_size=25)
10
+ return self unless searching?
11
+
12
+ page &&= page.to_i
13
+ search_size &&= search_size.to_i
14
+
15
+ record.paginate(page: page, per: search_size)
16
+ end
17
+
18
+ def performed
19
+ record.performed
20
+ end
21
+
22
+ def terms
23
+ record.terms
24
+ end
25
+
26
+ def results
27
+ record.results
28
+ end
29
+
30
+ alias_method :collection, :results
31
+ delegate :any?, :each, :map, to: :results
32
+
33
+ def size
34
+ record.results_size
35
+ end
36
+
37
+ def searching?
38
+ record.searching?
39
+ end
40
+
41
+ def to_curl
42
+ record.to_curl
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ShippingItemDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def product_name
10
+ record.order_item.product.name
11
+ end
12
+
13
+ def order_item
14
+ OrderItemDrop.new(record.order_item)
15
+ end
16
+
17
+ def order_item_id
18
+ OrderItemDrop.new(record.order_item_id)
19
+ end
20
+
21
+ def amount
22
+ record.amount
23
+ end
24
+
25
+ def shipping_date
26
+ record.created_at
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ShippingMethodDrop < Base
5
+ def name
6
+ record.name
7
+ end
8
+
9
+ def rate
10
+ record.rate
11
+ end
12
+
13
+ def provider
14
+ record.provider
15
+ end
16
+
17
+ def provider_box
18
+ record.provider_box
19
+ end
20
+
21
+ def tracking_number
22
+ record.tracking_number
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ShippingParcelDrop < Base
5
+ def barcode
6
+ record.barcode
7
+ end
8
+
9
+ def number
10
+ record.number
11
+ end
12
+
13
+ def state
14
+ record.state
15
+ end
16
+
17
+ def order
18
+ record.order.to_liquid
19
+ end
20
+
21
+ def shipping_items
22
+ CollectionDrop.new(record.shipping_items)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ShopDrop < Base
5
+ def name
6
+ record.name
7
+ end
8
+
9
+ def email
10
+ record.email
11
+ end
12
+
13
+ def domain
14
+ record.external_hostname
15
+ end
16
+
17
+ def meta_title
18
+ record.meta_title
19
+ end
20
+
21
+ def meta_keywords
22
+ record.meta_keywords
23
+ end
24
+
25
+ def meta_description
26
+ record.meta_description
27
+ end
28
+
29
+ def current?
30
+ record.id == shop.id
31
+ end
32
+
33
+ def metric?
34
+ record.metric?
35
+ end
36
+
37
+ def address
38
+ AddressDrop.new(record.address) if record.address
39
+ end
40
+
41
+ def language
42
+ LanguageDrop.new(record.language) if record.language
43
+ end
44
+
45
+ def current_locale
46
+ super
47
+ end
48
+
49
+ def possible_languages
50
+ record.all_languages
51
+ end
52
+
53
+ def currency
54
+ CurrencyDrop.new(record.currency)
55
+ end
56
+
57
+ def account
58
+ AccountDrop.new(record.account)
59
+ end
60
+
61
+ def customer_accounts
62
+ record.customer_accounts
63
+ end
64
+
65
+ def customer_accounts?
66
+ record.customer_accounts != "disabled"
67
+ end
68
+
69
+ def account_types
70
+ record.account_types
71
+ end
72
+
73
+ def google_analytics
74
+ record.tracking_script.try(:google).try(:presence)
75
+ end
76
+
77
+ def reviews?
78
+ record.reviews
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class SubscriptionDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+ def plan
9
+ record.plan.to_liquid
10
+ end
11
+ def auto_collection?
12
+ record.auto_collection
13
+ end
14
+ def active?
15
+ record.active?
16
+ end
17
+ def in_trial?
18
+ record.in_trial?
19
+ end
20
+ def qty
21
+ record.qty
22
+ end
23
+ def starts_at
24
+ record.starts_at
25
+ end
26
+ def ends_at
27
+ record.ends_at
28
+ end
29
+ def trial_starts_at
30
+ record.trial_starts_at
31
+ end
32
+ def trial_ends_at
33
+ record.trial_ends_at
34
+ end
35
+ def deleted?
36
+ record.deleted?
37
+ end
38
+
39
+ def state
40
+ record.state
41
+ end
42
+
43
+ def gift_card_code
44
+ record.gift_card_code
45
+ end
46
+
47
+ def delete_url
48
+ controller.store_account_delete_subscription_path(id)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class SubscriptionPlanDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def name
10
+ record.name
11
+ end
12
+
13
+ def invoice_name
14
+ record.invoice_name
15
+ end
16
+
17
+ def description
18
+ record.description
19
+ end
20
+
21
+ def handle
22
+ record.handle
23
+ end
24
+
25
+ def interval
26
+ record.interval
27
+ end
28
+
29
+ def interval_count
30
+ record.interval_count
31
+ end
32
+
33
+ def price
34
+ record.item_price
35
+ end
36
+
37
+ def setup_cost
38
+ record.setup_cost
39
+ end
40
+
41
+ def trial_interval
42
+ record.trial_interval
43
+ end
44
+
45
+ def trial_interval_count
46
+ record.trial_interval_count
47
+ end
48
+
49
+ def create_subscription_url
50
+ controller.store_account_create_subscription_path(id)
51
+ end
52
+
53
+ def custom_fields
54
+ CustomField.where(klass: record.class.to_s.demodulize, customer_see: true).
55
+ each_with_object({}) do |cf,hash|
56
+ hash[cf.handle] = cf.as_json
57
+ hash[cf.handle]["set_values"] = record.custom_field_values.to_h[cf.handle.to_s]
58
+ hash[cf.handle]["set_values"] ||= cf.default_values if cf.default_values.select(&:present?).present?
59
+ hash[cf.handle]["set_values"] ||= []
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ThemeSectionBlocksDrop < CollectionDrop
5
+ def initialize(collection=nil, order=nil)
6
+ @collection = (collection || []).select do |id, block|
7
+ order.include?(id)
8
+ end
9
+
10
+ @order = order || []
11
+ end
12
+
13
+ def each
14
+ @order.each do |id|
15
+ yield ThemeSectionDrop.new(id, collection[id])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ThemeSectionDrop < Base
5
+ def initialize(id, section)
6
+ @id = id
7
+ @record = section || {}
8
+ end
9
+
10
+ def id
11
+ @id
12
+ end
13
+
14
+ def blocks
15
+ ThemeSectionBlocksDrop.new(record["blocks"], record["block_order"])
16
+ end
17
+
18
+ def settings
19
+ ThemeSectionSettingsDrop.new(record)
20
+ end
21
+
22
+ def updated_at
23
+ record['updated_at']
24
+ end
25
+
26
+ def type
27
+ record["type"]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'image_drop'
4
+
5
+ module ShoperbLiquid
6
+ class ThemeSectionImageDrop < ImageDrop
7
+ def to_s
8
+ record.url
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "theme_settings_drop"
4
+
5
+ module ShoperbLiquid
6
+ class ThemeSectionSettingsDrop < ThemeSettingsDrop
7
+ attr_reader :section
8
+
9
+ def initialize(section)
10
+ @section = section
11
+ @settings = section["settings"] || {}
12
+ @translations = section["translations"] || {}
13
+ @settings = @settings.reverse_merge(@translations[current_locale] || {})
14
+
15
+ @links = section["links"] || {}
16
+
17
+ super(@settings)
18
+ end
19
+
20
+ protected
21
+
22
+ def format_value(key, value)
23
+ res = url(key, value) if @links[key]
24
+ res ||= (@translations[current_locale] || {})[key] || value
25
+ end
26
+
27
+ def url(key, value)
28
+ return unless @links[key]
29
+ return value if @links[key]["style"].in?(immutable_link_styles)
30
+
31
+ "/#{current_locale}#{value}"
32
+ # parsed_path = routes.recognize_path(value)
33
+ # routes.url_for(only_path: true, locale: current_locale, **parsed_path)
34
+ end
35
+
36
+ def immutable_link_styles
37
+ %w(CUSTOM Blank)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ThemeSettingsDrop < Base
5
+ attr_reader :settings
6
+
7
+ def initialize(custom_settings={})
8
+ @settings = custom_settings
9
+
10
+ settings.each do |key, value|
11
+ define_singleton_method key do
12
+ if image = image_object(key)
13
+ ThemeSectionImageDrop.new(image)
14
+ else
15
+ format_value(key, value)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.invokable?(method_name)
22
+ true
23
+ end
24
+
25
+ def method_missing(*args)
26
+ nil
27
+ end
28
+
29
+ private
30
+
31
+ def format_value(key, value)
32
+ value
33
+ end
34
+
35
+ def image_object(handle)
36
+ image_id = settings_images[handle]
37
+ images.detect { |i| i.id == image_id.to_i } if image_id
38
+ end
39
+
40
+ def images
41
+ @images ||= Image.includes(:image_sizes).where(id: image_ids)
42
+ end
43
+
44
+ def image_ids
45
+ settings_images.values
46
+ end
47
+
48
+ def settings_images
49
+ Hash[settings.map do |handle, value|
50
+ if match = value.to_s.match(image_regex)
51
+ [handle, match[:id]]
52
+ end
53
+ end.compact].compact
54
+ end
55
+
56
+ def image_regex
57
+ /shoperb_image:\/\/id:(?<id>\d+)\/\/(.+)/
58
+ end
59
+ end
60
+ end