dugway 1.0.6 → 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: 9b9aebab8254f2fde9e8d76861a518a9732344e71cf6cca8ee936e5aba942ea4
4
- data.tar.gz: 21bb8d6c9afe28bb55c657611be93ffe022ef9f1ffb57ac8a588203b03b5df05
3
+ metadata.gz: 4c29856362aa6781513881924c2ffdab292d4a1a3a401c91d11e4ef1f7389a43
4
+ data.tar.gz: 8676516fc4b26c415f78e31558f1df5814dddb55c80221e0507f5793343f8d2e
5
5
  SHA512:
6
- metadata.gz: 2a1b8d896e55523ac33f0bc89b79beaa7dc41cde66035d30e924df536fadd2126ec9a8f657032850fe05f580d7d5cf221cb61a3520b5c58d35fcb6046a543c33
7
- data.tar.gz: 997bfb03509c4c315bc56d619a5deba8135e1e4e6a5cb68a75b7233f91f6c6061f1c86bb2230522a657d609240ca8810971f1a795b383924ae0a72d06ca8b8a2
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)
data/lib/dugway/theme.rb CHANGED
@@ -98,13 +98,82 @@ module Dugway
98
98
 
99
99
  @errors << 'Missing theme name in source/settings.json' if name.blank?
100
100
  @errors << 'Invalid theme version in source/settings.json (ex: 1.0.3)' unless !!(version =~ /\d+\.\d+\.\d+/)
101
- @errors << 'Missing images in source/images' if image_files.empty?
101
+
102
+ if settings['preset_styles']
103
+ validate_preview
104
+ if settings['preset_styles']['presets']
105
+ settings['preset_styles']['presets'].each do |preset|
106
+ validate_preset_styles(preset)
107
+ validate_style_references(preset)
108
+ end
109
+ else
110
+ @errors << "Missing presets"
111
+ end
112
+ end
102
113
 
103
114
  @errors.empty?
104
115
  end
105
116
 
106
117
  private
107
118
 
119
+ def validate_preview
120
+ preview = settings['preset_styles']['preview']
121
+ if preview
122
+ %w[title_font body_font text_color background_color].each do |key|
123
+ @errors << "Missing #{key} in preview" unless preview[key]
124
+ end
125
+ else
126
+ @errors << "Missing preview in preset_styles"
127
+ end
128
+ end
129
+
130
+ def validate_preset_styles(preset)
131
+ @errors << 'Preset is missing group_name' unless preset['group_name'].is_a?(String)
132
+ @errors << 'Preset is missing styles' unless preset['styles'].is_a?(Array)
133
+
134
+ preset['styles'].each do |style|
135
+ @errors << 'Style is missing style_name' unless style['style_name'].is_a?(String)
136
+
137
+ if style['fonts'].is_a?(Hash) && !style['fonts'].empty?
138
+ style['fonts'].each_value do |font|
139
+ @errors << 'Font value should be a string' unless font.is_a?(String)
140
+ end
141
+ else
142
+ @errors << 'Style is missing fonts'
143
+ end
144
+
145
+ if style['colors'].is_a?(Hash) && !style['colors'].empty?
146
+ style['colors'].each do |key, color|
147
+ @errors << 'Invalid color format' unless color =~ /^#[0-9A-Fa-f]{6}$/
148
+ end
149
+ else
150
+ @errors << 'Style is missing colors'
151
+ end
152
+ end
153
+
154
+ @errors << 'Style names should be unique' unless preset['styles'].map { |style| style['style_name'] }.uniq.length == preset['styles'].length
155
+ end
156
+
157
+ def validate_style_references(preset)
158
+ ['fonts', 'colors'].each do |key_type|
159
+ validate_keys(preset, settings[key_type], key_type)
160
+ end
161
+ end
162
+
163
+ def validate_keys(preset, settings, key_type)
164
+ variables = settings.map { |item| item['variable'] }
165
+
166
+ preset['styles'].each do |style|
167
+ style_keys = style[key_type].keys
168
+
169
+ extra_keys = style_keys - variables
170
+ missing_keys = variables - style_keys
171
+
172
+ @errors << "Extra #{key_type} keys: #{extra_keys.join(', ')}" unless extra_keys.empty?
173
+ @errors << "Missing #{key_type} keys: #{missing_keys.join(', ')}" unless missing_keys.empty?
174
+ end
175
+ end
176
+
108
177
  def source_dir
109
178
  Dugway.source_dir
110
179
  end
@@ -1,3 +1,3 @@
1
1
  module Dugway
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -38,13 +38,50 @@
38
38
  "variable": "header_font",
39
39
  "label": "Header Font",
40
40
  "default": "Helvetica"
41
- },
41
+ },
42
42
  {
43
43
  "variable": "font",
44
44
  "label": "Font",
45
45
  "default": "Georgia"
46
46
  }
47
47
  ],
48
+ "preset_styles": {
49
+ "preview": {
50
+ "title_font": "header_font",
51
+ "body_font": "font",
52
+ "text_color": "link_color",
53
+ "background_color": "background_color"
54
+ },
55
+ "presets": [
56
+ {
57
+ "group_name": "Classic",
58
+ "styles": [
59
+ {
60
+ "style_name": "Classic #1",
61
+ "fonts": {
62
+ "header_font": "DM Sans",
63
+ "font": "DM Sans"
64
+ },
65
+ "colors": {
66
+ "background_color": "#FFFFFF",
67
+ "link_color": "#111111"
68
+ }
69
+ },
70
+ {
71
+ "style_name": "Classic #2",
72
+ "fonts": {
73
+ "header_font": "Lora",
74
+ "font": "Roboto"
75
+ },
76
+ "colors": {
77
+ "background_color": "#F7F7F7",
78
+ "link_color": "#222222"
79
+ }
80
+ }
81
+ ]
82
+ }
83
+ ]
84
+ },
48
85
  "colors": [
49
86
  {
50
87
  "variable": "background_color",
@@ -151,7 +151,7 @@ describe Dugway::Theme do
151
151
  end
152
152
 
153
153
  describe "#font_files" do
154
- it "shoud return an array of all font files" do
154
+ it "should return an array of all font files" do
155
155
  theme.font_files.should include("fonts/icons.ttf", "fonts/icons.woff")
156
156
  end
157
157
  end
@@ -210,28 +210,15 @@ describe Dugway::Theme do
210
210
  end
211
211
  end
212
212
 
213
- describe "when missing at least one image" do
214
- before(:each) do
215
- theme.stub(:image_files) { [] }
216
- end
217
-
218
- it "should not be valid" do
219
- theme.valid?.should be(false)
220
- theme.errors.size.should == 1
221
- theme.errors.first.should == 'Missing images in source/images'
222
- end
223
- end
224
-
225
213
  describe "when there are several errors" do
226
214
  before(:each) do
227
215
  theme.stub(:name) { nil }
228
216
  theme.stub(:version) { nil }
229
- theme.stub(:image_files) { [] }
230
217
  end
231
218
 
232
219
  it "should return all of them" do
233
220
  theme.valid?.should be(false)
234
- theme.errors.size.should == 3
221
+ theme.errors.size.should == 2
235
222
  end
236
223
  end
237
224
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dugway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Big Cartel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-12 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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
@@ -577,7 +578,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
577
578
  - !ruby/object:Gem::Version
578
579
  version: '0'
579
580
  requirements: []
580
- rubygems_version: 3.0.3.1
581
+ rubygems_version: 3.2.3
581
582
  signing_key:
582
583
  specification_version: 4
583
584
  summary: Easily build and test Big Cartel themes.