example/config.ru in happy-0.1.0.pre24 vs example/config.ru in happy-0.1.0.pre25

- old
+ new

@@ -2,10 +2,12 @@ lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib") $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path) require 'happy' +require 'happy/extras/action_controller' +require 'happy/extras/resource_controller' # Controllers are the core building blocks of Happy applications. # They're also just Rack apps, so in any Happy app, you will # declare at least a "root" controller class and run that through Rack. @@ -108,10 +110,18 @@ # Trigger an error. This should display a nice error page. null.foobar end + example 'ActionController' do + run ActionTest + end + + example 'ResourceController' do + run ResourceTest + end + render 'index.erb' end def examples; @examples ||= {}; end @@ -119,9 +129,40 @@ path_name ||= name.parameterize examples[name] = path_name # Create a path containing the example's code block on path_name, &blk + end +end + +class ActionTest < Happy::Extras::ActionController + def foo + if params['id'] + "You called foo with ID #{params['id']}!" + else + "You called foo without an ID." + end + end + + def bar + "The bar is open!" + end + + def index + %{ + This is the index method. + Try #{link_to 'foo', current_url('foo')} + (#{link_to 'with an ID', current_url('foo', '123')}) + or #{link_to 'bar', current_url('bar')}! + } + end +end + +class ResourceTest < Happy::Extras::ResourceController + %w{index show new create edit update destroy}.each do |action| + define_method action do + "You called #{action}!" + end end end run TestApp