get_code_frag

in src/_plugins/code_excerpt_processor.rb [203:230]


    def get_code_frag(proj_rel_path, _frag_path, src_path, region)
      excerpt_yaml_path = File.join(Dir.pwd, 'tmp', '_fragments', @path_base, proj_rel_path + '.excerpt.yaml');
      if File.exist? excerpt_yaml_path
        yaml = YAML.load_file(excerpt_yaml_path)
        result = yaml[region]
        if result.nil?
          result = "CODE EXCERPT not found: region '#{region}' not found in #{excerpt_yaml_path}"
          log_puts result
        else
          lines = result.split(/(?<=\n)/) 
          result = escape_and_trim_code(lines)
        end
      
      
      
      
      elsif region.empty? && src_path && (File.exist? src_path)
        lines = File.readlines src_path
        result = escape_and_trim_code(lines)
        raise 'CODE EXCERPT not found: no .excerpt.yaml file ' \
         "and source contains docregions: #{src_path}" if result.include? '#docregion'
      else
        result = "CODE EXCERPT not found: #{excerpt_yaml_path}, region='#{region}'"
        log_puts result
      end
      result
    end