Class: Whisper::Text

Inherits:
Object
  • Object
show all
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:

  1. there can be quoted regions, prefixed with “> ”, which can be nested (a la email)

  2. 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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 meta_file, body_file
  @meta_file = meta_file
  @body_file = body_file

  dependency_init
end

Class Attribute Details

.quote_formatterObject (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_fileObject (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_fileObject (readonly)

Returns the value of attribute meta_file.



37
38
39
# File 'lib/whisper/text.rb', line 37

def meta_file
  @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 &block; @quote_formatter = block end

.formattersObject



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, meta_or_body, format
  case meta_or_body
  when :meta; build_metas
  when :body; build_body format
  else raise ArgumentError, "unknown selector #{meta_or_body.inspect}"
  end
end

#dependenciesObject



46
# File 'lib/whisper/text.rb', line 46

def dependencies; [@meta_file, @body_file] end

#mObject

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) { meta[m] }
end

#metaObject



63
# File 'lib/whisper/text.rb', line 63

def meta; content(:meta, nil) end