module Psychic::Runner::CodeHelper
Public Instance Methods
absolute_source_file()
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 46 def absolute_source_file return nil if source_file.nil? if basedir File.expand_path source_file, basedir else source_file end end
code_block(source_code, language, opts = { format: :markdown })
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 77 def code_block(source_code, language, opts = { format: :markdown }) case opts[:format] when :rst ReStructuredTextHelper.code_block source_code, language when :markdown MarkdownHelper.code_block source_code, language else fail IllegalArgumentError, "Unknown format: #{format}" end end
detect_language()
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 68 def detect_language File.extname(source_file) end
highlighted_code(formatter = 'terminal256')
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 72 def highlighted_code(formatter = 'terminal256') Highlighter.new(language: language, filename: absolute_source_file, formatter: formatter).highlight(source) end
language()
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 64 def language @language ||= detect_language end
source()
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 56 def source File.read absolute_source_file end
source?()
click to toggle source
# File lib/psychic/runner/code_helper.rb, line 60 def source? !absolute_source_file.nil? end