Class: Md2Cnblog::BaseTranslator
- Inherits:
-
Object
- Object
- Md2Cnblog::BaseTranslator
show all
- Defined in:
- lib/md2cnblog/base_translator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(str, options = {}, render = nil) ⇒ BaseTranslator
Returns a new instance of BaseTranslator.
6
7
8
9
10
11
|
# File 'lib/md2cnblog/base_translator.rb', line 6
def initialize(str, options={}, render=nil)
@str ||= str if valide_str?(str)
@options = default_options.merge(options) if valide_option?(options)
@render = render || default_render
@markdown = ::Redcarpet::Markdown.new(@render, @options)
end
|
Instance Attribute Details
#markdown ⇒ Object
Returns the value of attribute markdown.
3
4
5
|
# File 'lib/md2cnblog/base_translator.rb', line 3
def markdown
@markdown
end
|
#options ⇒ Object
Returns the value of attribute options.
3
4
5
|
# File 'lib/md2cnblog/base_translator.rb', line 3
def options
@options
end
|
#output ⇒ Object
Returns the value of attribute output.
3
4
5
|
# File 'lib/md2cnblog/base_translator.rb', line 3
def output
@output
end
|
#render ⇒ Object
Returns the value of attribute render.
4
5
6
|
# File 'lib/md2cnblog/base_translator.rb', line 4
def render
@render
end
|
Instance Method Details
#default_options ⇒ Object
23
24
25
26
27
28
|
# File 'lib/md2cnblog/base_translator.rb', line 23
def default_options
{ no_intra_emphasis: true,
autolink: true,
space_after_headers: true,
fenced_code_blocks: true }
end
|
#default_render ⇒ Object
30
31
32
|
# File 'lib/md2cnblog/base_translator.rb', line 30
def default_render
Redcarpet::Render::HTML.new()
end
|
#echo ⇒ Object
43
44
45
|
# File 'lib/md2cnblog/base_translator.rb', line 43
def echo
print @output
end
|
#start ⇒ Object
34
35
36
37
|
# File 'lib/md2cnblog/base_translator.rb', line 34
def start
start_mute
echo
end
|
#start_mute ⇒ Object
39
40
41
|
# File 'lib/md2cnblog/base_translator.rb', line 39
def start_mute
@output = @markdown.render(@str)
end
|
#valide_option?(options) ⇒ Boolean
18
19
20
21
|
# File 'lib/md2cnblog/base_translator.rb', line 18
def valide_option?(options)
raise InvalidOptionsError unless options.is_a?(Hash)
true
end
|
#valide_str?(str) ⇒ Boolean
13
14
15
16
|
# File 'lib/md2cnblog/base_translator.rb', line 13
def valide_str?(str)
raise InvalidInputError unless str.is_a?(String)
true
end
|