Class: Textus::Format::Text
- Inherits:
-
Base
- Object
- Base
- Textus::Format::Text
show all
- Defined in:
- lib/textus/format/text.rb
Class Method Summary
collapse
Methods inherited from Base
format_name, validate_against, validate_raw_entry!
Class Method Details
.data_to_payload(data) ⇒ Object
49
50
51
52
|
# File 'lib/textus/format/text.rb', line 49
def self.data_to_payload(data)
data = data.transform_keys(&:to_s) if data.is_a?(Hash)
{ meta: data["_meta"] || {}, body: (data["body"] || "").to_s, content: nil }
end
|
.enforce_name_match!(_path, _meta) ⇒ Object
23
|
# File 'lib/textus/format/text.rb', line 23
def self.enforce_name_match!(_path, _meta); end
|
.extensions ⇒ Object
19
|
# File 'lib/textus/format/text.rb', line 19
def self.extensions = [".txt"]
|
.nested_glob ⇒ Object
21
|
# File 'lib/textus/format/text.rb', line 21
def self.nested_glob = "**/*.txt"
|
.parse(raw, path: nil) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/textus/format/text.rb', line 4
def self.parse(raw, path: nil)
raw = raw.dup.force_encoding(Encoding::UTF_8)
raise BadFrontmatter.new(path, "entry is not valid UTF-8") unless raw.valid_encoding?
{ "_meta" => {}, "body" => raw, "content" => nil }
end
|
.rewrite_name(_path, _basename) ⇒ Object
rubocop:disable Naming/PredicateMethod
32
33
34
|
# File 'lib/textus/format/text.rb', line 32
def self.rewrite_name(_path, _basename) false
end
|
.serialize(meta:, body:, content: nil) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/textus/format/text.rb', line 11
def self.serialize(meta:, body:, content: nil)
_ = meta
_ = content
b = body.to_s
b += "\n" unless b.empty? || b.end_with?("\n")
b
end
|
.serialize_for_put(meta:, body:, content:, path:) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/textus/format/text.rb', line 25
def self.serialize_for_put(meta:, body:, content:, path:)
_ = path
_ = content
bytes = serialize(meta: meta || {}, body: body.to_s)
[bytes, meta, body.to_s, nil]
end
|
.validate_path_extension(path, nested) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/textus/format/text.rb', line 36
def self.validate_path_extension(path, nested)
ext = File.extname(path)
if nested
return if ext == ""
raise UsageError.new("nested text path must not have an extension")
end
return if [".txt", ""].include?(ext)
raise UsageError.new("text format requires '.txt' or no extension (got #{ext.inspect})")
end
|