Class: BuildMaster::FileProcessor
- Inherits:
-
Object
- Object
- BuildMaster::FileProcessor
- Defined in:
- lib/buildmaster/site/file_processor.rb
Instance Attribute Summary collapse
-
#content_file ⇒ Object
readonly
Returns the value of attribute content_file.
-
#target_file ⇒ Object
readonly
Returns the value of attribute target_file.
Instance Method Summary collapse
- #generate_document ⇒ Object
-
#initialize(template, content_file, sitespec) ⇒ FileProcessor
constructor
A new instance of FileProcessor.
- #is_html? ⇒ Boolean
- #out_of_date? ⇒ Boolean
- #write_to_target ⇒ Object
Constructor Details
#initialize(template, content_file, sitespec) ⇒ FileProcessor
Returns a new instance of FileProcessor.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/buildmaster/site/file_processor.rb', line 9 def initialize(template, content_file, sitespec) @template = template @content_file = content_file @sitespec = sitespec @content_engine = sitespec.content_engines.for_source(content_file) if @content_engine basename = content_file.basename @path = sitespec.relative_to_root(content_file).parent.join("#{basename}.html") @target_file = sitespec.output_dir.file(@path) else @target_file = sitespec.output_dir.file(sitespec.relative_to_root(content_file)) end end |
Instance Attribute Details
#content_file ⇒ Object (readonly)
Returns the value of attribute content_file.
7 8 9 |
# File 'lib/buildmaster/site/file_processor.rb', line 7 def content_file @content_file end |
#target_file ⇒ Object (readonly)
Returns the value of attribute target_file.
7 8 9 |
# File 'lib/buildmaster/site/file_processor.rb', line 7 def target_file @target_file end |
Instance Method Details
#generate_document ⇒ Object
38 39 40 41 42 43 |
# File 'lib/buildmaster/site/file_processor.rb', line 38 def generate_document if (@content_engine) html_content = @content_engine.convert_to_html(content_file.load) process_html(html_content) end end |
#is_html? ⇒ Boolean
23 24 25 |
# File 'lib/buildmaster/site/file_processor.rb', line 23 def is_html? return target_file.extname == '.html' end |
#out_of_date? ⇒ Boolean
45 46 47 |
# File 'lib/buildmaster/site/file_processor.rb', line 45 def out_of_date? (not @target_file.exists?) || @target_file.older_than?(@content_file) end |
#write_to_target ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/buildmaster/site/file_processor.rb', line 27 def write_to_target if (@content_engine) document = generate_document target_file.write do |file| file.puts document.to_s end else content_file.copy_to(target_file) end end |