class Erector::Erected

Public Class Methods

new(in_file, superklass = 'Erector::Widget', method_name = 'content') click to toggle source
# File lib/erector/erect/erected.rb, line 10
def initialize(in_file, superklass = 'Erector::Widget', method_name = 'content')
  @in_file = in_file
  @superklass = superklass
  @method_name = method_name
end

Public Instance Methods

classname() click to toggle source
# File lib/erector/erect/erected.rb, line 31
def classname
  classnames[0]
end
classnames() click to toggle source
# File lib/erector/erect/erected.rb, line 20
def classnames
  base = classize(basename)
  parent = File.dirname(@in_file)
  grandparent = File.dirname(parent)
  if File.basename(grandparent) == "views"
    ["Views::" + classize(File.basename(parent)) + "::" + base, @superklass]
  else
    [base, @superklass]
  end
end
convert() click to toggle source
# File lib/erector/erect/erected.rb, line 43
def convert
  parser = RhtmlParser.new
  parsed = parser.parse(File.read(@in_file))
  if parsed.nil?
    raise "Could not parse #{@in_file}\n" +
      parser.failure_reason
  else
    File.open(filename, "w") do |f|
      f.puts("class #{classname} < #{parent_class}")
      f.puts("  def #{@method_name}")
      f.puts(parsed.set_indent(2).convert)
      f.puts("  end")
      f.puts("end")
    end
  end
end
filename() click to toggle source
# File lib/erector/erect/erected.rb, line 16
def filename
  dir + basename + ".rb"
end
parent_class() click to toggle source
# File lib/erector/erect/erected.rb, line 35
def parent_class
  classnames[1]
end
text() click to toggle source
# File lib/erector/erect/erected.rb, line 39
def text
  File.read(@in_file)
end

Protected Instance Methods

basename() click to toggle source
# File lib/erector/erect/erected.rb, line 62
def basename
  @in_file.split("/").last.gsub(/\..*$/, '')
end
classize(filename) click to toggle source
# File lib/erector/erect/erected.rb, line 71
def classize(filename)
  filename.split("_").map{|part| part.capitalize}.join
end
dir() click to toggle source
# File lib/erector/erect/erected.rb, line 66
def dir
  x = File.dirname(@in_file)
  return (x == ".") ? "" : "#{x}/"
end