ruyml 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +25 -30
- data/lib/ruyml.rb +1 -1
- data/lib/ruyml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 206c355ede0279b5ea81b5d23b523810aa575961
|
|
4
|
+
data.tar.gz: c97e2daebc1bf00e2dc4fbd89e9eb693c124af32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c4954cf874089bb2ce088e9b96eabd6576928e43289c8bd7b2aae56dc368fdd9f1fc1f42d2ce638e496aa33815bacc0a9e5dd368d8a23ff420348decfede5d2f
|
|
7
|
+
data.tar.gz: 843f5c0e14566117fed5c22120154497e31a9d13f51fc759f5f13e852271a2fe33a0f57910ec2b73769f6b7894fa7b2b33380c5ae2b55aa69f5b189dbc3bbf83
|
data/README.md
CHANGED
|
@@ -4,17 +4,19 @@ Ruby templating using YAML datasources
|
|
|
4
4
|
|
|
5
5
|
# Usage
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
Usage : ruyml [options]
|
|
7
|
+
## Library
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
```ruby
|
|
10
|
+
require 'ruyml'
|
|
11
|
+
require 'yaml'
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
content = YAML.load(File.read("file.yml"))
|
|
14
|
+
r = Ruyml::Data.new(content)
|
|
15
|
+
r.render("template.erb", "output.txt")
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## CLI
|
|
19
|
+
|
|
18
20
|
## Simple usage
|
|
19
21
|
|
|
20
22
|
Given a yaml file :
|
|
@@ -33,7 +35,7 @@ message = "<%= alert.message.capitalize %>"
|
|
|
33
35
|
Running :
|
|
34
36
|
|
|
35
37
|
```bash
|
|
36
|
-
|
|
38
|
+
ruyml -d alert.yaml -t template.erb
|
|
37
39
|
```
|
|
38
40
|
|
|
39
41
|
Gives the following output :
|
|
@@ -42,15 +44,15 @@ Gives the following output :
|
|
|
42
44
|
message = "Hello world !"
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
## Advanced usage
|
|
48
|
+
### Multiple data sources
|
|
47
49
|
You can refer to multiple YAML datasources in a template and render it using :
|
|
48
50
|
|
|
49
51
|
```bash
|
|
50
52
|
ruyml -d data1.yaml,data2.yaml -t template.erb
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
### Accessing Hash methods
|
|
54
56
|
When iterating over an item which is not a leaf of the YAML file, you can access
|
|
55
57
|
methods of the Hash class directly. In case a propertie has the same name than
|
|
56
58
|
the method you are trying to use, simply use the `<method>!` form.
|
|
@@ -59,27 +61,20 @@ For instance :
|
|
|
59
61
|
|
|
60
62
|
```yaml
|
|
61
63
|
object:
|
|
62
|
-
each:
|
|
64
|
+
each:
|
|
65
|
+
- attr1: val1
|
|
66
|
+
- attr2: val2
|
|
67
|
+
- attr3: val3
|
|
63
68
|
```
|
|
64
69
|
|
|
65
70
|
```erb
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
Object dump :
|
|
72
|
+
<%= object.each %>
|
|
73
|
+
|
|
74
|
+
Object attributes:
|
|
75
|
+
<% object.each! do |p, items| -%>
|
|
76
|
+
<% items.each do |attr, val| -%>
|
|
77
|
+
Attribute <%= attr %> has value <%= val %>
|
|
78
|
+
<% end -%>
|
|
71
79
|
<% end -%>
|
|
72
80
|
```
|
|
73
|
-
|
|
74
|
-
Once rendered, the result is :
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
Each object will have value.
|
|
78
|
-
|
|
79
|
-
Full object properties:
|
|
80
|
-
each : value
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Status
|
|
84
|
-
|
|
85
|
-
Alot of todos in there ... but you can feel the spirit.
|
data/lib/ruyml.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Ruyml
|
|
|
22
22
|
# Renders RUYML data using the given template.
|
|
23
23
|
# Rendered data is either written to an optional
|
|
24
24
|
# output file path or to stdout.
|
|
25
|
-
def render(template, output)
|
|
25
|
+
def render(template, output = nil)
|
|
26
26
|
result = ERB.new(File.read(template), 0, '-').result(binding)
|
|
27
27
|
if !output.nil?
|
|
28
28
|
File.open(output, "w") do |file|
|
data/lib/ruyml/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruyml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Xavier Lucas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-05-
|
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|