Class: Qippet::Boxes::CodeBox

Inherits:
Box
  • Object
show all
Defined in:
lib/qippet/boxes/code_box.rb

Overview

Box for creating code

Defined Under Namespace

Classes: BareColorFormatter

Constant Summary collapse

ALLOWED_ATTRIBUTES =
%i[source path range].freeze
TAB_SPACE =
20
CODE_LINE_HEIGHT =
19
CODE_CHAR_WIDTH =
8

Constants inherited from Box

Box::PADDING, Box::PADDING_X

Instance Attribute Summary collapse

Attributes inherited from Box

#image, #node

Instance Method Summary collapse

Methods inherited from Box

#add_attributes, #children, setup_attributes

Constructor Details

#initializeCodeBox

Returns a new instance of CodeBox.



34
35
36
37
# File 'lib/qippet/boxes/code_box.rb', line 34

def initialize
  super
  @show_line = false
end

Instance Attribute Details

#code_contentObject (readonly)

Returns the value of attribute code_content.



26
27
28
# File 'lib/qippet/boxes/code_box.rb', line 26

def code_content
  @code_content
end

#code_linesObject (readonly)

Returns the value of attribute code_lines.



26
27
28
# File 'lib/qippet/boxes/code_box.rb', line 26

def code_lines
  @code_lines
end

#formatterObject (readonly)

Returns the value of attribute formatter.



26
27
28
# File 'lib/qippet/boxes/code_box.rb', line 26

def formatter
  @formatter
end

#show_lineObject (readonly)

Returns the value of attribute show_line.



26
27
28
# File 'lib/qippet/boxes/code_box.rb', line 26

def show_line
  @show_line
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



26
27
28
# File 'lib/qippet/boxes/code_box.rb', line 26

def tokenizer
  @tokenizer
end

#writerObject (readonly)

Returns the value of attribute writer.



26
27
28
# File 'lib/qippet/boxes/code_box.rb', line 26

def writer
  @writer
end

Instance Method Details

#add_childObject



39
40
41
# File 'lib/qippet/boxes/code_box.rb', line 39

def add_child(*)
  throw :no_children_for_node, "Code Box cannot contain chidren"
end

#renderObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/qippet/boxes/code_box.rb', line 43

def render
  fetch_code_from_source
  extract_line_range
  return nil if code_content.nil?

  setup_syntax_highliter
  setup_writer
  super
  write_code_on_image
end