Class: Textus::Protocol::Format::Text
- Inherits:
-
Base
- Object
- Base
- Textus::Protocol::Format::Text
show all
- Defined in:
- lib/textus/protocol/format/text.rb
Class Method Summary
collapse
Methods inherited from Base
format_name, nested_ext, serialize_for_put, validate_against, validate_raw_entry!
Class Method Details
.data_to_payload(data) ⇒ Object
41
42
43
44
|
# File 'lib/textus/protocol/format/text.rb', line 41
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
22
|
# File 'lib/textus/protocol/format/text.rb', line 22
def self.enforce_name_match!(_path, _meta); end
|
.extensions ⇒ Object
20
|
# File 'lib/textus/protocol/format/text.rb', line 20
def self.extensions = [".txt"]
|
.nested_glob ⇒ Object
21
|
# File 'lib/textus/protocol/format/text.rb', line 21
def self.nested_glob = "**/*.txt"
|
.parse(raw, path: nil) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/textus/protocol/format/text.rb', line 5
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
24
25
26
|
# File 'lib/textus/protocol/format/text.rb', line 24
def self.rewrite_name(_path, _basename) false
end
|
.serialize(meta:, body:, content: nil) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/textus/protocol/format/text.rb', line 12
def self.serialize(meta:, body:, content: nil)
_ = meta
_ = content
b = body.to_s
b += "\n" unless b.empty? || b.end_with?("\n")
b
end
|
.validate_path_extension(path, nested) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/textus/protocol/format/text.rb', line 28
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
|