Class: MarkdownToTeX::Processor
- Inherits:
-
Object
- Object
- MarkdownToTeX::Processor
- Defined in:
- lib/markdown_to_tex/processor.rb
Instance Attribute Summary collapse
-
#git_branch_name ⇒ Object
readonly
Returns the value of attribute git_branch_name.
-
#git_commit_line ⇒ Object
readonly
Returns the value of attribute git_commit_line.
-
#git_describe ⇒ Object
readonly
Returns the value of attribute git_describe.
-
#git_hash_wd_long ⇒ Object
readonly
Returns the value of attribute git_hash_wd_long.
-
#git_status ⇒ Object
readonly
Returns the value of attribute git_status.
-
#git_status_long ⇒ Object
readonly
Returns the value of attribute git_status_long.
-
#git_wd_hash ⇒ Object
readonly
Returns the value of attribute git_wd_hash.
-
#run_stamp ⇒ Object
readonly
Returns the value of attribute run_stamp.
Instance Method Summary collapse
-
#initialize(options) ⇒ Processor
constructor
A new instance of Processor.
- #job_signature ⇒ Object
- #process(text) ⇒ Object
Constructor Details
#initialize(options) ⇒ Processor
Returns a new instance of Processor.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/markdown_to_tex/processor.rb', line 28 def initialize() @options = @run_stamp = DateTime.now.to_s if @options[:git] IO.popen("git branch -v --no-abbrev").each do |l| if l =~ /(\*|.)\s+(\S+)\s+([0-9a-f]+)\s(.*)/ if $1 == "*" @git_branch_name = $2 @git_wd_hash_long = $3 @git_wd_hash = @git_wd_hash_long[0,6] @git_commit_line = $4 @git_commit_line.gsub!(/\#/, '\#') @git_commit_line.gsub!(/\%/, '\%') @git_commit_line.gsub!(/\[ahead.*\] /, '') @git_status = @git_wd_hash + ": " + @git_commit_line @git_status_long = @git_commit_line + '\\\\\\\\' + @git_wd_hash_long + '\\\\\\\\' + @git_branch_name end end end @git_describe = "(no names found for git describe)" IO.popen("git describe --dirty --long").each do |l| if l =~ /(.*)/ @git_describe = $1 end end @macros = { "__OO2_RUN_STAMP__" => @run_stamp, "__OO2_GIT_DESCRIBE__" => @git_describe, "__OO2_GIT_STATUS__" => @git_status, "__OO2_GIT_STATUS_LONG__" => @git_status_long, "__OO2_GIT_HASH_LONG__" => @git_wd_hash_long } else @macros = { } end end |
Instance Attribute Details
#git_branch_name ⇒ Object (readonly)
Returns the value of attribute git_branch_name.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_branch_name @git_branch_name end |
#git_commit_line ⇒ Object (readonly)
Returns the value of attribute git_commit_line.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_commit_line @git_commit_line end |
#git_describe ⇒ Object (readonly)
Returns the value of attribute git_describe.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_describe @git_describe end |
#git_hash_wd_long ⇒ Object (readonly)
Returns the value of attribute git_hash_wd_long.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_hash_wd_long @git_hash_wd_long end |
#git_status ⇒ Object (readonly)
Returns the value of attribute git_status.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_status @git_status end |
#git_status_long ⇒ Object (readonly)
Returns the value of attribute git_status_long.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_status_long @git_status_long end |
#git_wd_hash ⇒ Object (readonly)
Returns the value of attribute git_wd_hash.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def git_wd_hash @git_wd_hash end |
#run_stamp ⇒ Object (readonly)
Returns the value of attribute run_stamp.
23 24 25 |
# File 'lib/markdown_to_tex/processor.rb', line 23 def run_stamp @run_stamp end |
Instance Method Details
#job_signature ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/markdown_to_tex/processor.rb', line 73 def job_signature s = [] s << "% md2tex run at #{@run_stamp}" s << "% description: #{@git_describe}" if @git_describe s << "% revision: #{@git_wd_hash_long}" if @git_wd_hash_long if @git_commit_line s << "% commit log:" s << "% #{@git_commit_line}" end s.join("\n")+"\n" end |
#process(text) ⇒ Object
68 69 70 71 |
# File 'lib/markdown_to_tex/processor.rb', line 68 def process(text) @renderer = Redcarpet::Markdown.new(MarkdownToTeX::Renderer) TextProcessor.process_final(@renderer.render(text), @macros) end |