Class: Erector::Erected
Instance Method Summary collapse
- #classname ⇒ Object
- #classnames ⇒ Object
- #convert ⇒ Object
- #filename ⇒ Object
-
#initialize(in_file) ⇒ Erected
constructor
A new instance of Erected.
- #parent_class ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(in_file) ⇒ Erected
Returns a new instance of Erected.
10 11 12 |
# File 'lib/erector/erected.rb', line 10 def initialize(in_file) @in_file = in_file end |
Instance Method Details
#classname ⇒ Object
29 30 31 |
# File 'lib/erector/erected.rb', line 29 def classname classnames[0] end |
#classnames ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/erector/erected.rb', line 18 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, "Erector::RailsWidget"] else [base, "Erector::Widget"] end end |
#convert ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/erector/erected.rb', line 41 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 content") f.puts(parsed.set_indent(2).convert) f.puts(" end") f.puts("end") end end end |
#filename ⇒ Object
14 15 16 |
# File 'lib/erector/erected.rb', line 14 def filename dir + basename + ".rb" end |
#parent_class ⇒ Object
33 34 35 |
# File 'lib/erector/erected.rb', line 33 def parent_class classnames[1] end |
#text ⇒ Object
37 38 39 |
# File 'lib/erector/erected.rb', line 37 def text File.read(@in_file) end |