bookshop-array-structures 1.6.1 → 2.0.0.pre.alpha.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e016f11ca04b0775464f53babe0820e58b83718a16ec4f224cacea8da3dedd42
4
- data.tar.gz: e5d3aaf4e8f513b8e7fad77c54d60749f14b3dcb32bd7d7201060d8b14c498e5
3
+ metadata.gz: b3711c17e1471fd6edbf0ea003a9acf57dfefd5a9f63bf782dc513e2017a68b0
4
+ data.tar.gz: ab98a4c6242250a4fee5bfc65f942b77668e2d9b50a9a1e28edb212571753af9
5
5
  SHA512:
6
- metadata.gz: f0b9b88aefaa1c26206102ea822c9d43c58012488ecde7e454bf67e43a55c4942be3cd790bb312e1dad42e82ab2d99b941336b2343e2e85ca1565a4aa89243e7
7
- data.tar.gz: 7d0c2f8005406396fb20923d4f4fe4391d96ff0fca9fd282653fa1fe0b09a4d0a67cf6e861f730c78187e8a1d75b986c5cceed5ff141cacf8c02b998376316ac
6
+ metadata.gz: a93e89d72c800dddfcd45485f9693b02ea2f2068cea4aff19e63e088986dc79c140eb40531ee76df909040836642401377ede3c50a41ec5ee059d786cc1bce71
7
+ data.tar.gz: 3cd104e743326297fd72e43d46a43e93dd60bd485e77e2585860985eacc6d2a499e75a127918f64ad4ff210300bcd5be16c1c815d4fa1c2a7df0b2cbdb54d8fc
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rubocop", "~> 0.51.0"
7
+ gem "hashdiff"
8
+ gem "rake"
9
+ gem "minitest"
10
+ gem 'minitest-reporters'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bookshop-array-structures (2.0.0.pre.alpha.3)
5
+ dry-inflector (>= 0.1, < 1.0)
6
+ jekyll (>= 3.7, < 5.0)
7
+ toml-rb (>= 2.0, < 3.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ ansi (1.5.0)
15
+ ast (2.4.2)
16
+ builder (3.2.4)
17
+ citrus (3.0.2)
18
+ colorator (1.1.0)
19
+ concurrent-ruby (1.1.8)
20
+ dry-inflector (0.2.0)
21
+ em-websocket (0.5.2)
22
+ eventmachine (>= 0.12.9)
23
+ http_parser.rb (~> 0.6.0)
24
+ eventmachine (1.2.7)
25
+ ffi (1.15.1)
26
+ forwardable-extended (2.6.0)
27
+ hashdiff (1.0.1)
28
+ http_parser.rb (0.6.0)
29
+ i18n (1.8.10)
30
+ concurrent-ruby (~> 1.0)
31
+ jekyll (4.2.0)
32
+ addressable (~> 2.4)
33
+ colorator (~> 1.0)
34
+ em-websocket (~> 0.5)
35
+ i18n (~> 1.0)
36
+ jekyll-sass-converter (~> 2.0)
37
+ jekyll-watch (~> 2.0)
38
+ kramdown (~> 2.3)
39
+ kramdown-parser-gfm (~> 1.0)
40
+ liquid (~> 4.0)
41
+ mercenary (~> 0.4.0)
42
+ pathutil (~> 0.9)
43
+ rouge (~> 3.0)
44
+ safe_yaml (~> 1.0)
45
+ terminal-table (~> 2.0)
46
+ jekyll-sass-converter (2.1.0)
47
+ sassc (> 2.0.1, < 3.0)
48
+ jekyll-watch (2.2.1)
49
+ listen (~> 3.0)
50
+ kramdown (2.3.1)
51
+ rexml
52
+ kramdown-parser-gfm (1.1.0)
53
+ kramdown (~> 2.0)
54
+ liquid (4.0.3)
55
+ listen (3.5.1)
56
+ rb-fsevent (~> 0.10, >= 0.10.3)
57
+ rb-inotify (~> 0.9, >= 0.9.10)
58
+ mercenary (0.4.0)
59
+ minitest (5.14.4)
60
+ minitest-reporters (1.4.3)
61
+ ansi
62
+ builder
63
+ minitest (>= 5.0)
64
+ ruby-progressbar
65
+ parallel (1.20.1)
66
+ parser (2.7.2.0)
67
+ ast (~> 2.4.1)
68
+ pathutil (0.16.2)
69
+ forwardable-extended (~> 2.6)
70
+ powerpack (0.1.3)
71
+ public_suffix (4.0.6)
72
+ rainbow (2.2.2)
73
+ rake
74
+ rake (10.5.0)
75
+ rb-fsevent (0.11.0)
76
+ rb-inotify (0.10.1)
77
+ ffi (~> 1.0)
78
+ rexml (3.2.5)
79
+ rouge (3.26.0)
80
+ rubocop (0.51.0)
81
+ parallel (~> 1.10)
82
+ parser (>= 2.3.3.1, < 3.0)
83
+ powerpack (~> 0.1)
84
+ rainbow (>= 2.2.2, < 3.0)
85
+ ruby-progressbar (~> 1.7)
86
+ unicode-display_width (~> 1.0, >= 1.0.1)
87
+ ruby-progressbar (1.11.0)
88
+ safe_yaml (1.0.5)
89
+ sassc (2.4.0)
90
+ ffi (~> 1.9)
91
+ terminal-table (2.0.0)
92
+ unicode-display_width (~> 1.1, >= 1.1.1)
93
+ toml-rb (2.0.1)
94
+ citrus (~> 3.0, > 3.0)
95
+ unicode-display_width (1.7.0)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ bookshop-array-structures!
102
+ hashdiff
103
+ minitest
104
+ minitest-reporters
105
+ rake
106
+ rubocop (~> 0.51.0)
107
+
108
+ BUNDLED WITH
109
+ 2.1.4
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push 'lib'
6
+ t.libs.push 'specs'
7
+ t.verbose = true
8
+ t.warning = false
9
+ t.pattern = "spec/**/*_spec.rb"
10
+ t.test_files = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ desc "Run tests"
14
+ task :default => [:test]
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
24
24
  spec.add_dependency "toml-rb", ">= 2.0", "< 3.0"
25
+ spec.add_dependency "dry-inflector", ">= 0.1", "< 1.0"
25
26
  end
@@ -1,5 +1,7 @@
1
1
  require "jekyll"
2
+ require "pathname"
2
3
  require "toml-rb"
4
+ require "dry/inflector"
3
5
 
4
6
  module Bookshop
5
7
  class ArrayStructures
@@ -18,13 +20,93 @@ module Bookshop
18
20
  return result
19
21
  end
20
22
 
21
- def self.handle_story(story, site)
22
- result = {};
23
- story.each_pair {|key, value|
24
- if result.has_key?(key) && storyname != "defaults"
23
+ def self.handle_props_object(props, result)
24
+ end
25
+
26
+ def self.handle_bookprops(value_obj, structure, value_context = nil)
27
+ structure["_select_data"] ||= {}
28
+ structure["_array_structures"] ||= {}
29
+ structure["_comments"] ||= {}
30
+ structure["value"] ||= {}
31
+ value_context = structure["value"] if value_context.nil?
32
+ inflector = Dry::Inflector.new
33
+ value_obj.each_pair {|key, value|
34
+ if value_context.has_key?(key)
35
+ next
36
+ end
37
+
38
+ if value.is_a? Hash
39
+ comment = value["--bookshop_comment"] ||
40
+ value["default--bookshop_comment"] ||
41
+ value["select--bookshop_comment"] ||
42
+ value["preview--bookshop_comment"]
43
+ if comment
44
+ structure["_comments"][key] = comment
45
+ end
46
+ unless value["default"].nil?
47
+ value_context[key] = value["default"]
48
+ next
49
+ end
50
+ if value["select"]
51
+ value_context[key] = nil
52
+ plural_key = inflector.pluralize(key)
53
+ structure["_select_data"][plural_key] = value["select"]
54
+ next
55
+ end
56
+ if value["preview"]
57
+ value_context[key] = nil
58
+ next
59
+ end
60
+ value_context[key] ||= {}
61
+ handle_bookprops(value, structure, value_context[key])
25
62
  next
26
63
  end
27
64
 
65
+ if value.is_a? Array
66
+ if value[0]&.is_a? Hash
67
+ if value[0]["--bookshop_comment"]
68
+ structure["_comments"][key] = value[0]["--bookshop_comment"]
69
+ end
70
+
71
+ singular_title = inflector.classify(key).gsub(/(.)([A-Z])/, '\1 \2')
72
+ structure["_array_structures"][key] ||= {
73
+ "values" => [{
74
+ "label" => singular_title,
75
+ "icon" => "add_box",
76
+ "value" => {}
77
+ }]
78
+ }
79
+ handle_bookprops( value[0],
80
+ structure["_array_structures"][key]["values"][0],
81
+ structure["_array_structures"][key]["values"][0]["value"])
82
+ value_context[key] = []
83
+ next
84
+ end
85
+ value_context[key] = value
86
+ end
87
+
88
+ if [true, false].include? value
89
+ value_context[key] = value
90
+ next
91
+ end
92
+
93
+ if key.include? "--bookshop_comment"
94
+ actual_key = key.split("--").first
95
+ next if actual_key == ""
96
+ structure["_comments"][actual_key] = value
97
+ next
98
+ end
99
+
100
+ value_context[key] = nil
101
+ }
102
+ end
103
+
104
+
105
+ def self.handle_legacy_story(story, site)
106
+ result = {};
107
+ story.each_pair {|key, value|
108
+ next unless result.has_key?(key) && storyname != "defaults"
109
+
28
110
  if key.include? "--repeat"
29
111
  new_key = key.split("--").first
30
112
  result[new_key] = []
@@ -71,6 +153,29 @@ module Bookshop
71
153
  end
72
154
 
73
155
  def self.transform_component(path, component, site)
156
+ unless component["defaults"].nil?
157
+ return transform_legacy_component(path, component, site)
158
+ end
159
+ result = { "value" => {} }
160
+ result["label"] = get_story_name(path)
161
+ result["value"]["_bookshop_name"] = get_component_type(path)
162
+ unless component["component"].nil?
163
+ result.merge!(component["component"])
164
+ end
165
+ unless component["props"].nil?
166
+ handle_bookprops(component["props"] || {}, result)
167
+ end
168
+ result["array_structures"] ||= [];
169
+ already_in_global_array = result["array_structures"].select{|value| value == 'bookshop_components'}.length > 0
170
+ if !already_in_global_array && !result["_hidden"]
171
+ result["array_structures"].push("bookshop_components")
172
+ end
173
+ result.delete("_hidden") unless result["_hidden"].nil?
174
+ return result
175
+ end
176
+
177
+ def self.transform_legacy_component(path, component, site)
178
+ puts "📚 Parsing legacy stories.toml config file"
74
179
  result = { "value" => {} }
75
180
  result["label"] = get_story_name(path)
76
181
  result["value"]["_component_type"] = get_component_type(path)
@@ -78,7 +183,7 @@ module Bookshop
78
183
  if storyname == "meta"
79
184
  result.merge!(story)
80
185
  else
81
- result["value"].merge!(handle_story(story, site))
186
+ result["value"].merge!(handle_legacy_story(story, site))
82
187
  end
83
188
  }
84
189
  result["array_structures"] ||= [];
@@ -90,13 +195,41 @@ module Bookshop
90
195
  return result
91
196
  end
92
197
 
198
+ def self.rewrite_bookshop_toml(content)
199
+ rewritten_lines = content.split("\n")&.collect { |line|
200
+ if line =~ /^[a-z0-9\-_\.\s]+=.*?#.+?$/i
201
+ /#:(?<comment>[^#]+)$/i =~ line
202
+ /^\s*?(?<variable_name>[a-z0-9\-_\.]+)\s?=/i =~ line
203
+ next line unless comment && variable_name
204
+
205
+ next "#{variable_name}--bookshop_comment = \"#{comment.strip}\"\n#{line}"
206
+ elsif line =~ /^\s*?\[.*?#.+?$/i
207
+ /#:(?<comment>[^#]+)$/i =~ line
208
+ next line unless comment
209
+ next "#{line}\n--bookshop_comment = \"#{comment.strip}\""
210
+ end
211
+ line
212
+ }
213
+ rewritten_lines.join("\n")
214
+ end
215
+
216
+ def self.parse_bookshop_toml(content)
217
+ rewritten_content = rewrite_bookshop_toml(content)
218
+ return TomlRB.parse(rewritten_content)
219
+ end
220
+
93
221
  def self.build_from_location(base_path, site)
94
222
  site.config["_select_data"] ||= {}
95
223
  site.config["_array_structures"] ||= {}
96
224
  puts "📚 Parsing Stories from #{base_path}"
97
- Dir.glob("**/*.stories.{toml,tml,tom,tm}", base: base_path).each do |f|
225
+ Dir.glob("**/*.{bookshop,stories}.{toml,tml,tom,tm}", base: base_path).each do |f|
98
226
  begin
99
- component = TomlRB.load_file(base_path + f)
227
+ if f =~ /bookshop/
228
+ raw_file = File.read(base_path + "/" + f)
229
+ component = parse_bookshop_toml(raw_file)
230
+ else
231
+ component = TomlRB.load_file(base_path + f)
232
+ end
100
233
  rescue => exception
101
234
  puts "❌ Error Parsing Story: " + f
102
235
  puts exception
@@ -118,15 +251,16 @@ module Bookshop
118
251
  end
119
252
 
120
253
  def self.build_array_structures(site)
121
- base_paths = [site.source + '/_bookshop/components/']
122
- if !site.theme.nil?
123
- base_paths.push(site.theme.root + "/_bookshop/components/")
254
+ bookshop_locations = site.config['bookshop_locations']&.collect do |location|
255
+ Pathname.new("#{site.source}/#{location}/components").cleanpath.to_s
256
+ end
257
+ bookshop_locations = bookshop_locations.select do |location|
258
+ Dir.exist?(location)
124
259
  end
125
- base_paths.each do |base_path|
260
+ bookshop_locations.each do |base_path|
126
261
  build_from_location(base_path, site)
127
262
  end
128
263
  puts "✅ Finshed Parsing Stories"
129
- #puts site.config["_array_structures"].inspect
130
264
  end
131
265
  end
132
266
  end
@@ -1,5 +1,5 @@
1
1
  module Bookshop
2
2
  module Arraystructures
3
- VERSION = "1.6.1"
3
+ VERSION = "2.0.0.pre.alpha.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookshop-array-structures
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 2.0.0.pre.alpha.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tate
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -50,6 +50,26 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '3.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: dry-inflector
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0.1'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0.1'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '1.0'
53
73
  description:
54
74
  email:
55
75
  - tate@cloudcannon.com
@@ -57,6 +77,9 @@ executables: []
57
77
  extensions: []
58
78
  extra_rdoc_files: []
59
79
  files:
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - Rakefile
60
83
  - bookshop-array-structures.gemspec
61
84
  - lib/bookshop-array-structures.rb
62
85
  - lib/bookshop-array-structures/version.rb
@@ -75,9 +98,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
98
  version: 2.3.0
76
99
  required_rubygems_version: !ruby/object:Gem::Requirement
77
100
  requirements:
78
- - - ">="
101
+ - - ">"
79
102
  - !ruby/object:Gem::Version
80
- version: '0'
103
+ version: 1.3.1
81
104
  requirements: []
82
105
  rubygems_version: 3.0.3
83
106
  signing_key: