Class: EasyHtmlGenerator::Generator::Compile::Base
- Inherits:
-
Base
- Object
- Base
- EasyHtmlGenerator::Generator::Compile::Base
show all
- Defined in:
- lib/easy_html_generator/generator/compile/base.rb
Overview
this is the generator base class
Instance Attribute Summary
Attributes inherited from Base
#config
Instance Method Summary
collapse
Methods inherited from Base
#enabled?, #file_changed?, #generate, #initialize, #log, #log_running, #repetitive?, #store_file_hash, #tasks
Instance Method Details
#do_file(input_file, output_file, config) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/easy_html_generator/generator/compile/base.rb', line 34
def do_file(input_file, output_file, config)
return unless File.exist?(input_file) && File.file?(input_file)
log "-> do_file #{input_file.sub(@project.src_path, '').green}"
FileUtils.mkdir_p File.dirname(output_file)
input_content = File.read(input_file)
output_content = do_input!(input_content, input_file, output_file, config)
store_file_hash(input_file)
return unless output_content
File.write(output_file, output_content)
end
|
30
31
32
|
# File 'lib/easy_html_generator/generator/compile/base.rb', line 30
def do_input!(_input, _input_file)
fail NotImplementedError.new "#{self.class.name} is an abstract class."
end
|
#generate!(config) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/easy_html_generator/generator/compile/base.rb', line 8
def generate!(config)
walk_files(config) do |input_file, output_file|
next unless file_changed? input_file
do_file(input_file, output_file, config)
end
end
|
26
27
28
|
# File 'lib/easy_html_generator/generator/compile/base.rb', line 26
def input_to_output_file(input_file, config)
input_file.sub(config.source, config.target)
end
|
#walk_files(config) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/easy_html_generator/generator/compile/base.rb', line 16
def walk_files(config)
selector = File.join(config.source, config.selector)
Dir[selector].each do |input_file|
output_file = input_to_output_file(input_file, config)
yield(input_file, output_file)
end
end
|