Class: Build

Inherits:
Object
  • Object
show all
Defined in:
lib/aml/Build.rb

Constant Summary collapse

@@structure =
[]
@@selfClosing =
[]

Instance Method Summary collapse

Constructor Details

#initialize(attribute = nil) ⇒ Build

Returns a new instance of Build.



8
9
10
11
12
13
14
15
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
# File 'lib/aml/Build.rb', line 8

def initialize(attribute=nil)
	@argument = Argument.new()
	@argument.define('[b]uild', nil, 'input file path and name', true)
	#@argument.define('[w]atch', false, 'watch for build updates')
	@argument.define('[s]elf[c]losing', true, 'enable self closing tags')
	@argument.define('[p]ath', nil, 'output file path')
	@argument.define('[n]ame', nil, 'output file name')
	@argument.define('[e]xtension', 'html', 'output file extension')
	@argument.define('[o]utput', nil, 'output file path and name')
	@argument.define('[h]elp', false, 'list all arguments')
	@argument.parse(attribute)
	if @argument.get('build') != nil.to_s
		@argument.set('path', File.dirname(@argument.get('build'))) if @argument.get('path') == nil.to_s
		@argument.set('name', File.basename(@argument.get('build'),'.*')) if @argument.get('name') == nil.to_s
		if @argument.get('output') == nil.to_s
			@argument.set('output', File.join(@argument.get('path'), @argument.get('name') + '.' + @argument.get('extension')))
		else
			@argument.set('path', File.dirname(@argument.get('output')))
			@argument.set('name', File.basename(@argument.get('output'),'.*'))
			@argument.set('extension', File.extname(@argument.get('output'))[1..-1])
		end
	end

	if @argument.get('selfclosing').to_s.downcase == 'true'
		@@selfClosing = %w[area base basefont bgsound br col frame hr img isindex input keygen link meta param source track wbr]
	elsif @argument.get('selfclosing').to_s.downcase != 'false'
		@@selfClosing = @argument.get('selfclosing').to_s.downcase.split(',')
		@argument.set('selfclosing','custom')
	end

	if @argument.show_help?
		@argument.show_help
	elsif @argument.has_requirements?
		@compile = Compile.new(@argument)
		@compile.process
		@compile.post_process
		if @compile.log.select{|k|k[:fail]==true}.count == 0
			console
			process_complete
		else
			console
		end
	else
		@argument.show_required
	end
end

Instance Method Details

#consoleObject



55
56
57
58
59
60
# File 'lib/aml/Build.rb', line 55

def console
	@compile.log.each do |log|
		line = log[:line] ? ":#{log[:line]}" : ""
		puts "#{log[:file]}#{line} - #{log[:message]}"
	end
end

#process_completeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/aml/Build.rb', line 62

def process_complete
	structure = prepare_structure(prepare_string_line_merge(@compile.structure))
	recursive_merge_lines(structure)
	structure.each do |group|
		recursive_close(group,0,0)
	end
	File.open(@argument.get('output'), 'w'){|file|
		struct_count = @@structure.count-1
		@@structure.each_with_index do |line,index|
			new_line = (index < struct_count) ? $/ : ""
			file.write(line+new_line) if line.strip.length > 0
		end
	}
	puts "Build completed."
end