Class: Mbrao::ParsingEngines::PlainText
- Inherits:
-
Base
- Object
- Base
- Mbrao::ParsingEngines::PlainText
- Defined in:
- lib/mbrao/parsing_engines/plain_text.rb
Overview
A class for parsing plain text files.
Instance Method Summary (collapse)
-
- (String|HashWithIndifferentAccess) filter_content(content, locales = [], options = {})
Filters content of a post by locale.
-
- (Hash) parse_metadata(content, options = {})
Parses metadata part and returns all valid metadata.
-
- (Array) separate_components(content, options = {})
Parses a whole post content and return its metadata and content parts.
Methods inherited from Base
Instance Method Details
- (String|HashWithIndifferentAccess) filter_content(content, locales = [], options = {})
Filters content of a post by locale.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mbrao/parsing_engines/plain_text.rb', line 52 def filter_content(content, locales = [], = {}) body = content.body.ensure_string.strip = ([:content_tags], ["{{content: %ARGS%}}", "{{/content}}"]) locales = ::Mbrao::Content.validate_locales(locales, content) # Split the content result = scan_content(body, .first, .last) # Now filter results perform_filter_content(result, locales) end |
- (Hash) parse_metadata(content, options = {})
Parses metadata part and returns all valid metadata.
37 38 39 40 41 42 43 |
# File 'lib/mbrao/parsing_engines/plain_text.rb', line 37 def (content, = {}) begin YAML.load(content) rescue Exception => e [:default] ? [:default] : (raise ::Mbrao::Exceptions::InvalidMetadata.new(e.to_s)) end end |
- (Array) separate_components(content, options = {})
Parses a whole post content and return its metadata and content parts.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mbrao/parsing_engines/plain_text.rb', line 17 def separate_components(content, = {}) , content, scanner, start_tag, end_tag = prepare_for_separation(content, ) if scanner.scan_until(start_tag) then = scanner.scan_until(end_tag) if then = .partition(end_tag).first content = scanner.rest.strip end end [.ensure_string.strip, content] end |