Module: GlimHelpers

Defined in:
lib/glim_helpers.rb

Instance Method Summary collapse

Instance Method Details

#include_file(entry_path, relative_path = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/glim_helpers.rb', line 24

def include_file(entry_path, relative_path = nil)
    relative_path ||= entry_path
    raise("File not found: #{entry_path}") if !File.file?(entry_path)
    result = "\n<file pathname=\"#{relative_path}\">"
    result += File.read(entry_path)
    result + "</file>\n"
end

#include_files(path, prefix = '') ⇒ Object

TODO: modify this so that you can also include a single file, list of files, etc



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/glim_helpers.rb', line 4

def include_files(path, prefix='')
    putt :include_files, "include_files(path: #{path}, prefix: #{prefix})"
    result = ""
    Dir.foreach(path) do |entry|
        next if entry.start_with?('.')
        entry_path = File.join(path, entry)
        relative_path = File.join(prefix, entry)
        if File.directory?(entry_path)
            result += include_files(entry_path, relative_path)
        else
            # elsif File.file?(entry_path)
            # result +=  "\n```\n# File: #{relative_path}\n"
            # result += File.read(entry_path)
            # result += "\n```\n"
            result += include_file(entry_path, relative_path)
        end
    end
    result
end

#prompt_output_filesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/glim_helpers.rb', line 33

def prompt_output_files 
"\n\nTODO \n\nfix this for xml\n\nSYSTEM MESSAGE: ALWAYS, when asked to generate source code or other text files, use the following format:\n<file pathname=\"path_to_file/hello.rb\">\nputs \"Hello from Line 1\"\nputs \"hello from Line 2\"\n</file>\nSo, the example above shows how you would include a file called \"hello.rb\" that belongs in the subdirectory \"path_to_file\" of the current directory. \nThe file would contain two \"puts\" statements. \nUse this for all text files you generate, not just source code.\n\n"
end