Class: Germinate::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/germinate/application.rb

Overview

The Application ties all the other componts together. It has public methods roughly corresponding commands that the ‘germ’ command-line tool supports.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatter=(value) ⇒ Object (writeonly)

Sets the attribute formatter

Parameters:

  • value

    the value to set the attribute formatter to.



4
5
6
# File 'lib/germinate/application.rb', line 4

def formatter=(value)
  @formatter = value
end

Instance Method Details

#format(source, output = $stdout, errors = $stderr) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/germinate/application.rb', line 6

def format(source, output=$stdout, errors=$stderr)
  librarian = load_librarian(source)
  editor    = Germinate::ArticleEditor.new(librarian)
  formatter = Germinate::ArticleFormatter.new(output)

  Germinate::SharedStyleAttributes.fattrs.each do 
    |style_attribute|
    formatter.send(style_attribute, librarian.send(style_attribute))
  end
  formatter.start!
  editor.each_hunk do |hunk|
    formatter.format!(hunk)
  end
  formatter.finish!
end

#list(source, things_to_list, output = $stdout) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/germinate/application.rb', line 22

def list(source, things_to_list, output=$stdout)
  librarian = load_librarian(source)
  if things_to_list.include?(:sections)
    output.puts(librarian.section_names.join("\n"))
  end
  if things_to_list.include?(:samples)
    output.puts(librarian.sample_names.join("\n"))
  end
  if things_to_list.include?(:processes)
    output.puts(librarian.process_names.join("\n"))
  end
end

#select(source, selector, output = $stdout) ⇒ Object



48
49
50
51
# File 'lib/germinate/application.rb', line 48

def select(source, selector, output=$stdout)
  librarian = load_librarian(source)
  output.puts(*librarian[selector])
end

#show(source, selection, output = $stdout) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/germinate/application.rb', line 35

def show(source, selection, output=$stdout)
  librarian = load_librarian(source)
  selection.fetch(:section, []).each do |section|
    output.puts(*librarian.section(section))
  end
  selection.fetch(:sample, []).each do |sample|
    output.puts(*librarian.sample(sample))
  end
  selection.fetch(:process, []).each do |process|
    output.puts(*librarian.process(process).command)
  end
end