Class: Textus::Format::Text
Class Method Summary collapse
- .enforce_name_match!(_path, _meta) ⇒ Object
- .extensions ⇒ Object
- .inject_uid(meta, content, _existing_uid) ⇒ Object
- .nested_glob ⇒ Object
- .parse(raw, path: nil) ⇒ Object
-
.rewrite_name(_path, _basename) ⇒ Object
rubocop:disable Naming/PredicateMethod.
- .serialize(meta:, body:, content: nil) ⇒ Object
- .serialize_for_put(meta:, body:, content:, path:) ⇒ Object
- .validate_path_extension(path, nested) ⇒ Object
Methods inherited from Base
Class Method Details
.enforce_name_match!(_path, _meta) ⇒ Object
27 |
# File 'lib/textus/format/text.rb', line 27 def self.enforce_name_match!(_path, ); end |
.extensions ⇒ Object
19 |
# File 'lib/textus/format/text.rb', line 19 def self.extensions = [".txt"] |
.inject_uid(meta, content, _existing_uid) ⇒ Object
23 24 25 |
# File 'lib/textus/format/text.rb', line 23 def self.inject_uid(, content, _existing_uid) [, content] end |
.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
36 37 38 |
# File 'lib/textus/format/text.rb', line 36 def self.rewrite_name(_path, _basename) # rubocop:disable Naming/PredicateMethod 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) _ = _ = content b = body.to_s b += "\n" unless b.empty? || b.end_with?("\n") b end |
.serialize_for_put(meta:, body:, content:, path:) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/textus/format/text.rb', line 29 def self.serialize_for_put(meta:, body:, content:, path:) _ = path _ = content bytes = serialize(meta: || {}, body: body.to_s) [bytes, , body.to_s, nil] end |
.validate_path_extension(path, nested) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/textus/format/text.rb', line 40 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 |