dugway 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8390ef193bc160dedfcd4745df7b5b96e2bb702b10bd3cd9794cd7f951edc03d
4
- data.tar.gz: bbba535b7d2c34823c50bdac3f83418ad74091063fc3cd6957fe1f70a36a0145
3
+ metadata.gz: 4c29856362aa6781513881924c2ffdab292d4a1a3a401c91d11e4ef1f7389a43
4
+ data.tar.gz: 8676516fc4b26c415f78e31558f1df5814dddb55c80221e0507f5793343f8d2e
5
5
  SHA512:
6
- metadata.gz: ecc5b434330a537eba7f403815975fbff7fbec5d1ab3256fc324392fdde90bd8228cd741897517ba92464a0a2023cf870d579ddd2fd192a27667b5d3d4098c9a
7
- data.tar.gz: 2557195c107df99b5ae72cfd027d6a4c43463b4d2c39b8a2d5022ddf4bdeab5d2c3fe34efdba8fff6bb5b5777fcdc39cf0ba5f14ff7c9f0c31dda507d081ab01
6
+ metadata.gz: d7ffa6f534fcb3d51f14de4168906a2b7dbfab08689ac8d61136df08ffa848458d94fdbdacf17db43611d40c3ebf208759d3ca49a10781d58e02b53c740f295c
7
+ data.tar.gz: 32186c12dd6696cf6b41904c253a414cb25a7af2f19f0ff45e29c5dbc7212bb09703bac52b0ba9e9216bce4b645af30a62d77de9d96e3c0b5f075758425d5b45
@@ -0,0 +1,67 @@
1
+ module Dugway
2
+ module Filters
3
+ module InstantCheckoutFilter
4
+ DIV_STYLES = [
5
+ "border-radius: 4px",
6
+ "font-size: 20px",
7
+ "font-weight: bold"
8
+ ].freeze
9
+
10
+ LINK_STYLES = [
11
+ "border-radius: 4px",
12
+ "height: 100%",
13
+ "display: flex",
14
+ "padding: 10px",
15
+ "align-items: center",
16
+ "justify-content: center"
17
+ ].freeze
18
+
19
+ def instant_checkout_button(account, a=nil, b=nil)
20
+ account = @context.registers[:account]
21
+ theme, height = sanitize_options(a, b)
22
+
23
+ return nil unless account.instant_checkout?
24
+
25
+ div_styles = generate_div_styles(theme, height)
26
+ link_styles = generate_link_styles(theme)
27
+
28
+ %(<div id="instant-checkout-button" style="#{ div_styles }"><a href="https://www.bigcartel.com/resources/help/article/apple-pay" style="#{ link_styles }">Instant Checkout</a></div>)
29
+ end
30
+
31
+ private
32
+
33
+ def sanitize_options(a, b)
34
+ theme = height = nil
35
+
36
+ [a, b].each do |value|
37
+ theme = value if /\A(dark|light(?:-outline)?)\z/.match(value)
38
+ height = value if /\A\d+(px|em|\%)\z/.match(value)
39
+ end
40
+
41
+ return theme, height
42
+ end
43
+
44
+ def generate_div_styles(theme, height)
45
+ styles = DIV_STYLES.dup
46
+ styles << "border: 1px solid black" if theme == "light-outline"
47
+ styles << "height: #{ height }" if height
48
+ styles << colors(theme)
49
+ styles.join("; ")
50
+ end
51
+
52
+ def generate_link_styles(theme)
53
+ styles = LINK_STYLES.dup
54
+ styles << colors(theme)
55
+ styles.join("; ")
56
+ end
57
+
58
+ def colors(theme)
59
+ if theme =~ /\Alight/
60
+ "background-color: white; color: black"
61
+ else
62
+ "background-color: black; color: white"
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -7,6 +7,7 @@ Liquid::Template.register_filter(Dugway::Filters::CoreFilters)
7
7
  Liquid::Template.register_filter(Dugway::Filters::DefaultPagination)
8
8
  Liquid::Template.register_filter(Dugway::Filters::UrlFilters)
9
9
  Liquid::Template.register_filter(Dugway::Filters::FontFilters)
10
+ Liquid::Template.register_filter(Dugway::Filters::InstantCheckoutFilter)
10
11
 
11
12
  Liquid::Template.register_tag(:get, Dugway::Tags::Get)
12
13
  Liquid::Template.register_tag(:paginate, Dugway::Tags::Paginate)
@@ -28,6 +29,7 @@ module Dugway
28
29
  registers = shared_registers
29
30
  registers[:category] = variables[:category]
30
31
  registers[:artist] = variables[:artist]
32
+ registers[:account] = Dugway.store
31
33
 
32
34
  if errors = variables.delete(:errors)
33
35
  shared_context['errors'] << errors
data/lib/dugway/store.rb CHANGED
@@ -127,6 +127,10 @@ module Dugway
127
127
  currency['locale']
128
128
  end
129
129
 
130
+ def instant_checkout?
131
+ Dugway.options.dig(:store, :instant_checkout) || false
132
+ end
133
+
130
134
  private
131
135
 
132
136
  def get(path)
@@ -1,3 +1,3 @@
1
1
  module Dugway
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dugway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Big Cartel
@@ -482,6 +482,7 @@ files:
482
482
  - lib/dugway/liquid/filters/core_filters.rb
483
483
  - lib/dugway/liquid/filters/default_pagination.rb
484
484
  - lib/dugway/liquid/filters/font_filters.rb
485
+ - lib/dugway/liquid/filters/instant_checkout_filter.rb
485
486
  - lib/dugway/liquid/filters/url_filters.rb
486
487
  - lib/dugway/liquid/filters/util_filters.rb
487
488
  - lib/dugway/liquid/tags/get.rb