Class: IncludeEngine

Inherits:
KnitrEngine show all
Includes:
Singleton
Defined in:
lib/gknit/include_engine.rb

Overview

Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation, without fee and without a signed licensing agreement, is hereby granted, provided that the above copyright notice, this paragraph and the following two paragraphs appear in all copies, modifications, and distributions.

IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Author:

  • Rodrigo Botafogo

Instance Attribute Summary collapse

Attributes inherited from KnitrEngine

#background, #class__output, #class__source, #collapse, #comment, #dev, #dev__args, #dpi, #echo, #error, #eval, #external, #fig__align, #fig__asp, #fig__cap, #fig__dim, #fig__env, #fig__ext, #fig__filename, #fig__height, #fig__keep, #fig__lp, #fig__ncol, #fig__path, #fig__pos, #fig__process, #fig__retina, #fig__scap, #fig__sep, #fig__show, #fig__showtext, #fig__subcap, #fig__width, #highlight, #include, #keep, #label, #message, #options, #out__extra, #out__height, #out__width, #prompt, #render, #resize__height, #resize__width, #results, #sanitize, #size, #split, #strip__white, #tidy, #tidy__opts, #warning

Instance Method Summary collapse

Methods inherited from KnitrEngine

#add, #add_hook, #capture_plot, device, #fig_keep, #figure_artifact_ready?, #file_ext, #process_options, #scalar_option_string, #units

Constructor Details

#initializeIncludeEngine


Ruby engine for processing 'include' chunks



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
# File 'lib/gknit/include_engine.rb', line 33

def initialize

  # call super to make @base_engine available
  super
       
  @engine = Proc.new do |options|
    # Ensure include chunks always load file content into options['code'].
    # This keeps include behavior working even if R-side wrappers are replaced.
    begin
      label = options['label'].unboxed_get(0).to_s
      relative_opt = options['relative']
      relative =
        if relative_opt.respond_to?(:unboxed_get)
          !!relative_opt.unboxed_get(0)
        else
          false
        end
      options.code = GalaazUtil.inline_file(label, relative)
    rescue StandardError => e
      options.code = "# Include failed: #{e.message}"
    end
    @base_engine.call(options)
  end
  
  # Add the include engine function for processing the rb block
  add(include: @engine)
  
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine.



27
28
29
# File 'lib/gknit/include_engine.rb', line 27

def engine
  @engine
end