Class: Bread::Basket::Poster::TextRenderer
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- Bread::Basket::Poster::TextRenderer
- Defined in:
- lib/bread/basket/poster/text_renderer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#curr_styles ⇒ Object
readonly
Returns the value of attribute curr_styles.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
Instance Method Summary collapse
- #alignment ⇒ Object
-
#block_code(content, first_line) ⇒ Object
Overloaded function for images, equations and maybe someday even code.
-
#double_emphasis(text) ⇒ Object
bold.
-
#emphasis(text) ⇒ Object
italic.
- #header(text, _header_level) ⇒ Object
-
#highlight(text) ⇒ Object
inline ==highlighting==.
- #paragraph(text) ⇒ Object
- #preprocess(full_document) ⇒ Object
-
#superscript(text) ⇒ Object
super^script.
-
#underline(text) ⇒ Object
underline.
Instance Attribute Details
#curr_styles ⇒ Object (readonly)
Returns the value of attribute curr_styles.
5 6 7 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 5 def curr_styles @curr_styles end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
5 6 7 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 5 def layout @layout end |
#pdf ⇒ Object (readonly)
Returns the value of attribute pdf.
5 6 7 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 5 def pdf @pdf end |
Instance Method Details
#alignment ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 16 def alignment if curr_styles['text-align'] curr_styles['text-align'].to_sym else :left end end |
#block_code(content, first_line) ⇒ Object
Overloaded function for images, equations and maybe someday even code
34 35 36 37 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 34 def block_code(content, first_line) BlockCodeHandler.new(pdf, layout, first_line, content) '' end |
#double_emphasis(text) ⇒ Object
bold
49 50 51 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 49 def double_emphasis(text) "<b>#{text}</b>" end |
#emphasis(text) ⇒ Object
italic
44 45 46 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 44 def emphasis(text) "<i>#{text}</i>" end |
#header(text, _header_level) ⇒ Object
28 29 30 31 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 28 def header(text, _header_level) @header_maker = Poster::HeaderMaker.new(pdf, layout) unless @header_maker @header_maker.create_header(text, curr_styles) end |
#highlight(text) ⇒ Object
inline ==highlighting==
68 69 70 71 72 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 68 def highlight(text) color = layout.respond_to?(:highlight) ? layout.highlight['color'] : '#f700ff' color.sub!('#', '') "<color rgb='#{color}'>#{text}</color>" end |
#paragraph(text) ⇒ Object
24 25 26 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 24 def paragraph(text) pdf.text text, inline_format: true, align: alignment end |
#preprocess(full_document) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 7 def preprocess(full_document) @pdf = Poster.pdf @layout = Poster.layout @curr_styles = Poster.current_styles curr_styles['font-size'] = layout.font_size unless curr_styles.key? 'font-size' pdf.font_size curr_styles['font-size'] full_document end |
#superscript(text) ⇒ Object
super^script
59 60 61 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 59 def superscript(text) "<sup>#{text}</sup>" end |
#underline(text) ⇒ Object
underline
54 55 56 |
# File 'lib/bread/basket/poster/text_renderer.rb', line 54 def underline(text) "<u>#{text}</u>" end |