Permalink
Browse files

Add some simple examples for unconventional AMo and AP use

  • Loading branch information...
1 parent b20d684 commit 45d41d8012c605f21de51e7018fa31e1d07776eb @wycats wycats committed Jul 19, 2009
View
50 actionpack/examples/very_simple.rb
@@ -0,0 +1,50 @@
+$:.push "rails/activesupport/lib"
+$:.push "rails/actionpack/lib"
+
+require "action_controller"
+
+class Kaigi < ActionController::Http
+ include AbstractController::Callbacks
+ include ActionController::RackConvenience
+ include ActionController::Renderer
+ include ActionController::Layouts
+ include ActionView::Context
+
+ before_filter :set_name
+ append_view_path "views"
+
+ def _action_view
+ self
+ end
+
+ def controller
+ self
+ end
+
+ DEFAULT_LAYOUT = Object.new.tap {|l| def l.render(*) yield end }
+
+ def _render_template_from_controller(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
+ ret = template.render(self, {})
+ layout.render(self, {}) { ret }
+ end
+
+ def index
+ render :template => "template"
+ end
+
+ def alt
+ render :template => "template", :layout => "alt"
+ end
+
+ private
+ def set_name
+ @name = params[:name]
+ end
+end
+
+app = Rack::Builder.new do
+ map("/kaigi") { run Kaigi.action(:index) }
+ map("/kaigi/alt") { run Kaigi.action(:alt) }
+end.to_app
+
+Rack::Handler::Mongrel.run app, :Port => 3000
View
1 actionpack/examples/views/layouts/alt.html.erb
@@ -0,0 +1 @@
++ <%= yield %> +
View
1 actionpack/examples/views/layouts/kaigi.html.erb
@@ -0,0 +1 @@
+Hello <%= yield %> Goodbye
View
1 actionpack/examples/views/template.html.erb
@@ -0,0 +1 @@
+Hello <%= @name %>
View
36 activemodel/examples/amo_ap_example.rb
@@ -0,0 +1,36 @@
+$:.push "activesupport/lib"
+$:.push "activemodel/lib"
+
+require "active_model/validations"
+require "active_model/deprecated_error_methods"
+require "active_model/errors"
+require "active_model/naming"
+
+class Person
+ include ActiveModel::Validations
+ extend ActiveModel::Naming
+
+ validates_presence_of :name
+
+ attr_accessor :name
+ def initialize(attributes = {})
+ @name = attributes[:name]
+ end
+
+ def persist
+ @persisted = true
+ end
+
+ def new_record?
+ @persisted
+ end
+
+ def to_model() self end
+end
+
+person1 = Person.new
+p person1.valid?
+person1.errors
+
+person2 = Person.new(:name => "matz")
+p person2.valid?

0 comments on commit 45d41d8

Please sign in to comment.