Class: Repubmark::Elems::Joint

Inherits:
Base
  • Object
show all
Defined in:
lib/repubmark/elems/joint.rb

Defined Under Namespace

Modules: ForwardingBuilders

Instance Attribute Summary

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Base

#absolute_url, #config, #count_words, #html_class, #own_url, parent?, parents, #relative_url

Constructor Details

#initialize(parent) ⇒ Joint

Returns a new instance of Joint.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/repubmark/elems/joint.rb', line 8

def initialize(parent)
  super parent

  @raw1   = nil
  @base   = nil
  @raw2   = nil
  @notes  = []
  @raw3   = nil

  @context = nil
  @context_note = false
end

Instance Method Details

#abbrev(abbrev, transcript) ⇒ Object

Builder methods: Base #



58
# File 'lib/repubmark/elems/joint.rb', line 58

def abbrev(abbrev, transcript) = base Abbrev.new self, abbrev, transcript

#base(elem) ⇒ Object (private)



130
131
132
133
134
135
136
# File 'lib/repubmark/elems/joint.rb', line 130

def base(elem)
  raise 'Joint base already exists'   if @base
  raise 'Joint notes already exist'   if @notes.any?

  @base = elem
  nil
end

#bold(str) ⇒ Object



60
# File 'lib/repubmark/elems/joint.rb', line 60

def bold(str) = base Text.new self, str, bold: true

#code_inline(str) ⇒ Object



62
# File 'lib/repubmark/elems/joint.rb', line 62

def code_inline(str) = base CodeInline.new self, str

#componentsObject (private)



124
125
126
127
128
# File 'lib/repubmark/elems/joint.rb', line 124

def components
  raise 'No context note' if @context && !@context_note

  [@raw1, @base, @raw2, *@notes, @raw3].compact
end

#context(index, category, slug) ⇒ Object

Builder methods: Notes #



103
104
105
106
107
108
# File 'lib/repubmark/elems/joint.rb', line 103

def context(index, category, slug)
  raise 'Context already given' if @context

  @context = [index, category, slug]
  nil
end

#context_noteObject



110
111
112
113
114
115
116
# File 'lib/repubmark/elems/joint.rb', line 110

def context_note
  raise 'No context given' if @context.nil?
  raise 'Context already noted' if @context_note

  @context_note = true
  ref_note(*@context)
end

#ellipsisObject



64
# File 'lib/repubmark/elems/joint.rb', line 64

def ellipsis = base Special.new self, :ellipsis

#fraction(top, bottom) ⇒ Object



66
# File 'lib/repubmark/elems/joint.rb', line 66

def fraction(top, bottom) = base Fraction.new self, top, bottom

#italic(str) ⇒ Object



68
# File 'lib/repubmark/elems/joint.rb', line 68

def italic(str) = base Text.new self, str, italic: true


70
# File 'lib/repubmark/elems/joint.rb', line 70

def link(text, uri) = base Link.new self, text, uri


72
# File 'lib/repubmark/elems/joint.rb', line 72

def link_italic(text, uri) = base Link.new self, text, uri, italic: true

#mdashObject



74
# File 'lib/repubmark/elems/joint.rb', line 74

def mdash = base Special.new self, :mdash

#note(elem) ⇒ Object (private)



138
139
140
141
142
143
# File 'lib/repubmark/elems/joint.rb', line 138

def note(elem)
  raise 'Joint base does not exists' if @base.nil?

  @notes << elem
  nil
end

#power(base, exponent) ⇒ Object



76
# File 'lib/repubmark/elems/joint.rb', line 76

def power(base, exponent) = base Power.new self, base, exponent

#quote(str = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/repubmark/elems/joint.rb', line 78

def quote(str = nil)
  quote = Quote.new self
  case [!!str, block_given?]
  when [true, false] then quote.text str
  when [false, true] then yield quote
  else
    raise 'Invalid args'
  end
  base quote
end

#quote_italic(str) ⇒ Object



89
90
91
92
93
# File 'lib/repubmark/elems/joint.rb', line 89

def quote_italic(str)
  quote = Quote.new self
  quote.italic str
  base quote
end

#raw(str) ⇒ Object

Builder methods: Raw #



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/repubmark/elems/joint.rb', line 37

def raw(str)
  text = Text.new self, str
  if @notes.any?
    raise 'Joint raw text already exists' if @raw3

    @raw3 = text
  elsif @base
    raise 'Joint raw text already exists' if @raw2

    @raw2 = text
  else
    raise 'Joint raw text already exists' if @raw1

    @raw1 = text
  end
end

#ref_note(index, category, slug) ⇒ Object



118
119
120
# File 'lib/repubmark/elems/joint.rb', line 118

def ref_note(index, category, slug)
  note Note.new self, index, category, slug
end

#section(*args) ⇒ Object



95
# File 'lib/repubmark/elems/joint.rb', line 95

def section(*args) = base Section.new self, *args

#text(str) ⇒ Object



97
# File 'lib/repubmark/elems/joint.rb', line 97

def text(str) = base Text.new self, str

#to_gemtextObject



31
# File 'lib/repubmark/elems/joint.rb', line 31

def to_gemtext = components.map(&:to_gemtext).join.freeze

#to_htmlObject



29
# File 'lib/repubmark/elems/joint.rb', line 29

def to_html = components.map(&:to_html).join.freeze

#to_summary_plainObject



27
# File 'lib/repubmark/elems/joint.rb', line 27

def to_summary_plain = components.map(&:to_summary_plain).join.freeze

#word_countObject

Basic methods #



25
# File 'lib/repubmark/elems/joint.rb', line 25

def word_count = components.sum(&:word_count)