awesome_xml_dsl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/lib/core_extensions.rb +21 -0
- data/lib/xml_dsl.rb +18 -0
- data/lib/xml_dsl/as_one_file.rb +11 -0
- data/lib/xml_dsl/attribute.rb +14 -0
- data/lib/xml_dsl/attribute_options_parser.rb +21 -0
- data/lib/xml_dsl/data_source.rb +27 -0
- data/lib/xml_dsl/generator.rb +43 -0
- data/lib/xml_dsl/options_parser.rb +73 -0
- data/lib/xml_dsl/partial.rb +30 -0
- data/lib/xml_dsl/tag.rb +67 -0
- data/lib/xml_dsl/version.rb +5 -0
- data/xml_dsl.gemspec +31 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42ac9228475c201a5f1dbeba16fd0643f8e49ba7e19ca8e4e4d98fb8f31652f2
|
4
|
+
data.tar.gz: 2e702e09f7b57074d46c2da30fc0e816fda3fef6d4e3ff1ffe0a19c011e135fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 560635f64613ff777f505e69beb33d4b51fbeb05346194bf97d6c36bde326a7a26b60d7a3b5dabb8fd543acc739a848bd860d674ea85c82043fc998f3f37f1a9
|
7
|
+
data.tar.gz: '0729cede90811991feb0606f5d974b1668b1e35befd4a142ce0e5b677ec0bd9d9a7e3926e0b485a68f72548de5e7abcb82a53bba12ef86df939ad66e2d84445f'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at phec06@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xml_dsl (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (12.3.2)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.2)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.4)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
rake (~> 12.0)
|
30
|
+
rspec (~> 3.0)
|
31
|
+
xml_dsl!
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Pedro Bernardes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# XmlDsl
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/xml_dsl`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'xml_dsl'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install xml_dsl
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xml_dsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/xml_dsl/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the XmlDsl project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/xml_dsl/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'xml_dsl'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless Hash.respond_to? :deep_merge
|
4
|
+
class Hash
|
5
|
+
def deep_merge(other_hash, &block)
|
6
|
+
dup.deep_merge!(other_hash, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def deep_merge!(other_hash, &block)
|
10
|
+
merge!(other_hash) do |key, this_val, other_val|
|
11
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
12
|
+
this_val.deep_merge(other_val, &block)
|
13
|
+
elsif block_given?
|
14
|
+
block.call(key, this_val, other_val)
|
15
|
+
else
|
16
|
+
other_val
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/xml_dsl.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'xml_dsl/version'
|
4
|
+
require 'xml_dsl/generator'
|
5
|
+
require 'xml_dsl/tag'
|
6
|
+
require 'xml_dsl/attribute'
|
7
|
+
require 'xml_dsl/partial'
|
8
|
+
require 'xml_dsl/options_parser'
|
9
|
+
require 'xml_dsl/attribute_options_parser'
|
10
|
+
require 'lib/core_extensions'
|
11
|
+
|
12
|
+
module XmlDsl
|
13
|
+
class RequiredValueNotPresent < StandardError; end
|
14
|
+
|
15
|
+
def self.root
|
16
|
+
File.dirname __dir__
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XmlDsl
|
4
|
+
class AttributeOptionsParser
|
5
|
+
def initialize(original_options)
|
6
|
+
@as = original_options[:as] || original_options[:require] || original_options[:if]
|
7
|
+
@options_parser = OptionsParser.new original_options
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse(options)
|
11
|
+
new options
|
12
|
+
end
|
13
|
+
|
14
|
+
def each
|
15
|
+
@options_parser.each do |parsed_options|
|
16
|
+
value = parsed_options[:locals][@as]
|
17
|
+
yield value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XmlDsl
|
4
|
+
class DataSource
|
5
|
+
def initialize(object:)
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
def can_read?(object, key)
|
10
|
+
return object.key?(key) if object.respond_to?(:key?)
|
11
|
+
|
12
|
+
object.respond_to?(key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def read(object, key)
|
16
|
+
return object[key] if object.is_a? Hash
|
17
|
+
|
18
|
+
object.send key
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(m, *args, &block)
|
22
|
+
return @data_source[m] if @data_source.is_a? Hash
|
23
|
+
|
24
|
+
@data_source.send(m, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XmlDsl
|
4
|
+
class Generator
|
5
|
+
def initialize(data_source:, template:, version_tag: '<?xml version="1.0" encoding="utf-8"?>')
|
6
|
+
@data_source = data_source
|
7
|
+
@template = template
|
8
|
+
@version_tag = version_tag
|
9
|
+
|
10
|
+
@template_dir = File.dirname @template
|
11
|
+
@tags = []
|
12
|
+
@generator = self
|
13
|
+
@depth = -1
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
instance_eval File.read(@template), @template.to_s
|
18
|
+
([@version_tag] + @tags.map(&:to_xml) + ['']).join "\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def tag(name, options = {}, &block)
|
22
|
+
OptionsParser.parse(options).each do |parsed_options|
|
23
|
+
xml_tag = Tag.new(name, self, 0, parsed_options)
|
24
|
+
@tags.push xml_tag
|
25
|
+
xml_tag.instance_eval(&block) if block_given?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def partial(name, options = {}, context = self, context_options = {})
|
30
|
+
file_name = File.join(@template_dir, "_#{name}.xml.rb").to_s
|
31
|
+
|
32
|
+
OptionsParser.parse(options, context_options).each do |parsed_options|
|
33
|
+
Partial.new(file_name, context, parsed_options).eval
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(m, *args, &block)
|
38
|
+
return @data_source[m] if @data_source.is_a? Hash
|
39
|
+
|
40
|
+
@data_source.send(m, *args, &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XmlDsl
|
4
|
+
class OptionsParser
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(original_options, parent_options = {})
|
8
|
+
self.options = original_options.clone
|
9
|
+
options[:locals] ||= {}
|
10
|
+
|
11
|
+
return unless parent_options.key?(:locals)
|
12
|
+
|
13
|
+
options[:locals] = parent_options[:locals].deep_merge(options[:locals])
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.parse(options, parent_options = {})
|
17
|
+
new options, parent_options
|
18
|
+
end
|
19
|
+
|
20
|
+
def each
|
21
|
+
return if options.key?(:if) && !options[:if]
|
22
|
+
|
23
|
+
if options.key?(:collection) && options.key?(:as)
|
24
|
+
return unless options[:collection].respond_to? :each
|
25
|
+
|
26
|
+
as = options[:as]
|
27
|
+
collection = options[:collection]
|
28
|
+
delete_options :collection, :as
|
29
|
+
|
30
|
+
collection.each do |element|
|
31
|
+
options[:locals][as] = element
|
32
|
+
|
33
|
+
yield options
|
34
|
+
end
|
35
|
+
elsif (options.key?(:if) || options.key?(:require)) && options.key?(:of)
|
36
|
+
return if options.key?(:if) && !(can_read? options[:of], options[:if])
|
37
|
+
|
38
|
+
if options.key?(:require) && !can_read?(options[:of], options[:require])
|
39
|
+
raise RequiredValueNotPresent, "Can't read required key #{options[:require]} of #{options[:of]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
accessor = options[:require] || options[:if]
|
43
|
+
of = options[:of]
|
44
|
+
as = options[:as] || accessor
|
45
|
+
|
46
|
+
delete_options :if, :of, :as, :require
|
47
|
+
|
48
|
+
options[:locals][as] = read of, accessor
|
49
|
+
yield options
|
50
|
+
else
|
51
|
+
yield options
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_options(*keys)
|
56
|
+
keys.each do |key|
|
57
|
+
options.delete key
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def can_read?(object, key)
|
62
|
+
return object.key?(key) if object.respond_to?(:key?)
|
63
|
+
|
64
|
+
object.respond_to?(key)
|
65
|
+
end
|
66
|
+
|
67
|
+
def read(object, key)
|
68
|
+
return object[key] if object.is_a? Hash
|
69
|
+
|
70
|
+
object.send key
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XmlDsl
|
4
|
+
class Partial
|
5
|
+
def initialize(file_name, context, options = {})
|
6
|
+
@context = context
|
7
|
+
@file_name = file_name
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def tag(name, options = {}, &block)
|
12
|
+
@context.tag name, options.deep_merge(@options), &block
|
13
|
+
end
|
14
|
+
|
15
|
+
def a(*args)
|
16
|
+
@context.a(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def eval
|
20
|
+
contents = File.read @file_name
|
21
|
+
instance_eval contents, @file_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(m, *args, &block)
|
25
|
+
return @options[:locals][m] if @options[:locals]&.key?(m)
|
26
|
+
|
27
|
+
@context.send(m, *args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/xml_dsl/tag.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XmlDsl
|
4
|
+
class Tag
|
5
|
+
def initialize(name, generator, depth, options = {})
|
6
|
+
@name = name
|
7
|
+
@generator = generator
|
8
|
+
@depth = depth
|
9
|
+
@options = options
|
10
|
+
|
11
|
+
@attributes = []
|
12
|
+
@tags = []
|
13
|
+
end
|
14
|
+
|
15
|
+
# Block evaluation
|
16
|
+
def a(name, options_or_value = {})
|
17
|
+
# It is options
|
18
|
+
if options_or_value.is_a? Hash
|
19
|
+
AttributeOptionsParser.parse(options_or_value).each do |value|
|
20
|
+
attribute = Attribute.new(name, value)
|
21
|
+
@attributes.push attribute
|
22
|
+
end
|
23
|
+
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
# It is a value
|
28
|
+
attribute = Attribute.new(name, options_or_value)
|
29
|
+
@attributes.push attribute
|
30
|
+
end
|
31
|
+
|
32
|
+
def tag(name, options = {}, &block)
|
33
|
+
OptionsParser.parse(options, @options).each do |parsed_options|
|
34
|
+
xml_tag = Tag.new(name, @generator, @depth + 1, parsed_options)
|
35
|
+
@tags.push xml_tag
|
36
|
+
xml_tag.instance_eval(&block) if block_given?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def partial(name, options = {})
|
41
|
+
@generator.partial(name, options, self, @options)
|
42
|
+
end
|
43
|
+
|
44
|
+
# XML Generation
|
45
|
+
def to_xml
|
46
|
+
spaces = ' ' * @depth * 2
|
47
|
+
start = "#{spaces}<#{@name}#{attributes_as_xml(spaces + ' ')}"
|
48
|
+
|
49
|
+
return start + ' />' if @tags.length.zero?
|
50
|
+
|
51
|
+
[start + '>', @tags.map(&:to_xml).join("\n"), "#{spaces}</#{@name}>"].join "\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
def attributes_as_xml(spaces)
|
55
|
+
return '' unless @attributes.any?
|
56
|
+
return " #{@attributes.first.to_xml}" if @attributes.length == 1
|
57
|
+
|
58
|
+
([''] + @attributes.map(&:to_xml).compact.map { |attribute| "#{spaces}#{attribute}" }).join("\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
def method_missing(m, *args, &block)
|
62
|
+
return @options[:locals][m] if @options[:locals]&.key?(m)
|
63
|
+
|
64
|
+
@generator.send(m, *args, &block)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/xml_dsl.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/xml_dsl/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'awesome_xml_dsl'
|
7
|
+
spec.version = XmlDsl::VERSION
|
8
|
+
spec.authors = ["Pedro 'Fedeaux' Bernardes"]
|
9
|
+
spec.email = ['phec06@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A simple yet powerful ruby dsl for generating XML files'
|
12
|
+
spec.homepage = 'https://github.com/fedeaux/xml_dsl'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
|
16
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/fedeaux/xml_dsl'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/fedeaux/xml_dsl'
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|examples)/}) }
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awesome_xml_dsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pedro 'Fedeaux' Bernardes
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- phec06@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- lib/lib/core_extensions.rb
|
32
|
+
- lib/xml_dsl.rb
|
33
|
+
- lib/xml_dsl/as_one_file.rb
|
34
|
+
- lib/xml_dsl/attribute.rb
|
35
|
+
- lib/xml_dsl/attribute_options_parser.rb
|
36
|
+
- lib/xml_dsl/data_source.rb
|
37
|
+
- lib/xml_dsl/generator.rb
|
38
|
+
- lib/xml_dsl/options_parser.rb
|
39
|
+
- lib/xml_dsl/partial.rb
|
40
|
+
- lib/xml_dsl/tag.rb
|
41
|
+
- lib/xml_dsl/version.rb
|
42
|
+
- xml_dsl.gemspec
|
43
|
+
homepage: https://github.com/fedeaux/xml_dsl
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
allowed_push_host: https://rubygems.org
|
48
|
+
homepage_uri: https://github.com/fedeaux/xml_dsl
|
49
|
+
source_code_uri: https://github.com/fedeaux/xml_dsl
|
50
|
+
changelog_uri: https://github.com/fedeaux/xml_dsl
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.3.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.1.2
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: A simple yet powerful ruby dsl for generating XML files
|
70
|
+
test_files: []
|