gloo-md 1.2 → 1.3
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/lib/md_doc.rb +28 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bfa6b6b1b63e61071e271da7649cb0d13d0dd7a6ab8f0bcfaeb455e6325efcc
|
|
4
|
+
data.tar.gz: 1fcd9683e59f38daf40984bc0d711fa44eac8ca3d9f39a7e6ce21d2b98568de6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ef1a0fc0d81d9fc7c145a5385b70dd848fc1de52c74c2c833175c998b04f8eded160ef9241ee579c1a723229f26b8036af4dd2dde7048871358c8b58730513e
|
|
7
|
+
data.tar.gz: a3572eb4470c11e401fef0628b1e506f24b628a07cc8115819abc4f59db7dc59d059591a5f4ef6422c72f4dd7f2fa5e43a4c7dba05d813e218fba1813920040b
|
data/lib/md_doc.rb
CHANGED
|
@@ -79,7 +79,9 @@ class MdDoc < Gloo::Core::Obj
|
|
|
79
79
|
|
|
80
80
|
#
|
|
81
81
|
# Read the file at path, parse frontmatter and body, populate children.
|
|
82
|
-
#
|
|
82
|
+
# Only scalar frontmatter values become gloo string children; complex values
|
|
83
|
+
# (arrays, nested hashes) are skipped — they are preserved on write by
|
|
84
|
+
# re-reading the file.
|
|
83
85
|
#
|
|
84
86
|
def msg_read
|
|
85
87
|
path = resolve_path
|
|
@@ -96,6 +98,7 @@ class MdDoc < Gloo::Core::Obj
|
|
|
96
98
|
fm_can = find_child FRONTMATTER
|
|
97
99
|
if fm_can && fm_hash
|
|
98
100
|
fm_hash.each do |key, val|
|
|
101
|
+
next unless scalar?( val )
|
|
99
102
|
child = fm_can.find_add_child( key.to_s, 'string' )
|
|
100
103
|
child.set_value val.to_s
|
|
101
104
|
end
|
|
@@ -107,25 +110,35 @@ class MdDoc < Gloo::Core::Obj
|
|
|
107
110
|
|
|
108
111
|
#
|
|
109
112
|
# Serialize frontmatter and body children back to the file at path.
|
|
110
|
-
#
|
|
113
|
+
# Re-reads the current file to get the base hash (preserving arrays and other
|
|
114
|
+
# complex values), then overlays the scalar children which may have been
|
|
115
|
+
# modified. Creates the file if it does not exist.
|
|
111
116
|
#
|
|
112
117
|
def msg_write
|
|
113
118
|
path = resolve_path
|
|
114
119
|
return unless path
|
|
115
120
|
|
|
121
|
+
expanded = File.expand_path( path )
|
|
122
|
+
|
|
123
|
+
# Re-read the file so arrays and nested hashes survive unchanged.
|
|
124
|
+
base = {}
|
|
125
|
+
if File.exist?( expanded )
|
|
126
|
+
base, _ = parse_frontmatter( File.read( expanded ) )
|
|
127
|
+
end
|
|
128
|
+
|
|
116
129
|
fm_can = find_child FRONTMATTER
|
|
117
|
-
|
|
130
|
+
|
|
131
|
+
# Overlay scalar children; updating an existing key preserves its position.
|
|
118
132
|
if fm_can
|
|
119
133
|
fm_can.children.each do |child|
|
|
120
|
-
|
|
134
|
+
base[ child.name ] = child.value
|
|
121
135
|
end
|
|
122
136
|
end
|
|
123
137
|
|
|
124
138
|
body = find_child BODY
|
|
125
139
|
body_text = body ? body.value.to_s : ''
|
|
126
140
|
|
|
127
|
-
|
|
128
|
-
File.write( File.expand_path( path ), content )
|
|
141
|
+
File.write( expanded, build_content( base, body_text ) )
|
|
129
142
|
end
|
|
130
143
|
|
|
131
144
|
|
|
@@ -135,6 +148,15 @@ class MdDoc < Gloo::Core::Obj
|
|
|
135
148
|
|
|
136
149
|
private
|
|
137
150
|
|
|
151
|
+
#
|
|
152
|
+
# True for scalar YAML values that can be stored as gloo string children.
|
|
153
|
+
# Arrays, hashes, and other complex types are skipped on read.
|
|
154
|
+
#
|
|
155
|
+
def scalar?( val )
|
|
156
|
+
val.is_a?( String ) || val.is_a?( Integer ) || val.is_a?( Float ) ||
|
|
157
|
+
val.is_a?( TrueClass ) || val.is_a?( FalseClass ) || val.nil?
|
|
158
|
+
end
|
|
159
|
+
|
|
138
160
|
#
|
|
139
161
|
# Get the expanded path string from the path child.
|
|
140
162
|
#
|