Class: CodeInclusion::Code

Inherits:
Object
  • Object
show all
Defined in:
lib/polytexnic/code_inclusion.rb

Constant Summary collapse

DEFAULT_LANGUAGE =
'text'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(retrieval_args, render_args) ⇒ Code

Returns a new instance of Code.



156
157
158
# File 'lib/polytexnic/code_inclusion.rb', line 156

def initialize(retrieval_args, render_args)
  @retrieval_args, @render_args = retrieval_args, render_args
end

Instance Attribute Details

#render_argsObject (readonly)

Returns the value of attribute render_args.



154
155
156
# File 'lib/polytexnic/code_inclusion.rb', line 154

def render_args
  @render_args
end

#retrieval_argsObject (readonly)

Returns the value of attribute retrieval_args.



154
155
156
# File 'lib/polytexnic/code_inclusion.rb', line 154

def retrieval_args
  @retrieval_args
end

Class Method Details

.for(line) ⇒ Object

Returns an instance of CodeInclusion::Code or nil



149
150
151
152
# File 'lib/polytexnic/code_inclusion.rb', line 149

def self.for(line)
  args = Args.new(line)
  new(args.retrieval, args.render) if args.code_inclusion_line?
end

Instance Method Details

#to_sObject

Returns the formatted code or an error message



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/polytexnic/code_inclusion.rb', line 161

def to_s
  return unless filename

  result = []
  result << "%= lang:#{language}#{highlight}"
  result << '\begin{code}'
  result.concat(raw_code)
  result << '\end{code}'

  rescue CodeInclusionException => e
    code_error(e.message)
end