Class: Website::HTMLwithPygments
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Website::HTMLwithPygments
- Defined in:
- lib/it_tools/html_publish.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
-
#ops ⇒ Object
Returns the value of attribute ops.
Instance Method Summary collapse
- #block_code(code, language) ⇒ Object
- #get_header_label(header_level) ⇒ Object
- #header(text, header_level) ⇒ Object
-
#initialize(options = {}) ⇒ HTMLwithPygments
constructor
A new instance of HTMLwithPygments.
- #postprocess(full_document) ⇒ Object
- #set_less_significant_to_zero(header_level) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ HTMLwithPygments
Returns a new instance of HTMLwithPygments.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/it_tools/html_publish.rb', line 15 def initialize( = {}) super @ops = {} @ops.merge! @log = Logger.new('log.txt') if level = @ops[:debug_level] @log.level = level else @log.level = Logger::INFO end $toc1 = "" $last_header_level = 0 $last_header_count = 0 $header = Array.new() 0.upto(6) { |i| $header[i] = 0 } end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
13 14 15 |
# File 'lib/it_tools/html_publish.rb', line 13 def log @log end |
#ops ⇒ Object
Returns the value of attribute ops.
13 14 15 |
# File 'lib/it_tools/html_publish.rb', line 13 def ops @ops end |
Instance Method Details
#block_code(code, language) ⇒ Object
32 33 34 |
# File 'lib/it_tools/html_publish.rb', line 32 def block_code(code, language) Pygments.highlight(code, :lexer => language) end |
#get_header_label(header_level) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/it_tools/html_publish.rb', line 35 def get_header_label( header_level ) index = header_level - 1 $header[index] = $header[index] + 1 header_level.upto($header.length - 1) { |i| $header[i] = 0 } header_string = "" 0.upto(header_level - 1) { |i| if i == header_level - 1 header_string += $header[i].to_s @log.debug "Header String: #{header_string}. Header Entry: #{$header[i]}" else header_string += $header[i].to_s + "." end } return header_string end |
#header(text, header_level) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/it_tools/html_publish.rb', line 53 def header(text, header_level) header_label = get_header_label(header_level) id = text.gsub(" ", "_") $toc1 += "<div class=\"toc#{header_level}\"><a href=\"##{id}\">#{header_label} - #{text}</a></div><br/>\n" return "\n<h#{header_level} id=\"#{id}\">#{header_label} - #{text}</h#{header_level}>\n" end |
#postprocess(full_document) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/it_tools/html_publish.rb', line 59 def postprocess(full_document) temp = $toc1 $toc1 = "" 0.upto(6) { |i| $header[i] = 0 } return temp + full_document end |
#set_less_significant_to_zero(header_level) ⇒ Object
50 51 52 |
# File 'lib/it_tools/html_publish.rb', line 50 def set_less_significant_to_zero(header_level) 10.times {|i| p i+1} end |