class Caracal::Core::Models::ParagraphModel
This class encapsulates the logic needed to store and manipulate paragraph data.
Attributes
paragraph_align[R]
paragraph_bgcolor[R]
paragraph_bold[R]
paragraph_color[R]
paragraph_italic[R]
paragraph_keep_next[R]
paragraph_size[R]
paragraph_style[R]
readers
paragraph_underline[R]
Public Class Methods
new(options={}, &block)
click to toggle source
initialization
Calls superclass method
Caracal::Core::Models::BaseModel::new
# File lib/caracal/core/models/paragraph_model.rb, line 33 def initialize(options={}, &block) content = options.delete(:content) { "" } text content, options.dup, &block @indent = nil super options, &block end
Public Instance Methods
bookmark_end(*args, &block)
click to toggle source
# File lib/caracal/core/models/paragraph_model.rb, line 126 def bookmark_end(*args, &block) options = Caracal::Utilities.extract_options!(args) options.merge!({ start: false}) model = Caracal::Core::Models::BookmarkModel.new(options, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, 'Bookmark ending tags require an id.' end model end
bookmark_start(*args, &block)
click to toggle source
.bookmarks
# File lib/caracal/core/models/paragraph_model.rb, line 114 def bookmark_start(*args, &block) options = Caracal::Utilities.extract_options!(args) options.merge!({ start: true}) model = Caracal::Core::Models::BookmarkModel.new(options, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, 'Bookmark starting tags require an id and a name.' end model end
br()
click to toggle source
.br
# File lib/caracal/core/models/paragraph_model.rb, line 140 def br model = Caracal::Core::Models::LineBreakModel.new() runs << model model end
empty?()
click to toggle source
indent(hash = nil)
click to toggle source
Getter/setter
# File lib/caracal/core/models/paragraph_model.rb, line 100 def indent(hash = nil) return @indent if hash.nil? unless [:left, :right].include?(hash.keys.first) && hash.values.first.is_a?(Integer) raise Caracal::Errors::InvalidModelError, 'the indent setter requires a hash like left: X or right: Y.' end @indent = { side: hash.keys.first, value: hash.values.first } end
link(*args, &block)
click to toggle source
.link
# File lib/caracal/core/models/paragraph_model.rb, line 147 def link(*args, &block) options = Caracal::Utilities.extract_options!(args) options.merge!({ content: args[0] }) if args[0] options.merge!({ href: args[1] }) if args[1] model = Caracal::Core::Models::LinkModel.new(options, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, ':link method must receive strings for the display text and the external href.' end model end
page()
click to toggle source
.page
# File lib/caracal/core/models/paragraph_model.rb, line 162 def page model = Caracal::Core::Models::PageBreakModel.new({ wrap: false }) runs << model model end
plain_text()
click to toggle source
.plaintext
# File lib/caracal/core/models/paragraph_model.rb, line 65 def plain_text runs.collect { |run| run.try(:text_content).to_s }.join(' ').strip end
run_attributes()
click to toggle source
.run_attributes
# File lib/caracal/core/models/paragraph_model.rb, line 53 def run_attributes { color: paragraph_color, size: paragraph_size, bold: paragraph_bold, italic: paragraph_italic, underline: paragraph_underline, bgcolor: paragraph_bgcolor } end
runs()
click to toggle source
.runs
# File lib/caracal/core/models/paragraph_model.rb, line 48 def runs @runs ||= [] end
text(*args, &block)
click to toggle source
.text
# File lib/caracal/core/models/paragraph_model.rb, line 169 def text(*args, &block) options = Caracal::Utilities.extract_options!(args) options.merge!({ content: args.first }) if args.first model = Caracal::Core::Models::TextModel.new(options, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, ':text method must receive a string for the display text.' end model end
Private Instance Methods
option_keys()
click to toggle source
# File lib/caracal/core/models/paragraph_model.rb, line 200 def option_keys [:content, :style, :align, :color, :size, :bold, :italic, :underline, :bgcolor] end