Class: PetitFelix::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/felix/config.rb

Constant Summary collapse

DEFAULT_OPTIONS =

Global defaults

{
	"image_dir" => (File.join("assets","images")),
	"input_files" => (File.join("md","*")),
	"output_dir" => (File.join("output")),
	"task" => "pdf-single",
}
CL_DATA =

Hash for custom command line argument calls

{

}

Instance Method Summary collapse

Instance Method Details

#cl_add_config(command, args, index, cl_args) ⇒ Object

Command Line Arguments



29
30
31
# File 'lib/felix/config.rb', line 29

def cl_add_config command, args, index, cl_args
	cl_args[command] = args[index + 1]
end

#load_cl_args(args) ⇒ Object

Loads command line arguments



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/felix/config.rb', line 123

def load_cl_args args
	cl_args = {}
	
	index = 0
	
	args.each do |com|
	
		command = com.downcase
	
		if command.start_with? "--"
			command = command[2..]
		
			if !@processed_arguments.include? command
		
				if CL_DATA.key? command
				
					CL_DATA[command].call command, args, index, cl_args

				else
				
					cl_add_config command, args, index, cl_args

				end
				
				@processed_arguments << command
				
			end
		end
		
		index+=1
	end

	cl_args
end

#load_config(wm, passed_args, args) ⇒ Object

Loads default rendering options and config Default arguments are loaded first, then arguments loaded in ./default.cfg, then command line arguments, then finally any arguments defined in the metadata.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/felix/config.rb', line 41

def load_config wm, passed_args, args

	@processed_arguments = []
	
	# Felix metadata handler
	 = PetitFelix::Metadata.new
	
	# load global default options
	default_options = Marshal.load(Marshal.dump(DEFAULT_OPTIONS))
	
	# Loads the default configuation in default.cfg
	
	default_config = {}
	
	default_file = File.join("default.cfg")
	
	if File.file? default_file
		
		default_config = .(File.read default_file)
	end
	
	# Loads command line arguments
	cl_args = load_cl_args args
	
	# Loads default worker options
	worker = ""
	worker_options = nil
	
	# Gets the task to run.
	
	if default_options.key? "task"
		worker = default_options["task"]
	end
	
	if default_config.key? "task"
		worker = default_config["task"]
	end
	
	if cl_args.key? "task"
		worker = cl_args["task"]
	end
	
	if passed_args.key? "task"
		worker = passed_args["task"]
	end
	
	# Loads the worker based on the task.
	
	if worker != ""
		worker_options = Marshal.load(Marshal.dump(wm.get_task_options worker))
	end

	# Now, assemble the options in order
	# First, default options
	options = default_options
	
	# Then loading default worker args
	if !worker_options.nil?
		worker_options.keys.each do |key|
			options[key] = worker_options[key]
		end
	end
	
	# Then loading default config file
	default_config.keys.each do |key|
		options[key] = default_config[key]
	end
		
	# Then loading CLI arguments
	cl_args.keys.each do |key|
		options[key] = cl_args[key]
	end
	
	# Then loading passed arguments
	passed_args.keys.each do |key|
		options[key] = passed_args[key]
	end

	options
end