Class: Erector::Erected
Instance Method Summary collapse
- #classname ⇒ Object
- #classnames ⇒ Object
- #convert ⇒ Object
- #filename ⇒ Object
-
#initialize(in_file, superklass = 'Erector::Widget', method_name = 'content') ⇒ Erected
constructor
A new instance of Erected.
- #parent_class ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(in_file, superklass = 'Erector::Widget', method_name = 'content') ⇒ Erected
Returns a new instance of Erected.
10 11 12 13 14 |
# 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 |
Instance Method Details
#classname ⇒ Object
31 32 33 |
# File 'lib/erector/erect/erected.rb', line 31 def classname classnames[0] end |
#classnames ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/erector/erect/erected.rb', line 16 def filename dir + basename + ".rb" end |
#parent_class ⇒ Object
35 36 37 |
# File 'lib/erector/erect/erected.rb', line 35 def parent_class classnames[1] end |
#text ⇒ Object
39 40 41 |
# File 'lib/erector/erect/erected.rb', line 39 def text File.read(@in_file) end |