Method: Erector::Erect#to_html

Defined in:
lib/erector/erect/erect.rb

#to_htmlObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/erector/erect/erect.rb', line 118

def to_html
  files.each do |file|
    say "Erecting #{file}... "
    #todo: move this into Erected with better tests for the naming methods
    begin
      #todo: fail if file isn't a .rb file
      require file
      filename = file.split('/').last.gsub(/\.rb$/, '')
      widget_name = camelize(filename)
      widget_class = constantize(widget_name)

      if widget_class < Erector::Widget
        widget = widget_class.new
        #todo: skip if it's missing a no-arg constructor
        dir = output_dir || File.dirname(file)
        ::FileUtils.mkdir_p(dir)
        output_file = "#{dir}/#{filename}.html"
        File.open(output_file, "w") do |f|
          f.puts widget.to_html
        end
        say " --> #{output_file}\n"
      else
        say " -- not a widget, skipping\n"
      end
    rescue => e
      puts e
      puts e.backtrace.join("\n\t")
      @success = false
    end
  end
end