waves-stable 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/app/Rakefile +72 -0
- data/app/bin/waves-console +4 -0
- data/app/bin/waves-server +4 -0
- data/app/configurations/development.rb.erb +31 -0
- data/app/configurations/mapping.rb.erb +14 -0
- data/app/configurations/production.rb.erb +31 -0
- data/app/controllers/.gitignore +0 -0
- data/app/doc/.gitignore +0 -0
- data/app/helpers/.gitignore +0 -0
- data/app/lib/application.rb.erb +5 -0
- data/app/lib/tasks/.gitignore +0 -0
- data/app/log/.gitignore +0 -0
- data/app/models/.gitignore +0 -0
- data/app/public/css/.gitignore +0 -0
- data/app/public/flash/.gitignore +0 -0
- data/app/public/images/.gitignore +0 -0
- data/app/public/javascript/.gitignore +0 -0
- data/app/schema/migrations/.gitignore +0 -0
- data/app/startup.rb +5 -0
- data/app/templates/errors/not_found_404.mab +2 -0
- data/app/templates/errors/server_error_500.mab +2 -0
- data/app/templates/layouts/default.mab +14 -0
- data/app/tmp/sessions/.gitignore +0 -0
- data/app/views/.gitignore +0 -0
- data/bin/waves +84 -0
- data/bin/waves-console +4 -0
- data/bin/waves-server +4 -0
- data/doc/HISTORY +44 -0
- data/doc/LICENSE +22 -0
- data/lib/commands/waves-console.rb +21 -0
- data/lib/commands/waves-server.rb +55 -0
- data/lib/controllers/base.rb +11 -0
- data/lib/controllers/mixin.rb +165 -0
- data/lib/dispatchers/base.rb +67 -0
- data/lib/dispatchers/default.rb +81 -0
- data/lib/foundations/default.rb +27 -0
- data/lib/foundations/simple.rb +30 -0
- data/lib/helpers/asset_helper.rb +67 -0
- data/lib/helpers/common.rb +66 -0
- data/lib/helpers/default.rb +13 -0
- data/lib/helpers/form.rb +40 -0
- data/lib/helpers/formatting.rb +30 -0
- data/lib/helpers/model.rb +33 -0
- data/lib/helpers/number_helper.rb +25 -0
- data/lib/helpers/tag_helper.rb +58 -0
- data/lib/helpers/url_helper.rb +77 -0
- data/lib/helpers/view.rb +24 -0
- data/lib/layers/default_errors.rb +26 -0
- data/lib/layers/inflect/english.rb +24 -0
- data/lib/layers/inflect/english/rules.rb +88 -0
- data/lib/layers/inflect/english/string.rb +24 -0
- data/lib/layers/mvc.rb +54 -0
- data/lib/layers/orm/active_record.rb +92 -0
- data/lib/layers/orm/active_record/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/active_record/tasks/generate.rb +28 -0
- data/lib/layers/orm/active_record/tasks/schema.rb +22 -0
- data/lib/layers/orm/data_mapper.rb +38 -0
- data/lib/layers/orm/filebase.rb +22 -0
- data/lib/layers/orm/migration.rb +79 -0
- data/lib/layers/orm/sequel.rb +86 -0
- data/lib/layers/orm/sequel/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/sequel/tasks/generate.rb +28 -0
- data/lib/layers/orm/sequel/tasks/schema.rb +16 -0
- data/lib/layers/simple.rb +32 -0
- data/lib/layers/simple_errors.rb +23 -0
- data/lib/mapping/mapping.rb +289 -0
- data/lib/mapping/pretty_urls.rb +96 -0
- data/lib/renderers/erubis.rb +63 -0
- data/lib/renderers/haml.rb +45 -0
- data/lib/renderers/markaby.rb +33 -0
- data/lib/renderers/mixin.rb +50 -0
- data/lib/runtime/application.rb +69 -0
- data/lib/runtime/blackboard.rb +57 -0
- data/lib/runtime/configuration.rb +185 -0
- data/lib/runtime/console.rb +20 -0
- data/lib/runtime/debugger.rb +9 -0
- data/lib/runtime/logger.rb +59 -0
- data/lib/runtime/mime_types.rb +22 -0
- data/lib/runtime/request.rb +78 -0
- data/lib/runtime/response.rb +40 -0
- data/lib/runtime/response_mixin.rb +38 -0
- data/lib/runtime/response_proxy.rb +30 -0
- data/lib/runtime/server.rb +107 -0
- data/lib/runtime/session.rb +66 -0
- data/lib/tasks/cluster.rb +26 -0
- data/lib/tasks/gem.rb +31 -0
- data/lib/tasks/generate.rb +80 -0
- data/lib/utilities/hash.rb +31 -0
- data/lib/utilities/inflect.rb +110 -0
- data/lib/utilities/integer.rb +24 -0
- data/lib/utilities/module.rb +21 -0
- data/lib/utilities/object.rb +25 -0
- data/lib/utilities/proc.rb +16 -0
- data/lib/utilities/string.rb +49 -0
- data/lib/utilities/symbol.rb +10 -0
- data/lib/utilities/tempfile.rb +9 -0
- data/lib/views/base.rb +9 -0
- data/lib/views/mixin.rb +110 -0
- data/lib/waves.rb +84 -0
- data/samples/blog/Rakefile +14 -0
- data/samples/blog/bin/waves-console +3 -0
- data/samples/blog/bin/waves-server +3 -0
- data/samples/blog/configurations/development.rb +31 -0
- data/samples/blog/configurations/mapping.rb +23 -0
- data/samples/blog/configurations/production.rb +30 -0
- data/samples/blog/doc/EMTPY +0 -0
- data/samples/blog/lib/application.rb +5 -0
- data/samples/blog/models/comment.rb +14 -0
- data/samples/blog/models/entry.rb +14 -0
- data/samples/blog/public/css/site.css +2 -0
- data/samples/blog/public/javascript/site.js +13 -0
- data/samples/blog/schema/migrations/001_initial_schema.rb +17 -0
- data/samples/blog/schema/migrations/002_add_comments.rb +18 -0
- data/samples/blog/schema/migrations/templates/empty.rb.erb +9 -0
- data/samples/blog/startup.rb +6 -0
- data/samples/blog/templates/comment/add.mab +10 -0
- data/samples/blog/templates/comment/list.mab +6 -0
- data/samples/blog/templates/entry/editor.mab +13 -0
- data/samples/blog/templates/entry/list.mab +11 -0
- data/samples/blog/templates/entry/show.mab +9 -0
- data/samples/blog/templates/entry/summary.mab +5 -0
- data/samples/blog/templates/errors/not_found_404.mab +2 -0
- data/samples/blog/templates/errors/server_error_500.mab +2 -0
- data/samples/blog/templates/layouts/default.mab +17 -0
- data/verify/app_generation/helpers.rb +24 -0
- data/verify/app_generation/startup.rb +39 -0
- data/verify/blackboard/blackboard_verify.rb +92 -0
- data/verify/blackboard/helpers.rb +5 -0
- data/verify/configurations/attributes.rb +37 -0
- data/verify/configurations/helpers.rb +1 -0
- data/verify/configurations/rack_integration.rb +29 -0
- data/verify/controllers/base.rb +37 -0
- data/verify/controllers/helpers.rb +13 -0
- data/verify/controllers/interface.rb +51 -0
- data/verify/core/helpers.rb +3 -0
- data/verify/core/utilities.rb +177 -0
- data/verify/foundations/default.rb +86 -0
- data/verify/foundations/default_application/Rakefile +14 -0
- data/verify/foundations/default_application/bin/waves-console +3 -0
- data/verify/foundations/default_application/bin/waves-server +3 -0
- data/verify/foundations/default_application/configurations/development.rb +26 -0
- data/verify/foundations/default_application/configurations/mapping.rb +14 -0
- data/verify/foundations/default_application/configurations/production.rb +30 -0
- data/verify/foundations/default_application/controllers/default.rb +15 -0
- data/verify/foundations/default_application/controllers/loaded.rb +15 -0
- data/verify/foundations/default_application/defaultapplication.db +0 -0
- data/verify/foundations/default_application/helpers/loaded.rb +10 -0
- data/verify/foundations/default_application/lib/application.rb +5 -0
- data/verify/foundations/default_application/models/default.rb +13 -0
- data/verify/foundations/default_application/models/loaded.rb +13 -0
- data/verify/foundations/default_application/schema/migrations/templates/empty.rb.erb +9 -0
- data/verify/foundations/default_application/startup.rb +7 -0
- data/verify/foundations/default_application/templates/errors/not_found_404.mab +2 -0
- data/verify/foundations/default_application/templates/errors/server_error_500.mab +2 -0
- data/verify/foundations/default_application/templates/layouts/default.mab +14 -0
- data/verify/foundations/default_application/views/default.rb +7 -0
- data/verify/foundations/default_application/views/loaded.rb +15 -0
- data/verify/foundations/helpers.rb +1 -0
- data/verify/foundations/simple.rb +25 -0
- data/verify/helpers.rb +76 -0
- data/verify/layers/data_mapper/association_verify.rb +87 -0
- data/verify/layers/default_errors.rb +29 -0
- data/verify/layers/helpers.rb +1 -0
- data/verify/layers/migration.rb +33 -0
- data/verify/layers/sequel/model.rb +41 -0
- data/verify/mapping/always.rb +19 -0
- data/verify/mapping/filters.rb +65 -0
- data/verify/mapping/handle.rb +24 -0
- data/verify/mapping/helpers.rb +7 -0
- data/verify/mapping/matches.rb +27 -0
- data/verify/mapping/named.rb +29 -0
- data/verify/mapping/options.rb +17 -0
- data/verify/mapping/path.rb +40 -0
- data/verify/mapping/response_proxy.rb +50 -0
- data/verify/mapping/threaded.rb +25 -0
- data/verify/requests/helpers.rb +16 -0
- data/verify/requests/request.rb +73 -0
- data/verify/requests/response.rb +59 -0
- data/verify/requests/session.rb +54 -0
- data/verify/views/helpers.rb +1 -0
- data/verify/views/rendering.rb +34 -0
- data/verify/views/templates/foo.erb +0 -0
- data/verify/views/templates/moo.erb +0 -0
- data/verify/views/templates/moo.mab +0 -0
- metadata +439 -0
data/lib/views/base.rb
ADDED
data/lib/views/mixin.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
# Views in Waves are ultimately responsible for generating the response body. Views mirror controllers - both have full access to the request and response, and both may modify the response and even short-circuit the request processing and return a result by calling redirect or calling Response#finish.
|
4
|
+
#
|
5
|
+
# Views, like controllers, are classes with methods that are invoked by a mapping block (see Waves::Mapping). View instance methods take an assigns hash that are typically converted into instance variables accesible from within a template.
|
6
|
+
#
|
7
|
+
# Like controllers, a default implementation is provided by the +waves+ command when you first create your application. This default can be overridden to change the behaviors for all views, or you can explicitly define a View class to provide specific behavior for one view.
|
8
|
+
#
|
9
|
+
# The default implementation simply determines which template to render and renders it, returning the result as a string. This machinery is provided by the View mixin, so it is easy to create your own View implementations.
|
10
|
+
#
|
11
|
+
# = Templates
|
12
|
+
#
|
13
|
+
# Although you won't typically need to modify or define View classes, you will often create and modify templates. Templates can be evaluated using any registered Renderer. Two are presently packaged with Waves: Markaby and Erubis. Templates have access to the assigns hash passed to the view method as instance variables. These can be explicitly defined by the mapping file or whomever is invoking the view.
|
14
|
+
#
|
15
|
+
# *Example*
|
16
|
+
#
|
17
|
+
# # Find the story named 'home' and pass it as @story into the "story/show" template
|
18
|
+
# use( :story ) | controller { find( 'home' ) } | view { |x| show( :story => x ) }
|
19
|
+
#
|
20
|
+
# = Helpers
|
21
|
+
#
|
22
|
+
# Helper methods can be defined for any view template by simply defining them within the default Helper module in <tt>helpers/default.rb</tt> of the generated application. Helpers specific to a particular View class can be explicitly defined by creating a helper module that corresponds to the View class. For examples, for the +User+ View class, you would define a helper module in <tt>user.rb</tt> named +User+.
|
23
|
+
#
|
24
|
+
# The default helper class initially includes a wide-variety of helpers, including helpers for layouts, Textile formatting, rendering forms, and nested views, as well as helpers for accessing the request and response objects. More helpers will be added in future releases, but in many cases, there is no need to include all of them in your application.
|
25
|
+
#
|
26
|
+
# = Layouts
|
27
|
+
#
|
28
|
+
# Layouts are defined using the +Layout+ view class, and layout templates are placed in the +layout+ directory of the +templates+ directory. Layouts are explicitly set within a template using the +layout+ method.
|
29
|
+
#
|
30
|
+
# *Example*
|
31
|
+
#
|
32
|
+
# layout :default, :title => @story.title do
|
33
|
+
# h1 @story.title
|
34
|
+
# textile @story.content
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# The layout method takes a name and an assigns hash that will be available within the layout template as instance variables. In this example, <tt>@title</tt> will be defined as <tt>@story.title</tt> within the layout template named 'default.'
|
39
|
+
#
|
40
|
+
# Any number of layouts may be included within a single view, and layouts may even be nested within layouts. This makes it possible to create large numbers of highly structured views that can be easily changed with minimal effort. For example, you might specify a layout associated with form elements. By incorporating this into your views as a +layout+ template, you can make changes across all your forms by changing this single template.
|
41
|
+
#
|
42
|
+
# = Nested Views
|
43
|
+
#
|
44
|
+
# It is easy to include one view inside another. A common use for this is to define one set of templates for reusable content 'fragments' (somewhat akin to partials in Rails) and another set that incorporate these fragments into specific layouts. Including a view from within another view is done, logically enough, using the +view+ method.
|
45
|
+
#
|
46
|
+
# *Example*
|
47
|
+
#
|
48
|
+
# # include the summary view for Story
|
49
|
+
# view :story, :summary, :story => @story
|
50
|
+
#
|
51
|
+
# = Request And Response Objects
|
52
|
+
#
|
53
|
+
# As always, the request and response objects, and a wide-variety of short-cut methods, are available within view templates via the Waves::ResponseMixin.
|
54
|
+
#
|
55
|
+
|
56
|
+
module Views
|
57
|
+
|
58
|
+
class NoTemplateError < Exception ; end
|
59
|
+
|
60
|
+
# A class method that returns the known Renderers, which is any module that is defined within Waves::Renderers and includes the Renderers::Mixin. You can define new Renderers simply be reopening Waves::Renderers and defining a module that mixes in Renderers::Mixin.
|
61
|
+
def Views.renderers
|
62
|
+
return [] if Renderers.constants.nil?
|
63
|
+
Renderers.constants.sort.inject([]) do |rx,cname|
|
64
|
+
( Module === (c=Renderers.const_get(cname)) &&
|
65
|
+
c < Renderers::Mixin ) ? ( rx << c ) : rx
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# The View mixin simply sets up the machinery for invoking a template, along with methods for accessing the request context and the standard interface for invoking a view method.
|
70
|
+
module Mixin
|
71
|
+
|
72
|
+
attr_reader :request
|
73
|
+
|
74
|
+
include Waves::ResponseMixin
|
75
|
+
|
76
|
+
def self.included( c )
|
77
|
+
def c.process( request, *args, &block )
|
78
|
+
self.new( request ).instance_exec( *args, &block )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize( request )
|
83
|
+
@request = request
|
84
|
+
@layout = :default
|
85
|
+
end
|
86
|
+
|
87
|
+
# Return the first renderer for which a template file can be found.
|
88
|
+
# Uses Renderers::Mixin.filename to construct the filename for each renderer.
|
89
|
+
def renderer(path)
|
90
|
+
Views.renderers.find do |renderer|
|
91
|
+
File.exists?( renderer.filename( path ) )
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def render( path, context = {} )
|
96
|
+
context.merge!( :request => request )
|
97
|
+
template = renderer( path ) || renderer( :generic / File.basename(path) )
|
98
|
+
raise NoTemplateError.new( path ) if template.nil?
|
99
|
+
template.render( path, context )
|
100
|
+
end
|
101
|
+
|
102
|
+
def method_missing(name,*args)
|
103
|
+
render( "/#{self.class.basename.snake_case}/#{name}", *args )
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
data/lib/waves.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# External Dependencies
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
# Some scripts need to be able to locate items relative to waves source.
|
5
|
+
WAVES = "#{File.dirname(__FILE__)}/.." unless defined?(WAVES)
|
6
|
+
|
7
|
+
require 'rack'
|
8
|
+
require 'daemons'
|
9
|
+
require 'live_console'
|
10
|
+
require 'autocode'
|
11
|
+
|
12
|
+
# for mimetypes only or when using as default handler
|
13
|
+
require 'mongrel'
|
14
|
+
|
15
|
+
# a bunch of handy stuff
|
16
|
+
require 'extensions/all'
|
17
|
+
require 'fileutils'
|
18
|
+
require 'metaid'
|
19
|
+
require 'forwardable'
|
20
|
+
require 'date'
|
21
|
+
require 'benchmark'
|
22
|
+
# require 'memcache'
|
23
|
+
require 'base64'
|
24
|
+
|
25
|
+
# selected project-specific extensions
|
26
|
+
require 'utilities/module'
|
27
|
+
require 'utilities/string'
|
28
|
+
require 'utilities/symbol'
|
29
|
+
require 'utilities/object'
|
30
|
+
require 'utilities/integer'
|
31
|
+
require 'utilities/inflect'
|
32
|
+
require 'utilities/proc'
|
33
|
+
require 'utilities/hash'
|
34
|
+
require 'utilities/tempfile'
|
35
|
+
# waves Runtime
|
36
|
+
require 'dispatchers/base'
|
37
|
+
require 'dispatchers/default'
|
38
|
+
require 'runtime/logger'
|
39
|
+
require 'runtime/mime_types'
|
40
|
+
require 'runtime/application'
|
41
|
+
require 'runtime/console'
|
42
|
+
require 'runtime/debugger'
|
43
|
+
require 'runtime/server'
|
44
|
+
require 'runtime/request'
|
45
|
+
require 'runtime/response'
|
46
|
+
require 'runtime/response_mixin'
|
47
|
+
require 'runtime/response_proxy'
|
48
|
+
require 'runtime/session'
|
49
|
+
require 'runtime/blackboard'
|
50
|
+
require 'runtime/configuration'
|
51
|
+
|
52
|
+
# waves URI mapping
|
53
|
+
require 'mapping/mapping'
|
54
|
+
require 'mapping/pretty_urls'
|
55
|
+
|
56
|
+
# waves mvc support
|
57
|
+
require 'controllers/mixin'
|
58
|
+
require 'controllers/base'
|
59
|
+
require 'views/mixin'
|
60
|
+
require 'views/base'
|
61
|
+
require 'helpers/tag_helper'
|
62
|
+
require 'helpers/url_helper'
|
63
|
+
require 'helpers/common'
|
64
|
+
require 'helpers/form'
|
65
|
+
require 'helpers/formatting'
|
66
|
+
require 'helpers/model'
|
67
|
+
require 'helpers/view'
|
68
|
+
require 'helpers/default'
|
69
|
+
require 'helpers/asset_helper'
|
70
|
+
require 'helpers/number_helper'
|
71
|
+
require 'renderers/mixin'
|
72
|
+
require 'renderers/erubis'
|
73
|
+
require 'renderers/markaby'
|
74
|
+
require 'renderers/haml'
|
75
|
+
|
76
|
+
|
77
|
+
# waves foundations / layers
|
78
|
+
require 'layers/simple'
|
79
|
+
require 'layers/simple_errors'
|
80
|
+
require 'foundations/simple'
|
81
|
+
require 'layers/mvc'
|
82
|
+
require 'layers/default_errors'
|
83
|
+
require 'layers/inflect/english'
|
84
|
+
require 'foundations/default'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Warning: This file is clobbered when you update your
|
4
|
+
# application with the waves script. Accordingly, you may
|
5
|
+
# wish to keep your tasks in .rb or .rake files in lib/tasks
|
6
|
+
require 'startup'
|
7
|
+
Waves::Console.load(:mode => ENV['mode'])
|
8
|
+
|
9
|
+
# load tasks from waves framework
|
10
|
+
%w( cluster generate gem ).each { |task| require "tasks/#{task}.rb" }
|
11
|
+
|
12
|
+
# load tasks from this app's lib/tasks
|
13
|
+
Dir["lib/tasks/*.{rb,rake}"].each { |task| require task }
|
14
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Blog
|
2
|
+
|
3
|
+
module Configurations
|
4
|
+
|
5
|
+
class Development < Default
|
6
|
+
|
7
|
+
database :adapter => 'sqlite', :database => 'blog.db'
|
8
|
+
|
9
|
+
reloadable [ Blog ]
|
10
|
+
|
11
|
+
log :level => :debug
|
12
|
+
|
13
|
+
host '127.0.0.1'
|
14
|
+
|
15
|
+
port 3000
|
16
|
+
|
17
|
+
handler ::Rack::Handler::Mongrel, :Host => host, :Port => port
|
18
|
+
# handler ::Rack::Handler::WEBrick, :BindAddress => host, :Port => port
|
19
|
+
# handler ::Rack::Handler::Thin, :Host => host, :Port => port
|
20
|
+
|
21
|
+
application do
|
22
|
+
use ::Rack::ShowExceptions
|
23
|
+
use ::Rack::Static, :urls => [ '/css', '/javascript' ], :root => 'public'
|
24
|
+
run ::Waves::Dispatchers::Default.new
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Blog
|
2
|
+
|
3
|
+
module Configurations
|
4
|
+
|
5
|
+
module Mapping
|
6
|
+
extend Waves::Mapping
|
7
|
+
|
8
|
+
path '/', :method => :get do
|
9
|
+
redirect("/entries")
|
10
|
+
end
|
11
|
+
|
12
|
+
path %r{^/comments/?$}, :method => :post do
|
13
|
+
resource( :comment ) do
|
14
|
+
controller { comment = create; redirect( "/entry/#{comment.entry.name}" ) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
include Waves::Mapping::PrettyUrls::RestRules
|
18
|
+
include Waves::Mapping::PrettyUrls::GetRules
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Blog
|
2
|
+
|
3
|
+
module Configurations
|
4
|
+
|
5
|
+
class Production < Default
|
6
|
+
|
7
|
+
database :host => 'localhost', :adapter => 'mysql', :database => 'blog',
|
8
|
+
:user => 'root', :password => ''
|
9
|
+
|
10
|
+
reloadable []
|
11
|
+
|
12
|
+
log :level => :error,
|
13
|
+
:output => ( :log / "waves.#{$$}" ),
|
14
|
+
:rotation => :weekly
|
15
|
+
|
16
|
+
host '0.0.0.0'
|
17
|
+
|
18
|
+
port 80
|
19
|
+
|
20
|
+
handler ::Rack::Handler::Mongrel, :Host => host, :Port => port
|
21
|
+
# handler ::Rack::Handler::WEBrick, :BindAddress => host, :Port => port
|
22
|
+
# handler ::Rack::Handler::Thin, :Host => host, :Port => port
|
23
|
+
|
24
|
+
application do
|
25
|
+
run ::Waves::Dispatchers::Default.new
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Blog
|
2
|
+
|
3
|
+
module Models
|
4
|
+
|
5
|
+
class Entry < Default
|
6
|
+
one_to_many :comments, :class => Blog::Models::Comment, :key => :entry_id, :order => :updated_on
|
7
|
+
before_save do
|
8
|
+
set_with_params(:updated_on => Time.now) if columns.include? :updated_on
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$(document).ready( function() {
|
2
|
+
$('a.delete').click( function() {
|
3
|
+
if ( confirm("Are you sure?") ) {
|
4
|
+
var href = $(this).attr('href');
|
5
|
+
$.ajax({ type: 'delete', url: href,
|
6
|
+
success: function() { window.location = '/entries'; }
|
7
|
+
});
|
8
|
+
}
|
9
|
+
// this isn't really a link ...
|
10
|
+
// so tell the browser we've handled it
|
11
|
+
return false;
|
12
|
+
});
|
13
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class AddComments < Sequel::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
create_table :comments do
|
5
|
+
primary_key :id
|
6
|
+
foreign_key :entry_id, :table => :entries
|
7
|
+
text :name
|
8
|
+
text :email
|
9
|
+
text :content
|
10
|
+
timestamp :updated_on
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
drop_table :comments
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
form :action => "/comments", :method => 'POST' do
|
2
|
+
input :type => :hidden, :name => 'comment.entry_id', :value => @entry.id
|
3
|
+
label 'Name'; br
|
4
|
+
input :type => :text, :name => 'comment.name'; br
|
5
|
+
label 'Email'; br
|
6
|
+
input :type => :text, :name => 'comment.email'; br
|
7
|
+
label 'Comment'; br
|
8
|
+
textarea :name => 'comment.content', :rows => 10, :cols => 80; br
|
9
|
+
input :type => :submit, :value => 'Save'
|
10
|
+
end
|