Class: Germinate::ArticleFormatter

Inherits:
Object
  • Object
show all
Includes:
SharedStyleAttributes
Defined in:
lib/germinate/article_formatter.rb

Overview

A Formatter is responsible for taking content hunks received from an Editor and formatting them for display or publishing.

Instance Method Summary collapse

Methods included from SharedStyleAttributes

#copy_shared_style_attrubutes_from, #shared_style_attributes

Constructor Details

#initialize(output_stream = $stdout) ⇒ ArticleFormatter

Returns a new instance of ArticleFormatter.



17
18
19
20
# File 'lib/germinate/article_formatter.rb', line 17

def initialize(output_stream=$stdout)
  @output_stream  = output_stream
  @first_output   = true
end

Instance Method Details

#finish!Object



25
26
# File 'lib/germinate/article_formatter.rb', line 25

def finish!
end

#format!(hunk) ⇒ Object



28
29
30
31
32
# File 'lib/germinate/article_formatter.rb', line 28

def format!(hunk)
  @output_stream.puts unless first_output?
  hunk.format_with(self)
  @first_output = false if first_output?
end

#format_code!(hunk, comment_prefix = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/germinate/article_formatter.rb', line 42

def format_code!(hunk, comment_prefix=nil)
  code_transforms.inject(hunk) do |hunk, transform|
    transform.call(hunk)
  end.each do |line|
    @output_stream.puts(line)
  end
end

#format_text!(hunk, comment_prefix = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/germinate/article_formatter.rb', line 34

def format_text!(hunk, comment_prefix=nil)
  text_transforms.inject(hunk) do |hunk, transform|
    transform.call(hunk)
  end.each do |line|
    @output_stream.puts(line)
  end
end

#start!Object



22
23
# File 'lib/germinate/article_formatter.rb', line 22

def start!
end