Class: Erector::Erected
Instance Method Summary collapse
- #classname ⇒ Object
- #convert ⇒ Object
- #filename ⇒ Object
-
#initialize(in_file) ⇒ Erected
constructor
A new instance of Erected.
- #text ⇒ Object
Constructor Details
#initialize(in_file) ⇒ Erected
Returns a new instance of Erected.
9 10 11 |
# File 'lib/erector/erected.rb', line 9 def initialize(in_file) @in_file = in_file end |
Instance Method Details
#classname ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/erector/erected.rb', line 17 def classname base = classize(basename) parent = File.dirname(@in_file) grandparent = File.dirname(parent) if File.basename(grandparent) == "views" base = "Views::" + classize(File.basename(parent)) + "::" + base end base end |
#convert ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/erector/erected.rb', line 31 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} < Erector::Widget") f.puts(" def render") f.puts(parsed.set_indent(2).convert) f.puts(" end") f.puts("end") end end end |
#filename ⇒ Object
13 14 15 |
# File 'lib/erector/erected.rb', line 13 def filename dir + basename + ".rb" end |
#text ⇒ Object
27 28 29 |
# File 'lib/erector/erected.rb', line 27 def text File.read(@in_file) end |