class Paru::PandocFilter::CodeBlock

A CodeBlock is a Block level node with an attribute object and the code as a string

@!attribute attr

@return [Attr]

@!attribute string

@return [String]

Attributes

attr[RW]
string[RW]

Public Class Methods

from_code_string(code_string, language = "") click to toggle source

Create a new CodeBlock based on a string and, optionally, a language

@param code_string [String] the string with code to use as the

contents of the CodeBlock

@param language [String] the optional language class @return [CodeBlock]

# File lib/paru/filter/code_block.rb, line 97
def self.from_code_string(code_string, language = "")
    attributes = ["", [language], []]
    code_block = CodeBlock.new [attributes, code_string]
    return code_block
end
from_file(filename, language = "") click to toggle source

Create a new CodeBlock based on the contents of a file, and, optionally, a language

@param filename {String} the path to the file to read the

contents from

@param language {String} the language of the contents

@return [CodeBlock]

# File lib/paru/filter/code_block.rb, line 78
def self.from_file(filename, language = "")
    return self.from_code_string(File.read(filename), language) 
end
new(contents) click to toggle source

Create a new CodeBlock based on the contents

@param contents [Array] an array with the attribute and the code

string
# File lib/paru/filter/code_block.rb, line 41
def initialize(contents)
    @attr = Attr.new contents[0]
    @string = contents[1]
end

Public Instance Methods

ast_contents() click to toggle source

An AST representation of this CodeBlock

# File lib/paru/filter/code_block.rb, line 47
def ast_contents()
    [
        @attr.to_ast,
        @string
    ]
end
has_string?() click to toggle source

Has this CodeBlock string contents?

@return [Boolean] true

# File lib/paru/filter/code_block.rb, line 57
def has_string?()
    true
end
to_code_string() click to toggle source

Get this CodeBlock’s contents as a string

@return [String]

# File lib/paru/filter/code_block.rb, line 85
def to_code_string()
    return @string
end
to_file(filename) click to toggle source

Write this CodeBlock’s contents to file

@param filename {String} the path to the file to write

# File lib/paru/filter/code_block.rb, line 64
def to_file(filename)
    File.open(filename, "w") do |file|
        file.write "#{@string}\n"
    end
end