16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/mayday/script_generator.rb', line 16
def to_ruby(opts={})
opts[:exit_after] = true if opts[:exit_after] == nil;
opts[:output] = true if opts[:output] == nil;
require_lines = libs_to_require.map { |lib_to_require| "require '#{lib_to_require}'" }.join("\n")
function_defs = flags.map(&:function_def_string).join
exit_chunk = if opts[:exit_after]
<<-CODE
if #{any_errors_variable_name}
exit(1)
else
exit
end
CODE
else
""
end
call_flag_functions_chunk = call_flag_functions_string("file", opts[:output])
<<-CODE
# encoding: utf-8
Encoding.default_external = "utf-8"
#{require_lines}
#{function_defs}
Dir[ENV["SRCROOT"] + "/**/*.{m,h,swift}"].each do |filename|
# Could be a dir with .m, like Underscore.m's dir
if (File.file?(filename))
file = File.open(filename, 'r')
#{call_flag_functions_chunk}
end
end
#{exit_chunk}
CODE
end
|