Class: Whisper::Text
- Inherits:
-
Object
- Object
- Whisper::Text
- Includes:
- Dependency, Loggy
- Defined in:
- lib/whisper/text.rb
Overview
a text object, capable of converting itself from “enhanced textile” to html, plain text, and other formats.
this class deals with the gory details of textile, comments, and format-specific regions, each of which conflict with each other in horrible ways.
comment and post format is basically textile, EXCEPT:
-
there can be quoted regions, prefixed with “> ”, which can be nested (a la email)
-
there can be arbitrary, non-nested regions, which the user can define their own boundary markers and formatters for, which cannot be nested.
Class Attribute Summary collapse
-
.quote_formatter ⇒ Object
readonly
Returns the value of attribute quote_formatter.
Instance Attribute Summary collapse
-
#body_file ⇒ Object
readonly
Returns the value of attribute body_file.
-
#meta_file ⇒ Object
readonly
Returns the value of attribute meta_file.
Class Method Summary collapse
Instance Method Summary collapse
- #body(format, opts = {}) ⇒ Object
- #build(old, meta_or_body, format) ⇒ Object
- #dependencies ⇒ Object
-
#initialize(meta_file, body_file) ⇒ Text
constructor
A new instance of Text.
-
#m ⇒ Object
pass all these through to the metainfo container.
- #meta ⇒ Object
Methods included from Dependency
#content, #dependency_init, #refresh!, #timestamp
Constructor Details
#initialize(meta_file, body_file) ⇒ Text
Returns a new instance of Text.
39 40 41 42 43 44 |
# File 'lib/whisper/text.rb', line 39 def initialize , body_file @meta_file = @body_file = body_file dependency_init end |
Class Attribute Details
.quote_formatter ⇒ Object (readonly)
Returns the value of attribute quote_formatter.
27 28 29 |
# File 'lib/whisper/text.rb', line 27 def quote_formatter @quote_formatter end |
Instance Attribute Details
#body_file ⇒ Object (readonly)
Returns the value of attribute body_file.
37 38 39 |
# File 'lib/whisper/text.rb', line 37 def body_file @body_file end |
#meta_file ⇒ Object (readonly)
Returns the value of attribute meta_file.
37 38 39 |
# File 'lib/whisper/text.rb', line 37 def @meta_file end |
Class Method Details
.format(start_tag, end_tag, &block) ⇒ Object
29 30 31 32 |
# File 'lib/whisper/text.rb', line 29 def format start_tag, end_tag, &block @formatters ||= [] @formatters << [start_tag, end_tag, block] end |
.format_quote(&block) ⇒ Object
34 |
# File 'lib/whisper/text.rb', line 34 def format_quote █ @quote_formatter = block end |
.formatters ⇒ Object
26 |
# File 'lib/whisper/text.rb', line 26 def formatters; @formatters ||= [] end |
Instance Method Details
#body(format, opts = {}) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/whisper/text.rb', line 55 def body format, opts={} c = content :body, format if opts[:prefix] c.lines.map { |l| opts[:prefix] + l } else c end end |
#build(old, meta_or_body, format) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/whisper/text.rb', line 47 def build old, , format case when :meta; when :body; build_body format else raise ArgumentError, "unknown selector #{.inspect}" end end |
#dependencies ⇒ Object
46 |
# File 'lib/whisper/text.rb', line 46 def dependencies; [@meta_file, @body_file] end |
#m ⇒ Object
pass all these through to the metainfo container
66 67 68 |
# File 'lib/whisper/text.rb', line 66 [:labels, :entry_id, :published, :updated, :id, :author, :content_file, :parent_id, :message_id].each do |m| define_method(m) { [m] } end |
#meta ⇒ Object
63 |
# File 'lib/whisper/text.rb', line 63 def ; content(:meta, nil) end |