Class: Repubmark::Elems::Base
- Inherits:
-
Object
- Object
- Repubmark::Elems::Base
show all
- Defined in:
- lib/repubmark/elems/base.rb
Direct Known Subclasses
Abbrev, Annotation, Article, Blockquote, Canvas, Caption, Chapter, CodeBlock, CodeInline, Figure, Figures, Footnote, FootnotesCategory, Fraction, Iframe, Joint, List, ListItem, Note, Paragraph, Power, Quote, Section, Separator, Special, Text
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent) ⇒ Base
Returns a new instance of Base.
8
9
10
|
# File 'lib/repubmark/elems/base.rb', line 8
def initialize(parent)
self.parent = parent
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
6
7
8
|
# File 'lib/repubmark/elems/base.rb', line 6
def parent
@parent
end
|
Class Method Details
.parent?(klass) ⇒ Boolean
46
47
48
49
50
51
52
|
# File 'lib/repubmark/elems/base.rb', line 46
def parent?(klass)
unless klass.instance_of? Class
raise TypeError, "Expected #{Class}, got #{klass.class}"
end
parents.include? klass.name
end
|
.parents(*args) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/repubmark/elems/base.rb', line 35
def parents(*args)
if @parents
raise ArgumentError, 'Invalid args' unless args.empty?
return @parents
end
@parents = args.map { |arg| "#{Elems}::#{arg}".freeze }.to_a.freeze
nil
end
|
Instance Method Details
#absolute_url(path) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/repubmark/elems/base.rb', line 74
def absolute_url(path)
base_url = String(config[:base_url]).strip.freeze
raise 'Invalid base URL' if base_url.empty?
path = "/#{path}" unless path.start_with? '/'
"#{base_url}#{path}"
end
|
#config ⇒ Object
32
|
# File 'lib/repubmark/elems/base.rb', line 32
def config = parent.config
|
#count_words(str) ⇒ Object
101
|
# File 'lib/repubmark/elems/base.rb', line 101
def count_words(str) = str.split.count
|
#html_class(key) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/repubmark/elems/base.rb', line 93
def html_class(key)
if (value = config[:"css_class_#{key}"])
%( class="#{value}").freeze
else
''
end
end
|
#own_url(path) ⇒ Object
70
71
72
|
# File 'lib/repubmark/elems/base.rb', line 70
def own_url(path)
config[:relative_urls] ? relative_url(path) : absolute_url(path)
end
|
#relative_url(path) ⇒ Object
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/repubmark/elems/base.rb', line 82
def relative_url(path)
current_path = String(config[:current_path]).strip.freeze
raise 'Invalid current path URL' if current_path.empty?
Pathname
.new(path)
.relative_path_from("/#{current_path}/..")
.to_s
.freeze
end
|
#to_gemtext ⇒ Object
24
25
26
|
# File 'lib/repubmark/elems/base.rb', line 24
def to_gemtext
raise NotImplementedError, "#{self.class}#to_gemtext"
end
|
#to_html ⇒ Object
20
21
22
|
# File 'lib/repubmark/elems/base.rb', line 20
def to_html
raise NotImplementedError, "#{self.class}#to_html"
end
|
#to_summary_plain ⇒ Object
18
|
# File 'lib/repubmark/elems/base.rb', line 18
def to_summary_plain = nil
|
#word_count ⇒ Object
16
|
# File 'lib/repubmark/elems/base.rb', line 16
def word_count = 0
|