Class: Heading
- Defined in:
- lib/almirah/doc_items/heading.rb
Constant Summary collapse
- @@global_section_number =
""
Instance Attribute Summary collapse
-
#anchor_id ⇒ Object
Returns the value of attribute anchor_id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#section_number ⇒ Object
Returns the value of attribute section_number.
Attributes inherited from Paragraph
Attributes inherited from DocItem
Class Method Summary collapse
Instance Method Summary collapse
- #get_section_info ⇒ Object
-
#initialize(text, level) ⇒ Heading
constructor
A new instance of Heading.
- #to_html ⇒ Object
Methods inherited from Paragraph
Methods inherited from TextLine
add_lazy_doc_id, #bold, #bold_and_italic, #change_state, #format_string, #italic, #link
Constructor Details
#initialize(text, level) ⇒ Heading
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/almirah/doc_items/heading.rb', line 11 def initialize(text, level) @text = text @level = level @anchor_id = getTextWithoutSpaces() if @@global_section_number == "" @@global_section_number = "1" for n in 1..(level-1) do @@global_section_number += ".1" end else previous_level = @@global_section_number.split(".").length if previous_level == level a = @@global_section_number.split(".") a[-1] = (a[-1].to_i() +1).to_s @@global_section_number = a.join(".") elsif level > previous_level a = @@global_section_number.split(".") a.push("1") @@global_section_number = a.join(".") else # level < previous_level a = @@global_section_number.split(".") delta = previous_level - level a.pop(delta) @@global_section_number = a.join(".") # increment a = @@global_section_number.split(".") a[-1] = (a[-1].to_i() +1).to_s @@global_section_number = a.join(".") end end @section_number = @@global_section_number end |
Instance Attribute Details
#anchor_id ⇒ Object
Returns the value of attribute anchor_id.
6 7 8 |
# File 'lib/almirah/doc_items/heading.rb', line 6 def anchor_id @anchor_id end |
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/almirah/doc_items/heading.rb', line 5 def level @level end |
#section_number ⇒ Object
Returns the value of attribute section_number.
7 8 9 |
# File 'lib/almirah/doc_items/heading.rb', line 7 def section_number @section_number end |
Class Method Details
.reset_global_section_number ⇒ Object
68 69 70 |
# File 'lib/almirah/doc_items/heading.rb', line 68 def self.reset_global_section_number @@global_section_number = "" end |
Instance Method Details
#get_section_info ⇒ Object
51 52 53 |
# File 'lib/almirah/doc_items/heading.rb', line 51 def get_section_info s = @section_number + " " + @text end |
#to_html ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/almirah/doc_items/heading.rb', line 55 def to_html s = '' if @@htmlTableRenderInProgress s += "</table>\n" @@htmlTableRenderInProgress = false end headingLevel = level.to_s s += "<a name=\"#{@anchor_id}\"></a>\n" s += "<h#{headingLevel}> #{@text} <a href=\"\##{@anchor_id}\" class=\"heading_anchor\">" s += "¶</a></h#{headingLevel}>" return s end |