scaffold_parser 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/scaffold_parser +5 -1
- data/lib/scaffold_parser/nokogiri_patches.rb +14 -9
- data/lib/scaffold_parser/scaffolders/xsd/builder.rb +106 -0
- data/lib/scaffold_parser/scaffolders/xsd/parser.rb +80 -72
- data/lib/scaffold_parser/scaffolders/xsd.rb +107 -17
- data/lib/scaffold_parser.rb +26 -1
- data/scaffold_parser.gemspec +2 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9ecbc5c73c858c25d5f97806fb148720065dcae
|
4
|
+
data.tar.gz: ca3a1f63c84c8dc18c08f6d8099167eb884797fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4490d4c87ef3d9512b6b69997705ca613b62f788ee77d95b7df721b97dab4e397f8995a7fced42aae3ffb58b2a02138df6e70591d70dd2b8e08f90b880fae9d
|
7
|
+
data.tar.gz: efdd40de39de53466c90a607b2d301b6aa4c1d9345478091440140d57391fbee9c712855c0c2c74e3946d2fa6639f90fc91460df349d1b9899d0dd6c25958445
|
data/bin/scaffold_parser
CHANGED
@@ -10,9 +10,13 @@ abort 'Path to schema file as a first argument is required' unless path
|
|
10
10
|
OptionParser.new do |opts|
|
11
11
|
opts.banner = 'Usage: scaffold_parser <path_to_schema> [options]'
|
12
12
|
|
13
|
-
opts.on(
|
13
|
+
opts.on('-nNAMESPACE', '--namespace=NAMESPACE', 'Output all classes in given namespace') do |v|
|
14
14
|
options[:namespace] = v
|
15
15
|
end
|
16
|
+
|
17
|
+
opts.on('-v', '--verbose', 'Run verbosely') do |v|
|
18
|
+
options[:verbose] = v
|
19
|
+
end
|
16
20
|
end.parse!
|
17
21
|
|
18
22
|
ScaffoldParser.scaffold(path, options)
|
@@ -18,15 +18,15 @@ module ScaffoldParser
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def submodel_nodes
|
21
|
-
attribute_elements.select(&:parent_type?) + extension.submodel_nodes
|
21
|
+
@submodel_nodes ||= attribute_elements.select(&:parent_type?) + extension.submodel_nodes
|
22
22
|
end
|
23
23
|
|
24
24
|
def value_nodes
|
25
|
-
attribute_elements.select(&:end_type?) + extension.value_nodes
|
25
|
+
@value_nodes ||= attribute_elements.select(&:end_type?) + extension.value_nodes
|
26
26
|
end
|
27
27
|
|
28
28
|
def array_nodes
|
29
|
-
attribute_elements.select(&:list_type?) + extension.array_nodes
|
29
|
+
@array_nodes ||= attribute_elements.select(&:list_type?) + extension.array_nodes
|
30
30
|
end
|
31
31
|
|
32
32
|
def end_type?
|
@@ -57,7 +57,7 @@ module ScaffoldParser
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def named_list?
|
60
|
-
definition.list_element.present? && definition.list_element.max_occurs > 1
|
60
|
+
!simple_list? && definition.list_element.present? && definition.list_element.max_occurs > 1
|
61
61
|
end
|
62
62
|
|
63
63
|
def list_element
|
@@ -89,11 +89,12 @@ module ScaffoldParser
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def definition
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
@definition ||=
|
93
|
+
if self['type'].present? && !self['type'].start_with?('xs:')
|
94
|
+
find_type(self['type'])
|
95
|
+
else
|
96
|
+
self
|
97
|
+
end
|
97
98
|
end
|
98
99
|
|
99
100
|
def extension
|
@@ -184,6 +185,10 @@ module ScaffoldParser
|
|
184
185
|
def array_nodes
|
185
186
|
[]
|
186
187
|
end
|
188
|
+
|
189
|
+
def definition
|
190
|
+
self
|
191
|
+
end
|
187
192
|
end
|
188
193
|
end
|
189
194
|
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module ScaffoldParser
|
2
|
+
module Scaffolders
|
3
|
+
class XSD
|
4
|
+
class Builder
|
5
|
+
attr_reader :node
|
6
|
+
|
7
|
+
def self.call(node, options)
|
8
|
+
self.new(node, options).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(node, options)
|
12
|
+
@node = node
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
puts "Scaffolding builder for #{node.to_name}" if @options[:verbose]
|
18
|
+
|
19
|
+
f = StringIO.new
|
20
|
+
f.indent = true if @options[:namespace]
|
21
|
+
|
22
|
+
f.puts "require '#{namespaced('builders/base_builder')}'"
|
23
|
+
requires = node.submodel_nodes.map { |n| n.to_class_name.underscore }.uniq
|
24
|
+
requires.each { |r| f.puts "require '#{namespaced(r.prepend('builders/'))}'" }
|
25
|
+
requires = node.array_nodes.reject { |l| l.list_element.xs_type? }.uniq
|
26
|
+
requires.each { |n| f.puts "require '#{namespaced(n.list_element.to_class_name.underscore.prepend('builders/'))}'" }
|
27
|
+
f.puts
|
28
|
+
|
29
|
+
f.puts "module #{@options[:namespace]}" if @options[:namespace]
|
30
|
+
f.putsi "module Builders"
|
31
|
+
f.putsi " class #{node.to_class_name}"
|
32
|
+
f.putsi " include BaseBuilder"
|
33
|
+
f.puts
|
34
|
+
|
35
|
+
f.putsi " def builder"
|
36
|
+
f.putsi " root = Ox::Element.new(element_name)"
|
37
|
+
|
38
|
+
node.value_nodes.each do |node|
|
39
|
+
f.puts
|
40
|
+
f.putsi " if attributes.key? :#{node.to_name.underscore}"
|
41
|
+
f.putsi " element = Ox::Element.new('#{node.to_name}')"
|
42
|
+
f.putsi " element << attributes[:#{node.to_name.underscore}] if attributes[:#{node.to_name.underscore}]"
|
43
|
+
f.putsi " root << element"
|
44
|
+
f.putsi " end"
|
45
|
+
end
|
46
|
+
|
47
|
+
node.submodel_nodes.each do |node|
|
48
|
+
f.puts
|
49
|
+
f.putsi " if attributes.key? :#{node.to_name.underscore}"
|
50
|
+
f.putsi " root << #{node.to_class_name}.new(attributes[:#{node.to_name.underscore}], '#{node.to_name}').builder"
|
51
|
+
f.putsi " end"
|
52
|
+
end
|
53
|
+
|
54
|
+
node.array_nodes.reject { |l| l.list_element.xs_type? }.each do |node|
|
55
|
+
if node.named_list?
|
56
|
+
f.puts
|
57
|
+
f.putsi " if attributes.key? :#{node.to_name.underscore}"
|
58
|
+
f.putsi " element = Ox::Element.new('#{node.to_name}')"
|
59
|
+
f.putsi " attributes[:#{node.to_name.underscore}].each { |i| element << #{node.list_element.to_class_name}.new(i, '#{node.list_element.to_name}').builder }"
|
60
|
+
f.putsi " root << element"
|
61
|
+
f.putsi " end"
|
62
|
+
else # simple_list
|
63
|
+
f.puts
|
64
|
+
f.putsi " if attributes.key? :#{node.to_name.underscore}"
|
65
|
+
f.putsi " attributes[:#{node.to_name.underscore}].each { |i| root << #{node.list_element.to_class_name}.new(i, '#{node.list_element.to_name}').builder }"
|
66
|
+
f.putsi " end"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
node.array_nodes.select { |l| l.list_element.xs_type? }.each do |node|
|
71
|
+
f.puts
|
72
|
+
|
73
|
+
if node.named_list?
|
74
|
+
f.putsi " if attributes.key? :#{node.to_name.underscore}"
|
75
|
+
f.putsi " element = Ox::Element.new('#{node.to_name}')"
|
76
|
+
f.putsi " attributes[:#{node.to_name.underscore}].map { |i| Ox::Element.new('#{node.list_element.to_name}') << i }.each { |i| element << i }"
|
77
|
+
f.putsi " root << element"
|
78
|
+
f.putsi " end"
|
79
|
+
else #simple_list
|
80
|
+
f.putsi " if attributes.key? :#{node.to_name.underscore}"
|
81
|
+
f.putsi " attributes[:#{node.to_name.underscore}].map { |i| Ox::Element.new('#{node.to_name}') << i }.each { |i| root << i }"
|
82
|
+
f.putsi " end"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
f.puts
|
87
|
+
f.putsi " root"
|
88
|
+
f.putsi " end"
|
89
|
+
|
90
|
+
|
91
|
+
f.putsi " end"
|
92
|
+
f.putsi "end"
|
93
|
+
f.puts "end" if @options[:namespace]
|
94
|
+
|
95
|
+
["builders/#{node.to_class_name.underscore}.rb", f.string.strip]
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def namespaced(path)
|
101
|
+
[@options[:namespace]&.underscore, path].compact.join('/')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -14,97 +14,105 @@ module ScaffoldParser
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call
|
17
|
-
|
17
|
+
puts "Scaffolding parser for #{node.to_name}" if @options[:verbose]
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
f = StringIO.new
|
20
|
+
f.indent = true if @options[:namespace]
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
f.puts "require '#{namespaced('parsers/base_parser')}'"
|
23
|
+
node.submodel_nodes.map { |n| namespaced(n.to_class_name.underscore.prepend('parsers/')) }.uniq.each { |n| f.puts "require '#{n}'" }
|
24
|
+
node.array_nodes.reject { |l| l.list_element.xs_type? }.each { |n| f.puts "require '#{namespaced(n.list_element.to_class_name.underscore.prepend('parsers/'))}'" }
|
25
|
+
f.puts
|
26
|
+
|
27
|
+
f.puts "module #{@options[:namespace]}" if @options[:namespace]
|
28
|
+
f.putsi "module Parsers"
|
29
|
+
f.putsi " class #{node.to_class_name}"
|
30
|
+
f.putsi " include BaseParser"
|
31
|
+
|
32
|
+
node.value_nodes.each do |method|
|
25
33
|
f.puts
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
f.putsi " include BaseElement"
|
35
|
+
method_name = method.to_name.underscore
|
36
|
+
at = method.to_name
|
30
37
|
|
31
|
-
|
32
|
-
|
38
|
+
f.putsi " def #{method_name}"
|
39
|
+
f.putsi " at :#{at}"
|
40
|
+
f.putsi " end"
|
41
|
+
end
|
33
42
|
|
34
|
-
|
35
|
-
|
43
|
+
node.submodel_nodes.each do |method|
|
44
|
+
f.puts
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
46
|
+
klass = method.to_class_name
|
47
|
+
method_name = method.to_name.underscore
|
48
|
+
at = method.to_name
|
41
49
|
|
42
|
-
|
43
|
-
|
50
|
+
f.putsi " def #{method_name}"
|
51
|
+
f.putsi " submodel_at(#{klass}, :#{at})"
|
52
|
+
f.putsi " end"
|
53
|
+
end
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
at = method.to_name
|
55
|
+
node.array_nodes.reject { |l| l.list_element.xs_type? }.each do |method|
|
56
|
+
f.puts
|
48
57
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
58
|
+
list_element_klass = method.list_element_klass
|
59
|
+
method_name = method.to_name.underscore
|
60
|
+
list_element_at = method.list_element_at.map { |e| ":#{e}" }.join(', ')
|
53
61
|
|
54
|
-
|
55
|
-
|
62
|
+
f.putsi " def #{method_name}"
|
63
|
+
f.putsi " array_of_at(#{list_element_klass}, [#{list_element_at}])"
|
64
|
+
f.putsi " end"
|
65
|
+
end
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
list_element_at = method.list_element_at.map { |e| ":#{e}" }.join(', ')
|
67
|
+
node.array_nodes.select { |l| l.list_element.xs_type? }.each do |method|
|
68
|
+
f.puts
|
60
69
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
70
|
+
list_element_klass = method.list_element_klass
|
71
|
+
method_name = method.to_name.underscore
|
72
|
+
list_element_at = method.list_element_at.map { |e| ":#{e}" }.join(', ')
|
65
73
|
|
66
|
-
|
67
|
-
|
74
|
+
f.putsi " def #{method_name}"
|
75
|
+
f.putsi " array_of_at(String, [#{list_element_at}])"
|
76
|
+
f.putsi " end"
|
77
|
+
end
|
68
78
|
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
### to_h method
|
80
|
+
lines = []
|
81
|
+
node.value_nodes.each do |node|
|
82
|
+
lines << "hash[:#{node.to_name.underscore}] = #{node.to_name.underscore} if raw.key? :#{node.to_name}"
|
83
|
+
end
|
72
84
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
85
|
+
node.submodel_nodes.each do |node|
|
86
|
+
lines << "hash[:#{node.to_name.underscore}] = #{node.to_name.underscore}.to_h if raw.key? :#{node.to_name}"
|
87
|
+
end
|
88
|
+
node.array_nodes.reject { |l| l.list_element.xs_type? }.each do |node|
|
89
|
+
lines << "hash[:#{node.to_name.underscore}] = #{node.to_name.underscore}.map(&:to_h) if raw.key? :#{node.to_name}"
|
90
|
+
end
|
91
|
+
node.array_nodes.select { |l| l.list_element.xs_type? }.each do |node|
|
92
|
+
lines << "hash[:#{node.to_name.underscore}] = #{node.to_name.underscore} if raw.key? :#{node.to_name}"
|
93
|
+
end
|
94
|
+
if lines.any?
|
95
|
+
f.puts
|
96
|
+
# lines.last.chop!
|
97
|
+
# first_line = lines.shift
|
77
98
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
lines << "#{node.to_name.underscore}: #{node.to_name.underscore}.to_h,"
|
85
|
-
end
|
86
|
-
node.array_nodes.reject { |l| l.list_element.xs_type? }.each do |node|
|
87
|
-
lines << "#{node.to_name.underscore}: #{node.to_name.underscore}.map(&:to_h),"
|
88
|
-
end
|
89
|
-
node.array_nodes.select { |l| l.list_element.xs_type? }.each do |node|
|
90
|
-
lines << "#{node.to_name.underscore}: #{node.to_name.underscore},"
|
91
|
-
end
|
92
|
-
if lines.any?
|
93
|
-
f.puts
|
94
|
-
lines.last.chop!
|
95
|
-
first_line = lines.shift
|
96
|
-
|
97
|
-
f.putsi " def to_h"
|
98
|
-
f.putsi " { #{first_line}"
|
99
|
-
lines.each do |line|
|
100
|
-
f.putsi " #{line}"
|
101
|
-
end
|
102
|
-
f.putsi " }.delete_if { |k, v| v.nil? || v.empty? }"
|
103
|
-
f.putsi " end"
|
99
|
+
f.putsi " def to_h"
|
100
|
+
f.putsi " hash = {}"
|
101
|
+
f.puts
|
102
|
+
|
103
|
+
lines.each do |line|
|
104
|
+
f.putsi " #{line}"
|
104
105
|
end
|
105
|
-
f.
|
106
|
-
|
106
|
+
f.puts
|
107
|
+
|
108
|
+
f.putsi " hash"
|
109
|
+
f.putsi " end"
|
107
110
|
end
|
111
|
+
f.putsi " end"
|
112
|
+
f.putsi "end"
|
113
|
+
f.puts "end" if @options[:namespace]
|
114
|
+
|
115
|
+
["parsers/#{node.to_class_name.underscore}.rb", f.string.strip]
|
108
116
|
end
|
109
117
|
|
110
118
|
private
|
@@ -1,40 +1,130 @@
|
|
1
1
|
require 'scaffold_parser/scaffolders/xsd/parser'
|
2
|
+
require 'scaffold_parser/scaffolders/xsd/builder'
|
2
3
|
|
3
4
|
module ScaffoldParser
|
4
5
|
module Scaffolders
|
5
6
|
class XSD
|
6
|
-
def self.call(doc, options
|
7
|
-
self.new(doc, options
|
7
|
+
def self.call(doc, options)
|
8
|
+
self.new(doc, options).call
|
8
9
|
end
|
9
10
|
|
10
|
-
def initialize(doc, options
|
11
|
+
def initialize(doc, options)
|
11
12
|
@doc = doc
|
12
13
|
@options = options
|
13
|
-
@already_scaffolded_subelements = already_scaffolded_subelements
|
14
14
|
end
|
15
15
|
|
16
16
|
def call
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
17
|
+
puts "Starting collectiong elements to scaffold" if @options[:verbose]
|
18
|
+
|
19
|
+
unscaffolded_elements = collect_unscaffolded_subelements(@doc) + @doc.submodel_nodes
|
21
20
|
|
22
|
-
|
23
|
-
@already_scaffolded_subelements << subelement.to_class_name
|
21
|
+
puts "Collected #{unscaffolded_elements.size} elements to scaffold" if @options[:verbose]
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
code = unscaffolded_elements.flat_map do |element|
|
24
|
+
[Parser.call(element.definition, @options), Builder.call(element.definition, @options)]
|
27
25
|
end
|
26
|
+
|
27
|
+
code.push ['parsers/base_parser.rb', base_element_template]
|
28
|
+
code.push ['builders/base_builder.rb', base_builder_template]
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
all
|
33
|
+
def collect_unscaffolded_subelements(node, collected = [])
|
34
|
+
subelements = node.definition.submodel_nodes.to_a + node.definition.array_nodes.map(&:list_element)
|
36
35
|
.reject(&:xs_type?)
|
37
|
-
.reject { |node|
|
36
|
+
.reject { |node| collected.include?(node.to_class_name) }
|
37
|
+
|
38
|
+
subelements.each do |element|
|
39
|
+
if collected.none? { |c| c.to_class_name == element.to_class_name }
|
40
|
+
collected << element
|
41
|
+
|
42
|
+
puts "Collected #{element.to_name} element" if @options[:verbose]
|
43
|
+
|
44
|
+
collect_unscaffolded_subelements(element, collected)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
collected
|
49
|
+
end
|
50
|
+
|
51
|
+
def base_element_template
|
52
|
+
<<~TEMPLATE
|
53
|
+
module Parsers
|
54
|
+
module BaseParser
|
55
|
+
EMPTY_ARRAY = []
|
56
|
+
|
57
|
+
attr_accessor :raw
|
58
|
+
|
59
|
+
def initialize(raw)
|
60
|
+
@raw = raw
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def at(locator)
|
66
|
+
return nil if raw.nil?
|
67
|
+
|
68
|
+
raw[locator]
|
69
|
+
end
|
70
|
+
|
71
|
+
def submodel_at(klass, locator)
|
72
|
+
element_xml = at locator
|
73
|
+
|
74
|
+
klass.new(element_xml) if element_xml
|
75
|
+
end
|
76
|
+
|
77
|
+
def array_of_at(klass, locator)
|
78
|
+
return EMPTY_ARRAY if raw.nil?
|
79
|
+
|
80
|
+
elements = raw.dig(*locator) || EMPTY_ARRAY
|
81
|
+
if elements.is_a?(Hash) || elements.is_a?(String)
|
82
|
+
elements = [elements]
|
83
|
+
end
|
84
|
+
|
85
|
+
elements.map do |raw|
|
86
|
+
klass.new(raw)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def all(locator)
|
91
|
+
return EMPTY_ARRAY if raw.nil?
|
92
|
+
|
93
|
+
result = raw[locator]
|
94
|
+
|
95
|
+
if result.is_a? Hash
|
96
|
+
[result]
|
97
|
+
elsif result.is_a? Array
|
98
|
+
result
|
99
|
+
else
|
100
|
+
EMPTY_ARRAY
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
TEMPLATE
|
106
|
+
end
|
107
|
+
|
108
|
+
def base_builder_template
|
109
|
+
<<~TEMPLATE
|
110
|
+
module Builders
|
111
|
+
module BaseBuilder
|
112
|
+
attr_accessor :attributes, :element_name
|
113
|
+
|
114
|
+
def initialize(attributes = {}, element_name)
|
115
|
+
@element_name = element_name
|
116
|
+
@attributes = attributes || {}
|
117
|
+
end
|
118
|
+
|
119
|
+
def to_xml
|
120
|
+
doc = Ox::Document.new(version: '1.0')
|
121
|
+
doc << builder
|
122
|
+
|
123
|
+
Ox.dump(doc, with_xml: true)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
TEMPLATE
|
38
128
|
end
|
39
129
|
end
|
40
130
|
end
|
data/lib/scaffold_parser.rb
CHANGED
@@ -6,10 +6,35 @@ require 'scaffold_parser/scaffolders/xsd'
|
|
6
6
|
|
7
7
|
Nokogiri::XML::Element.include ScaffoldParser::NokogiriPatches::Element
|
8
8
|
Nokogiri::XML::Document.include ScaffoldParser::NokogiriPatches::Document
|
9
|
-
|
9
|
+
StringIO.include ScaffoldParser::FilePatches
|
10
10
|
|
11
11
|
module ScaffoldParser
|
12
12
|
def self.scaffold(path, options = {})
|
13
|
+
unless Dir.exists?('./tmp/')
|
14
|
+
Dir.mkdir('./tmp/')
|
15
|
+
puts './tmp/ directory created'
|
16
|
+
end
|
17
|
+
|
18
|
+
unless Dir.exists?('./tmp/builders')
|
19
|
+
Dir.mkdir('./tmp/builders')
|
20
|
+
puts './tmp/builders directory created'
|
21
|
+
end
|
22
|
+
|
23
|
+
unless Dir.exists?('./tmp/parsers')
|
24
|
+
Dir.mkdir('./tmp/parsers')
|
25
|
+
puts './tmp/parsers directory created'
|
26
|
+
end
|
27
|
+
|
28
|
+
scaffold_to_string(path, options).each do |path, content|
|
29
|
+
complete_path = path.prepend('./tmp/')
|
30
|
+
|
31
|
+
puts "Writing out #{complete_path}" if options[:verbose]
|
32
|
+
|
33
|
+
File.open(complete_path, 'wb') { |f| f.write content }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.scaffold_to_string(path, options = {})
|
13
38
|
doc = Nokogiri::XML(File.open(path))
|
14
39
|
|
15
40
|
Scaffolders::XSD.call(doc, options)
|
data/scaffold_parser.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'scaffold_parser'
|
6
|
-
spec.version = '0.
|
6
|
+
spec.version = '0.3.0'
|
7
7
|
spec.authors = ['Premysl Donat']
|
8
8
|
spec.email = ['pdonat@seznam.cz']
|
9
9
|
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'pry'
|
26
26
|
spec.add_development_dependency 'nokogiri'
|
27
27
|
spec.add_development_dependency 'activesupport'
|
28
|
+
spec.add_development_dependency 'saharspec'
|
28
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffold_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Premysl Donat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: saharspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: ''
|
98
112
|
email:
|
99
113
|
- pdonat@seznam.cz
|
@@ -116,6 +130,7 @@ files:
|
|
116
130
|
- lib/scaffold_parser/file_patches.rb
|
117
131
|
- lib/scaffold_parser/nokogiri_patches.rb
|
118
132
|
- lib/scaffold_parser/scaffolders/xsd.rb
|
133
|
+
- lib/scaffold_parser/scaffolders/xsd/builder.rb
|
119
134
|
- lib/scaffold_parser/scaffolders/xsd/parser.rb
|
120
135
|
- scaffold_parser.gemspec
|
121
136
|
homepage: https://github.com/Masa331/scaffold_parser
|