Class: BuildMaster::FileProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/buildmaster/site/file_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject (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_fileObject (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_documentObject



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

Returns:

  • (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

Returns:

  • (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_targetObject



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