Class: Neapolitan::Part
- Inherits:
-
Object
- Object
- Neapolitan::Part
- Defined in:
- lib/neapolitan/part.rb
Overview
A part is a section of a template. Templates can be segmented into parts using the ‘— FORMAT’ notation.
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
The template to which the part belongs.
-
#text ⇒ Object
readonly
Body of text as given in the part.
Class Method Summary collapse
-
.parse(template, body) ⇒ Object
Parse text body and create new part.
Instance Method Summary collapse
-
#default ⇒ Object
Template default format split into array.
-
#finish ⇒ Object
Template default format split into array.
-
#format ⇒ Object
Rendering format as given in the template document.
- #formatting(&custom) ⇒ Object
-
#initialize(template, text, format) ⇒ Part
constructor
Setup new Part instance.
-
#specific ⇒ Object
Part specific format split into array.
-
#stencil ⇒ Object
Template default format split into array.
Constructor Details
#initialize(template, text, format) ⇒ Part
Setup new Part instance.
34 35 36 37 38 |
# File 'lib/neapolitan/part.rb', line 34 def initialize(template, text, format) @template = template @text = text @format = format end |
Instance Attribute Details
#template ⇒ Object (readonly)
The template to which the part belongs.
21 22 23 |
# File 'lib/neapolitan/part.rb', line 21 def template @template end |
#text ⇒ Object (readonly)
Body of text as given in the part.
24 25 26 |
# File 'lib/neapolitan/part.rb', line 24 def text @text end |
Class Method Details
.parse(template, body) ⇒ Object
Parse text body and create new part.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/neapolitan/part.rb', line 8 def self.parse(template, body) if body.start_with?('---') index = body.index("\n") format = body[0...index].strip.sub(/^---/,'').strip text = body[index+1..-1].strip else text = body format = '' end new(template, text, format) end |
Instance Method Details
#default ⇒ Object
Template default format split into array.
51 52 53 |
# File 'lib/neapolitan/part.rb', line 51 def default @_default ||= split_format(template.default) end |
#finish ⇒ Object
Template default format split into array.
61 62 63 |
# File 'lib/neapolitan/part.rb', line 61 def finish @_finish ||= split_format(template.finish) end |
#format ⇒ Object
Rendering format as given in the template document.
41 42 43 |
# File 'lib/neapolitan/part.rb', line 41 def format @format end |
#formatting(&custom) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/neapolitan/part.rb', line 66 def formatting(&custom) if custom custom.call(self) else if specific.empty? stencil + default + finish else stencil + specific + finish end end end |
#specific ⇒ Object
Part specific format split into array.
46 47 48 |
# File 'lib/neapolitan/part.rb', line 46 def specific @_specific ||= split_format(format) end |
#stencil ⇒ Object
Template default format split into array.
56 57 58 |
# File 'lib/neapolitan/part.rb', line 56 def stencil @_stencil ||= split_format(template.stencil) end |