Permalink
Browse files

Added text and erb view types. Text works; ERB needs specs.

  • Loading branch information...
1 parent 1238af9 commit fa469c184a6dc84a1c2fe2f083d6e3dfe81513a0 @gilesbowkett committed Oct 2, 2008
Showing with 21 additions and 4 deletions.
  1. +1 −1 lib/controller.rb
  2. +7 −0 lib/erb_view.rb
  3. +3 −0 lib/text_view.rb
  4. +9 −2 lib/towelie.rb
  5. +1 −1 spec/towelie_spec.rb
View
@@ -4,7 +4,7 @@ def delegate_thru_view(*method_names)
method_names.each do |method_name|
class_eval <<-METHOD
def #{method_name}(*args)
- @view.to_ruby(@model.#{method_name}(*args))
+ @view.render(@model.#{method_name}(*args))
end
METHOD
end
View
@@ -0,0 +1,7 @@
+class ErbView < View
+ def render(nodes)
+ body = to_ruby(nodes.body)
+ name = nodes.name
+ filename = nodes.filename
+ end
+end
View
@@ -0,0 +1,3 @@
+class TextView < View
+ alias :render :to_ruby
+end
View
@@ -9,13 +9,20 @@
require "#{File.dirname(__FILE__) + "/"}node_analysis"
require "#{File.dirname(__FILE__) + "/"}model"
require "#{File.dirname(__FILE__) + "/"}view"
+require "#{File.dirname(__FILE__) + "/"}text_view"
+require "#{File.dirname(__FILE__) + "/"}erb_view"
require "#{File.dirname(__FILE__) + "/"}controller"
class Towelie
- def initialize
+ def initialize(view_format)
@model = Model.new
- @view = View.new
+ @view = case view_format
+ when :text
+ TextView.new
+ when :erb
+ ErbView.new
+ end
end
delegate_thru_model :parse, :duplication?, :method_definitions
delegate_thru_view :duplicated, :unique, :homonyms, :diff
View
@@ -3,7 +3,7 @@
describe Towelie do
before(:each) do
- @towelie = Towelie.new
+ @towelie = Towelie.new(:text)
end
before(:all) do
@the_nodes = [

0 comments on commit fa469c1

Please sign in to comment.