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

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: e016f11ca04b0775464f53babe0820e58b83718a16ec4f224cacea8da3dedd42
4
- data.tar.gz: e5d3aaf4e8f513b8e7fad77c54d60749f14b3dcb32bd7d7201060d8b14c498e5
3
+ metadata.gz: eb6e86e2d0e14e8231bf8dbef51cc5a22d5e4cd4f5828845ba7a1bac23c4631d
4
+ data.tar.gz: 7bb542b48d431ae9c743c75c4d675f8f33432d23e442a538ef7cbdf88c5264cd
5
5
  SHA512:
6
- metadata.gz: f0b9b88aefaa1c26206102ea822c9d43c58012488ecde7e454bf67e43a55c4942be3cd790bb312e1dad42e82ab2d99b941336b2343e2e85ca1565a4aa89243e7
7
- data.tar.gz: 7d0c2f8005406396fb20923d4f4fe4391d96ff0fca9fd282653fa1fe0b09a4d0a67cf6e861f730c78187e8a1d75b986c5cceed5ff141cacf8c02b998376316ac
6
+ metadata.gz: 330d33cb9371f8e230f8e1289d31ac8692245f3f48b8f240df760ae814e75983e0141b086a2a2819163c085efe67be21c3baeb38625e525e24d243e44b8b7ff5
7
+ data.tar.gz: c9457ba7304e920421674ecd79993c22dbad0efedeacc3ed53285eba4b48de1cf6bae37751a631062f42e946a3ab9def3190cf39343be940d11e6f075e533d63
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,4 +1,5 @@
1
1
  require "jekyll"
2
+ require 'pathname'
2
3
  require "toml-rb"
3
4
 
4
5
  module Bookshop
@@ -18,13 +19,84 @@ module Bookshop
18
19
  return result
19
20
  end
20
21
 
21
- def self.handle_story(story, site)
22
- result = {};
23
- story.each_pair {|key, value|
24
- if result.has_key?(key) && storyname != "defaults"
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])
25
59
  next
26
60
  end
27
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
+
28
100
  if key.include? "--repeat"
29
101
  new_key = key.split("--").first
30
102
  result[new_key] = []
@@ -71,6 +143,29 @@ module Bookshop
71
143
  end
72
144
 
73
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?
164
+ return result
165
+ end
166
+
167
+ def self.transform_legacy_component(path, component, site)
168
+ puts "📚 Parsing legacy stories.toml config file"
74
169
  result = { "value" => {} }
75
170
  result["label"] = get_story_name(path)
76
171
  result["value"]["_component_type"] = get_component_type(path)
@@ -78,7 +173,7 @@ module Bookshop
78
173
  if storyname == "meta"
79
174
  result.merge!(story)
80
175
  else
81
- result["value"].merge!(handle_story(story, site))
176
+ result["value"].merge!(handle_legacy_story(story, site))
82
177
  end
83
178
  }
84
179
  result["array_structures"] ||= [];
@@ -90,13 +185,41 @@ module Bookshop
90
185
  return result
91
186
  end
92
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
+
93
211
  def self.build_from_location(base_path, site)
94
212
  site.config["_select_data"] ||= {}
95
213
  site.config["_array_structures"] ||= {}
96
214
  puts "📚 Parsing Stories from #{base_path}"
97
- Dir.glob("**/*.stories.{toml,tml,tom,tm}", base: base_path).each do |f|
215
+ Dir.glob("**/*.{bookshop,stories}.{toml,tml,tom,tm}", base: base_path).each do |f|
98
216
  begin
99
- component = TomlRB.load_file(base_path + f)
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
100
223
  rescue => exception
101
224
  puts "❌ Error Parsing Story: " + f
102
225
  puts exception
@@ -118,15 +241,16 @@ module Bookshop
118
241
  end
119
242
 
120
243
  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/")
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)
124
249
  end
125
- base_paths.each do |base_path|
250
+ bookshop_locations.each do |base_path|
126
251
  build_from_location(base_path, site)
127
252
  end
128
253
  puts "✅ Finshed Parsing Stories"
129
- #puts site.config["_array_structures"].inspect
130
254
  end
131
255
  end
132
256
  end
@@ -1,5 +1,5 @@
1
1
  module Bookshop
2
2
  module Arraystructures
3
- VERSION = "1.6.1"
3
+ VERSION = "2.0.0-alpha.2"
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.2
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-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -57,6 +57,9 @@ 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
@@ -75,9 +78,9 @@ 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
86
  signing_key: