Class: Sprout::SimpleResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/sprout/simple_resolver.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(template, output, files, base_dir = nil) ⇒ SimpleResolver

Returns a new instance of SimpleResolver.



29
30
31
32
33
34
35
36
37
# File 'lib/sprout/simple_resolver.rb', line 29

def initialize(template, output, files, base_dir=nil)
  @template = template
  @output = output
  @files = files
  @base_dir = base_dir
  @ignored_files = []
  execute
  finish
end

Instance Method Details

#edit_warningObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sprout/simple_resolver.rb', line 76

def edit_warning
  return "  /*************************************\n   * DO NOT EDIT THIS FILE!\n   * This file was auto-generated from\n   * an ERB template which can be\n   * found at: \n   * \#{@template}\n   *************************************/\n"
end

#executeObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sprout/simple_resolver.rb', line 39

def execute
  template_file = File.open(@template, 'r')
  content = template_file.read
  result = ERB.new(content, nil, '>').result(binding)

  output_file = File.open(@output, 'w')
  output_file.write(result)

  template_file.close
  output_file.close
end

#filesObject



51
52
53
# File 'lib/sprout/simple_resolver.rb', line 51

def files
  return @files
end

#finishObject



55
56
57
58
59
60
61
62
# File 'lib/sprout/simple_resolver.rb', line 55

def finish
  if(@ignored_files.size > 0)
    Logger.puts '>> SimpleResolver ignored the following files because their names were invalid:'
    @ignored_files.each do |file|
      puts file
    end
  end
end

#xml_edit_warningObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sprout/simple_resolver.rb', line 64

def xml_edit_warning
  return "<!--\nDO NOT EDIT THIS FILE!\nThis file was auto-generated from\nan ERB template which can be\nfound at: \n\#{@template}\n-->\n"
end