bookshop-array-structures 1.4.7 → 2.0.0.pre.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +11 -0
- data/Gemfile.lock +109 -0
- data/Rakefile +14 -0
- data/bookshop-array-structures.gemspec +1 -0
- data/lib/bookshop-array-structures.rb +154 -14
- data/lib/bookshop-array-structures/version.rb +1 -1
- metadata +27 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2b80104056e78915d6eedc29619a34914c07c8a5b5d6bc04ec1d28b0d96337a
|
4
|
+
data.tar.gz: a14718cdcfd503cbef9c185ad812bd995ef03abeef5e22eb54557a7a67cb8a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eba54c7c2e53f66d953e48aac1fcd0f4fc2a8991539e0ca929fdcc7d73015525beb9ce0e3cf42938cb8bff7c4bb3e762531984805ce37791fca88eaec3a3765
|
7
|
+
data.tar.gz: 5a421d4799a3a30fe06deadc927c1e7bfe060c4c8586e63b50dff2391129429a1640c67838351c2be1096f0dc0d69be7859dd8ac1986c136621d1fc4ab8c78a7
|
data/Gemfile
ADDED
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]
|
@@ -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.
|
22
|
-
|
23
|
-
|
24
|
-
|
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])
|
62
|
+
next
|
63
|
+
end
|
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
|
25
90
|
next
|
26
91
|
end
|
27
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!(
|
186
|
+
result["value"].merge!(handle_legacy_story(story, site))
|
82
187
|
end
|
83
188
|
}
|
84
189
|
result["array_structures"] ||= [];
|
@@ -90,17 +195,41 @@ module Bookshop
|
|
90
195
|
return result
|
91
196
|
end
|
92
197
|
|
93
|
-
def self.
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
+
|
221
|
+
def self.build_from_location(base_path, site)
|
98
222
|
site.config["_select_data"] ||= {}
|
99
223
|
site.config["_array_structures"] ||= {}
|
100
|
-
puts "📚 Parsing Stories
|
101
|
-
Dir.glob("**/*.stories.{toml,tml,tom,tm}", base: base_path).each do |f|
|
224
|
+
puts "📚 Parsing Stories from #{base_path}"
|
225
|
+
Dir.glob("**/*.{bookshop,stories}.{toml,tml,tom,tm}", base: base_path).each do |f|
|
102
226
|
begin
|
103
|
-
|
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
|
104
233
|
rescue => exception
|
105
234
|
puts "❌ Error Parsing Story: " + f
|
106
235
|
puts exception
|
@@ -119,8 +248,19 @@ module Bookshop
|
|
119
248
|
end
|
120
249
|
}
|
121
250
|
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def self.build_array_structures(site)
|
254
|
+
bookshop_locations = site.config['bookshop_locations']&.collect do |location|
|
255
|
+
Pathname.new(location + "/components").cleanpath.to_s
|
256
|
+
end
|
257
|
+
bookshop_locations = bookshop_locations.select do |location|
|
258
|
+
Dir.exist?(location)
|
259
|
+
end
|
260
|
+
bookshop_locations.each do |base_path|
|
261
|
+
build_from_location(base_path, site)
|
262
|
+
end
|
122
263
|
puts "✅ Finshed Parsing Stories"
|
123
|
-
#puts site.config["_array_structures"].inspect
|
124
264
|
end
|
125
265
|
end
|
126
266
|
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:
|
4
|
+
version: 2.0.0.pre.alpha.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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:
|
103
|
+
version: 1.3.1
|
81
104
|
requirements: []
|
82
105
|
rubygems_version: 3.0.3
|
83
106
|
signing_key:
|