bookshop-array-structures 1.4.5 → 2.0.0.pre.alpha.3

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: d9c01f665a4a513af227820d73178c650ada11a5083c4d2c6870dd7f601bae0b
4
- data.tar.gz: d2962ed392eed80038c4be7bdf3e391d185cc992cc33913276eea71f82827544
3
+ metadata.gz: 6738d08d84522a5465442dcfdba331e599e1d24db2298e8fc60ae474dc097f41
4
+ data.tar.gz: c7ecfde99307b8756bc24cc175421735869d013760dd5311b26e6a39c8ce7ff4
5
5
  SHA512:
6
- metadata.gz: 4542176f7a9b5df942c7c492a1c0ab8bb5f8f5b14bdcd484fe66ce6c4bc9e360fa8d25b610533540073e087fdf722a9e31b18c4e57d4f1da3d6ea5e541e248ba
7
- data.tar.gz: 652a9618a21a82dbfe11f9ddfc1dfbb5fcc66dea3b5a6a6db174b621ffd81e9f3b80241b9b4e4762383dc597b0ab042b4e6cd52cc7f86b0462b10110ead032e8
6
+ metadata.gz: 2441b86eebcee962023cc93266905d04ec5e95609ba5cb42089fd727fc7d4264a26d89cd78e68a0206f8fa0460b2c869b87ab7979e487179aca645ee1ee2ab88
7
+ data.tar.gz: ce87689acdc1e21fc509612e6477d8aea56ca4ec9b98e93a0db38cbd72eb5dc95ccc56bb04145de945e7603ce74da3cf8da215e110ed5544c1eb5b8d7d5bd7e0
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,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bookshop-array-structures (1.6.1)
5
+ jekyll (>= 3.7, < 5.0)
6
+ toml-rb (>= 2.0, < 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ansi (1.5.0)
14
+ ast (2.4.2)
15
+ builder (3.2.4)
16
+ citrus (3.0.2)
17
+ colorator (1.1.0)
18
+ concurrent-ruby (1.1.8)
19
+ em-websocket (0.5.2)
20
+ eventmachine (>= 0.12.9)
21
+ http_parser.rb (~> 0.6.0)
22
+ eventmachine (1.2.7)
23
+ ffi (1.15.1)
24
+ forwardable-extended (2.6.0)
25
+ hashdiff (1.0.1)
26
+ http_parser.rb (0.6.0)
27
+ i18n (1.8.10)
28
+ concurrent-ruby (~> 1.0)
29
+ jekyll (4.2.0)
30
+ addressable (~> 2.4)
31
+ colorator (~> 1.0)
32
+ em-websocket (~> 0.5)
33
+ i18n (~> 1.0)
34
+ jekyll-sass-converter (~> 2.0)
35
+ jekyll-watch (~> 2.0)
36
+ kramdown (~> 2.3)
37
+ kramdown-parser-gfm (~> 1.0)
38
+ liquid (~> 4.0)
39
+ mercenary (~> 0.4.0)
40
+ pathutil (~> 0.9)
41
+ rouge (~> 3.0)
42
+ safe_yaml (~> 1.0)
43
+ terminal-table (~> 2.0)
44
+ jekyll-sass-converter (2.1.0)
45
+ sassc (> 2.0.1, < 3.0)
46
+ jekyll-watch (2.2.1)
47
+ listen (~> 3.0)
48
+ kramdown (2.3.1)
49
+ rexml
50
+ kramdown-parser-gfm (1.1.0)
51
+ kramdown (~> 2.0)
52
+ liquid (4.0.3)
53
+ listen (3.5.1)
54
+ rb-fsevent (~> 0.10, >= 0.10.3)
55
+ rb-inotify (~> 0.9, >= 0.9.10)
56
+ mercenary (0.4.0)
57
+ minitest (5.14.4)
58
+ minitest-reporters (1.4.3)
59
+ ansi
60
+ builder
61
+ minitest (>= 5.0)
62
+ ruby-progressbar
63
+ parallel (1.20.1)
64
+ parser (2.7.2.0)
65
+ ast (~> 2.4.1)
66
+ pathutil (0.16.2)
67
+ forwardable-extended (~> 2.6)
68
+ powerpack (0.1.3)
69
+ public_suffix (4.0.6)
70
+ rainbow (2.2.2)
71
+ rake
72
+ rake (10.5.0)
73
+ rb-fsevent (0.11.0)
74
+ rb-inotify (0.10.1)
75
+ ffi (~> 1.0)
76
+ rexml (3.2.5)
77
+ rouge (3.26.0)
78
+ rubocop (0.51.0)
79
+ parallel (~> 1.10)
80
+ parser (>= 2.3.3.1, < 3.0)
81
+ powerpack (~> 0.1)
82
+ rainbow (>= 2.2.2, < 3.0)
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (~> 1.0, >= 1.0.1)
85
+ ruby-progressbar (1.11.0)
86
+ safe_yaml (1.0.5)
87
+ sassc (2.4.0)
88
+ ffi (~> 1.9)
89
+ terminal-table (2.0.0)
90
+ unicode-display_width (~> 1.1, >= 1.1.1)
91
+ toml-rb (2.0.1)
92
+ citrus (~> 3.0, > 3.0)
93
+ unicode-display_width (1.7.0)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ bookshop-array-structures!
100
+ hashdiff
101
+ minitest
102
+ minitest-reporters
103
+ rake
104
+ rubocop (~> 0.51.0)
105
+
106
+ BUNDLED WITH
107
+ 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]
@@ -1,22 +1,102 @@
1
1
  require "jekyll"
2
+ require 'pathname'
2
3
  require "toml-rb"
3
4
 
4
5
  module Bookshop
5
6
  class ArrayStructures
6
7
  def self.get_story_name(path)
7
- basename = path.split("/").last.split(".").first
8
- return basename.split("-").map(&:capitalize).join(" ")
8
+ basename = get_component_type(path)
9
+ return basename.split(/-|\//).map(&:capitalize).join(" ")
9
10
  end
10
11
 
11
- def self.transform_component(path, component, site)
12
- result = {}
13
- result['_component_type'] = path.split(".").first;
14
- component.each_pair { |storyname, story|
15
- story.each_pair {|key, value|
16
- if result.has_key?(key) && storyname != "defaults"
12
+ def self.get_component_type(path)
13
+ result = path.split(".").first;
14
+ pathParts = path.split(".").first.split("/")
15
+ if pathParts.length >= 2 && pathParts[pathParts.length-1] === pathParts[pathParts.length-2]
16
+ pathParts.pop
17
+ result = pathParts.join("/")
18
+ end
19
+ return result
20
+ end
21
+
22
+ def self.handle_props_object(props, result)
23
+ end
24
+
25
+ def self.handle_bookprops(value_obj, structure, value_context = nil)
26
+ structure["_select_data"] ||= {}
27
+ structure["_array_structures"] ||= {}
28
+ structure["_comments"] ||= {}
29
+ structure["value"] ||= {}
30
+ value_context = structure["value"] if value_context.nil?
31
+ value_obj.each_pair {|key, value|
32
+ if value_context.has_key?(key)
33
+ next
34
+ end
35
+
36
+ if value.is_a? Hash
37
+ comment = value["--bookshop_comment"] ||
38
+ value["default--bookshop_comment"] ||
39
+ value["select--bookshop_comment"] ||
40
+ value["preview--bookshop_comment"]
41
+ if comment
42
+ structure["_comments"][key] = comment
43
+ end
44
+ unless value["default"].nil?
45
+ value_context[key] = value["default"]
46
+ next
47
+ end
48
+ if value["select"]
49
+ value_context[key] = nil
50
+ structure["_select_data"][key+"s"] = value["select"]
51
+ next
52
+ end
53
+ if value["preview"]
54
+ value_context[key] = nil
55
+ next
56
+ end
57
+ value_context[key] ||= {}
58
+ handle_bookprops(value, structure, value_context[key])
17
59
  next
18
60
  end
19
61
 
62
+ if value.is_a? Array
63
+ if value[0]&.is_a? Hash
64
+ if value[0]["--bookshop_comment"]
65
+ structure["_comments"][key] = value[0]["--bookshop_comment"]
66
+ end
67
+
68
+ structure["_array_structures"][key] ||= {"values" => [{"value" => {}}]}
69
+ handle_bookprops( value[0],
70
+ structure["_array_structures"][key]["values"][0],
71
+ structure["_array_structures"][key]["values"][0]["value"])
72
+ value_context[key] = []
73
+ next
74
+ end
75
+ value_context[key] = value
76
+ end
77
+
78
+ if [true, false].include? value
79
+ value_context[key] = value
80
+ next
81
+ end
82
+
83
+ if key.include? "--bookshop_comment"
84
+ actual_key = key.split("--").first
85
+ next if actual_key == ""
86
+ structure["_comments"][actual_key] = value
87
+ next
88
+ end
89
+
90
+ value_context[key] = nil
91
+ }
92
+ end
93
+
94
+
95
+ def self.handle_legacy_story(story, site)
96
+ result = {};
97
+ story.each_pair {|key, value|
98
+ next unless result.has_key?(key) && storyname != "defaults"
99
+
20
100
  if key.include? "--repeat"
21
101
  new_key = key.split("--").first
22
102
  result[new_key] = []
@@ -52,31 +132,125 @@ module Bookshop
52
132
  end
53
133
  site.config["_select_data"][new_key].push(option)
54
134
  }
135
+ elsif key.include? "--"
136
+ new_key = key.split("--").first
137
+ result[new_key] = nil
55
138
  else
56
139
  result[key] = value
57
140
  end
58
141
  }
59
- }
142
+ return result
143
+ end
144
+
145
+ def self.transform_component(path, component, site)
146
+ unless component["defaults"].nil?
147
+ return transform_legacy_component(path, component, site)
148
+ end
149
+ result = { "value" => {} }
150
+ result["label"] = get_story_name(path)
151
+ result["value"]["_bookshop_name"] = get_component_type(path)
152
+ unless component["component"].nil?
153
+ result.merge!(component["component"])
154
+ end
155
+ unless component["props"].nil?
156
+ handle_bookprops(component["props"] || {}, result)
157
+ end
158
+ result["array_structures"] ||= [];
159
+ already_in_global_array = result["array_structures"].select{|value| value == 'bookshop_components'}.length > 0
160
+ if !already_in_global_array && !result["_hidden"]
161
+ result["array_structures"].push("bookshop_components")
162
+ end
163
+ result.delete("_hidden") unless result["_hidden"].nil?
60
164
  return result
61
165
  end
62
166
 
63
- def self.build_array_structures(site)
64
- base_path = ""
65
- if !site.theme.nil?
66
- base_path = site.theme.root + "/_bookshop/components/"
167
+ def self.transform_legacy_component(path, component, site)
168
+ puts "📚 Parsing legacy stories.toml config file"
169
+ result = { "value" => {} }
170
+ result["label"] = get_story_name(path)
171
+ result["value"]["_component_type"] = get_component_type(path)
172
+ component.each_pair { |storyname, story|
173
+ if storyname == "meta"
174
+ result.merge!(story)
175
+ else
176
+ result["value"].merge!(handle_legacy_story(story, site))
177
+ end
178
+ }
179
+ result["array_structures"] ||= [];
180
+ contains_component = result["array_structures"].select{|value| value == 'components'}.length > 0
181
+ if !contains_component && !result["_hidden"]
182
+ result["array_structures"].push("components")
67
183
  end
184
+ result.delete("_hidden") unless result["_hidden"].nil?
185
+ return result
186
+ end
187
+
188
+ def self.rewrite_bookshop_toml(content)
189
+ rewritten_lines = content.split("\n")&.collect { |line|
190
+ if line =~ /^[a-z0-9\-_\.\s]+=.*?#.+?$/i
191
+ /#:(?<comment>[^#]+)$/i =~ line
192
+ /^\s*?(?<variable_name>[a-z0-9\-_\.]+)\s?=/i =~ line
193
+ next line unless comment && variable_name
194
+
195
+ next "#{variable_name}--bookshop_comment = \"#{comment.strip}\"\n#{line}"
196
+ elsif line =~ /^\s*?\[.*?#.+?$/i
197
+ /#:(?<comment>[^#]+)$/i =~ line
198
+ next line unless comment
199
+ next "#{line}\n--bookshop_comment = \"#{comment.strip}\""
200
+ end
201
+ line
202
+ }
203
+ rewritten_lines.join("\n")
204
+ end
205
+
206
+ def self.parse_bookshop_toml(content)
207
+ rewritten_content = rewrite_bookshop_toml(content)
208
+ return TomlRB.parse(rewritten_content)
209
+ end
210
+
211
+ def self.build_from_location(base_path, site)
68
212
  site.config["_select_data"] ||= {}
69
213
  site.config["_array_structures"] ||= {}
70
- site.config["_array_structures"]["components"] ||= {
71
- "values" => []
72
- }
73
- Dir.glob("**/*.stories.{toml,tml,tom,tm}", base: base_path).each do |f|
74
- component = TomlRB.load_file(base_path + f)
75
- site.config["_array_structures"]["components"]["values"].push({
76
- "label" => get_story_name(f),
77
- "value" => transform_component(f, component, site)
78
- })
214
+ puts "📚 Parsing Stories from #{base_path}"
215
+ Dir.glob("**/*.{bookshop,stories}.{toml,tml,tom,tm}", base: base_path).each do |f|
216
+ begin
217
+ if f =~ /bookshop/
218
+ raw_file = File.read(base_path + "/" + f)
219
+ component = parse_bookshop_toml(raw_file)
220
+ else
221
+ component = TomlRB.load_file(base_path + f)
222
+ end
223
+ rescue => exception
224
+ puts "❌ Error Parsing Story: " + f
225
+ puts exception
226
+ next
227
+ end
228
+ transformed_component = transform_component(f, component, site)
229
+ array_structures = transformed_component.delete("array_structures")
230
+ array_structures.each{|key|
231
+ begin
232
+ site.config["_array_structures"][key] ||= {}
233
+ site.config["_array_structures"][key]["values"] ||= []
234
+ site.config["_array_structures"][key]["values"].push(transformed_component)
235
+ rescue => exception
236
+ puts "❌ Error Adding Story to Array Structures: " + f
237
+ puts "🤔 Maybe your current _config.yml has conflicting array structures?"
238
+ end
239
+ }
240
+ end
241
+ end
242
+
243
+ def self.build_array_structures(site)
244
+ bookshop_locations = site.config['bookshop_locations']&.collect do |location|
245
+ Pathname.new(location + "/components").cleanpath.to_s
246
+ end
247
+ bookshop_locations = bookshop_locations.select do |location|
248
+ Dir.exist?(location)
249
+ end
250
+ bookshop_locations.each do |base_path|
251
+ build_from_location(base_path, site)
79
252
  end
253
+ puts "✅ Finshed Parsing Stories"
80
254
  end
81
255
  end
82
256
  end
@@ -1,5 +1,5 @@
1
1
  module Bookshop
2
2
  module Arraystructures
3
- VERSION = "1.4.5"
3
+ VERSION = "2.0.0.pre.alpha.3"
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.4.5
4
+ version: 2.0.0.pre.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tate
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-22 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -50,13 +50,16 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '3.0'
53
- description:
53
+ description:
54
54
  email:
55
55
  - tate@cloudcannon.com
56
56
  executables: []
57
57
  extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - Rakefile
60
63
  - bookshop-array-structures.gemspec
61
64
  - lib/bookshop-array-structures.rb
62
65
  - lib/bookshop-array-structures/version.rb
@@ -64,7 +67,7 @@ homepage: https://github.com/cloudcannon/bookshop
64
67
  licenses:
65
68
  - MIT
66
69
  metadata: {}
67
- post_install_message:
70
+ post_install_message:
68
71
  rdoc_options: []
69
72
  require_paths:
70
73
  - lib
@@ -75,12 +78,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
78
  version: 2.3.0
76
79
  required_rubygems_version: !ruby/object:Gem::Requirement
77
80
  requirements:
78
- - - ">="
81
+ - - ">"
79
82
  - !ruby/object:Gem::Version
80
- version: '0'
83
+ version: 1.3.1
81
84
  requirements: []
82
85
  rubygems_version: 3.0.3
83
- signing_key:
86
+ signing_key:
84
87
  specification_version: 4
85
88
  summary: A Jekyll plugin to generate array structures from bookshop
86
89
  test_files: []