| |   |
| 1 | require 'rubygems' |
| 2 | require 'camping' |
| 3 | |
| 4 | Camping.goes :Events |
| 5 | |
| 6 | module Events::Models |
| 7 | class Event < Base; end |
| 8 | |
| 9 | class CreateTheBasics < V 1.0 |
| 10 | def self.up |
| 11 | create_table :events_events do |t| |
| 12 | t.string :name |
| 13 | t.string :url |
| 14 | t.text :description |
| 15 | end |
| 16 | |
| 17 | Event.create! :name => 'RubyFools', :url => 'http://rubyfools.com/', :description => 'Ruby in CPH and Oslo' |
| 18 | end |
| 19 | |
| 20 | def self.down |
| 21 | drop_table :events |
| 22 | end |
| 23 | end |
| 24 | end |
| 25 | |
| 26 | module Events::Controllers |
| 27 | class Events < R '/events' |
| 28 | def get |
| 29 | @events = Event.find(:all) |
| 30 | render :events |
| 31 | end |
| 32 | end |
| 33 | |
| 34 | class Stylesheet < R '/stylesheet.css' |
| 35 | def get |
| 36 | IO.read('../sinatra/stylesheet.css') |
| 37 | end |
| 38 | end |
| 39 | end |
| 40 | |
| 41 | module Events::Views |
| 42 | def layout |
| 43 | html do |
| 44 | head do |
| 45 | title 'blog' |
| 46 | link :rel => 'stylesheet', :type => 'text/css', |
| 47 | :href => '/stylesheet.css', :media => 'screen' |
| 48 | end |
| 49 | body do |
| 50 | div.content do |
| 51 | self << yield |
| 52 | end |
| 53 | end |
| 54 | end |
| 55 | end |
| 56 | |
| 57 | def events |
| 58 | if @events.empty? |
| 59 | p 'No events found' |
| 60 | else |
| 61 | table do |
| 62 | caption 'Events' |
| 63 | tr :class => 'odd' do |
| 64 | th 'Name', :class => 'name', :scope => 'col' |
| 65 | end |
| 66 | c = 'odd' |
| 67 | @events.each do |e| |
| 68 | tr(:class => (c == 'even' ? c = 'odd' : c = 'even')) do |
| 69 | td :class => 'name' do |
| 70 | a e.name, :href => e.url |
| 71 | e.description |
| 72 | end |
| 73 | end |
| 74 | end |
| 75 | end |
| 76 | end |
| 77 | end |
| 78 | end |
| 79 | |
| 80 | def Events.create |
| 81 | Events::Models.create_schema :assume => (Events::Models::Event.table_exists? ? 1.0 : 0.0) |
| 82 | end |
| toggle raw diff |
--- /dev/null
+++ b/camping/events.rb
@@ -0,0 +1,82 @@
+require 'rubygems'
+require 'camping'
+
+Camping.goes :Events
+
+module Events::Models
+ class Event < Base; end
+
+ class CreateTheBasics < V 1.0
+ def self.up
+ create_table :events_events do |t|
+ t.string :name
+ t.string :url
+ t.text :description
+ end
+
+ Event.create! :name => 'RubyFools', :url => 'http://rubyfools.com/', :description => 'Ruby in CPH and Oslo'
+ end
+
+ def self.down
+ drop_table :events
+ end
+ end
+end
+
+module Events::Controllers
+ class Events < R '/events'
+ def get
+ @events = Event.find(:all)
+ render :events
+ end
+ end
+
+ class Stylesheet < R '/stylesheet.css'
+ def get
+ IO.read('../sinatra/stylesheet.css')
+ end
+ end
+end
+
+module Events::Views
+ def layout
+ html do
+ head do
+ title 'blog'
+ link :rel => 'stylesheet', :type => 'text/css',
+ :href => '/stylesheet.css', :media => 'screen'
+ end
+ body do
+ div.content do
+ self << yield
+ end
+ end
+ end
+ end
+
+ def events
+ if @events.empty?
+ p 'No events found'
+ else
+ table do
+ caption 'Events'
+ tr :class => 'odd' do
+ th 'Name', :class => 'name', :scope => 'col'
+ end
+ c = 'odd'
+ @events.each do |e|
+ tr(:class => (c == 'even' ? c = 'odd' : c = 'even')) do
+ td :class => 'name' do
+ a e.name, :href => e.url
+ e.description
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+def Events.create
+ Events::Models.create_schema :assume => (Events::Models::Event.table_exists? ? 1.0 : 0.0)
+end |
| |   |
| 1 | <html> |
| 2 | <head> |
| 3 | <title>Events</title> |
| 4 | <link href='/stylesheet.css' media='screen' rel='stylesheet' type='text/css' /> |
| 5 | <meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> |
| 6 | </head> |
| 7 | <body> |
| 8 | <table> |
| 9 | <caption>Events</caption> |
| 10 | <tr class='odd'> |
| 11 | <th class='name' scope='col'>Name</th> |
| 12 | </tr> |
| 13 | <tr class='even'> |
| 14 | <td class='name'> |
| 15 | <a href='http://rubyfools.com'>RubyFools</a> |
| 16 | Ruby conference in Copenhagen and Oslo |
| 17 | </td> |
| 18 | </tr> |
| 19 | <tr class='odd'> |
| 20 | <td class='name'> |
| 21 | <a href='http://rubyconf.org'>RubyConf</a> |
| 22 | THE Ruby conference |
| 23 | </td> |
| 24 | </tr> |
| 25 | </table> |
| 26 | <form action='/events' method='POST'> |
| 27 | <fieldset> |
| 28 | <legend>New Event</legend> |
| 29 | |
| 30 | <label for='name'>Name</label> |
| 31 | <input id='name' name='name' size='30' type='text' /> |
| 32 | <br /> |
| 33 | |
| 34 | <label for='url'>Homepage</label> |
| 35 | <input id='url' name='url' size='30' type='text' /> |
| 36 | <br /> |
| 37 | |
| 38 | <label for='description'>Description</label> |
| 39 | <textarea cols='30' id='description' name='description' rows='4' type='description'> |
| 40 | </textarea> |
| 41 | <br /> |
| 42 | |
| 43 | <input class='submit' name='foo[bar]' type='submit' value='Create' /> |
| 44 | </fieldset> |
| 45 | </form> |
| 46 | </body> |
| 47 | |
| 48 | </html> |
| toggle raw diff |
--- /dev/null
+++ b/sinatra/events.html
@@ -0,0 +1,48 @@
+<html>
+ <head>
+ <title>Events</title>
+ <link href='/stylesheet.css' media='screen' rel='stylesheet' type='text/css' />
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
+ </head>
+ <body>
+ <table>
+ <caption>Events</caption>
+ <tr class='odd'>
+ <th class='name' scope='col'>Name</th>
+ </tr>
+ <tr class='even'>
+ <td class='name'>
+ <a href='http://rubyfools.com'>RubyFools</a>
+ Ruby conference in Copenhagen and Oslo
+ </td>
+ </tr>
+ <tr class='odd'>
+ <td class='name'>
+ <a href='http://rubyconf.org'>RubyConf</a>
+ THE Ruby conference
+ </td>
+ </tr>
+ </table>
+ <form action='/events' method='POST'>
+ <fieldset>
+ <legend>New Event</legend>
+
+ <label for='name'>Name</label>
+ <input id='name' name='name' size='30' type='text' />
+ <br />
+
+ <label for='url'>Homepage</label>
+ <input id='url' name='url' size='30' type='text' />
+ <br />
+
+ <label for='description'>Description</label>
+ <textarea cols='30' id='description' name='description' rows='4' type='description'>
+ </textarea>
+ <br />
+
+ <input class='submit' name='foo[bar]' type='submit' value='Create' />
+ </fieldset>
+ </form>
+ </body>
+
+</html> |
| |   |
| 25 | 25 | get('/stylesheet.css') { Sass::Engine.new(File.read(__FILE__).gsub(/.*__END__/m, '')).render } |
| 26 | 26 | |
| 27 | 27 | get '/events' do |
| 28 | | puts Event.all.inspect |
| 29 | 28 | @events = Event.all |
| 30 | 29 | haml(layout('Events', %q{ |
| 31 | 30 | - if @events.empty? |
| … | … | |
| 38 | 38 | - @events.each do |e| |
| 39 | 39 | %tr{:class => (c == 'even' ? c = 'odd' : c = 'even') } |
| 40 | 40 | %td{:class => 'name'} |
| 41 | | %a{:href => '#'}= e.name |
| 41 | %a{:href => e.url}= e.name |
| 42 | 42 | = e.description |
| 43 | 43 | %form{:action => '/events', :method => 'POST'} |
| 44 | 44 | %fieldset |
| 45 | 45 | %legend New Event |
| 46 | | |
| 47 | 46 | %label{:for => 'name'} Name |
| 48 | 47 | %input{:type => 'text', :name => 'name', :id => 'name', :size => 30} |
| 49 | 48 | %br |
| 50 | 49 | |
| 50 | %label{:for => 'url'} Homepage |
| 51 | %input{:type => 'text', :name => 'url', :id => 'url', :size => 30} |
| 52 | %br |
| 53 | |
| 51 | 54 | %label{:for => 'description'} Description |
| 52 | 55 | %textarea{:type => 'description', :name => 'description', :id => 'description', :cols => 30, :rows => 4} |
| 53 | 56 | %br |
| … | … | |
| 65 | 65 | redirect '/events' |
| 66 | 66 | end |
| 67 | 67 | |
| 68 | | |
| 69 | 68 | def layout(title, content) |
| 70 | 69 | %Q( |
| 71 | 70 | %html |
| toggle raw diff |
--- a/sinatra/events.rb
+++ b/sinatra/events.rb
@@ -25,7 +25,6 @@ Event.table.create!
get('/stylesheet.css') { Sass::Engine.new(File.read(__FILE__).gsub(/.*__END__/m, '')).render }
get '/events' do
- puts Event.all.inspect
@events = Event.all
haml(layout('Events', %q{
- if @events.empty?
@@ -39,16 +38,19 @@ get '/events' do
- @events.each do |e|
%tr{:class => (c == 'even' ? c = 'odd' : c = 'even') }
%td{:class => 'name'}
- %a{:href => '#'}= e.name
+ %a{:href => e.url}= e.name
= e.description
%form{:action => '/events', :method => 'POST'}
%fieldset
%legend New Event
-
%label{:for => 'name'} Name
%input{:type => 'text', :name => 'name', :id => 'name', :size => 30}
%br
+ %label{:for => 'url'} Homepage
+ %input{:type => 'text', :name => 'url', :id => 'url', :size => 30}
+ %br
+
%label{:for => 'description'} Description
%textarea{:type => 'description', :name => 'description', :id => 'description', :cols => 30, :rows => 4}
%br
@@ -63,7 +65,6 @@ post '/events' do
redirect '/events'
end
-
def layout(title, content)
%Q(
%html |
| |   |
| 1 | body { |
| 2 | background:#B5B5B5 none repeat scroll 0%; |
| 3 | font-family:Verdana,Arial,"Bitstream Vera Sans",Helvetica,sans-serif; |
| 4 | line-height:160%; |
| 5 | margin:0pt; |
| 6 | padding:30px; |
| 7 | } |
| 8 | h1 { |
| 9 | display:block; |
| 10 | padding-bottom:5px; |
| 11 | } |
| 12 | a { |
| 13 | color:black; |
| 14 | } |
| 15 | form label { |
| 16 | float:left; |
| 17 | font-weight:bold; |
| 18 | width:120px; |
| 19 | } |
| 20 | form input, form textarea { |
| 21 | margin-bottom:5px; |
| 22 | width:180px; |
| 23 | } |
| 24 | form input.submit { |
| 25 | margin-left:120px; |
| 26 | margin-top:5px; |
| 27 | width:90px; |
| 28 | } |
| 29 | form br { |
| 30 | clear:left; |
| 31 | } |
| 32 | table { |
| 33 | background:#FFFFFF none repeat scroll 0%; |
| 34 | border:1px solid #000000; |
| 35 | border-collapse:collapse; |
| 36 | width:100%; |
| 37 | } |
| 38 | table caption { |
| 39 | background:#FFFFFF none repeat scroll 0%; |
| 40 | border-color:#000000 rgb(0, 0, 0) -moz-use-text-color; |
| 41 | border-style:solid solid none; |
| 42 | border-width:1px 1px medium; |
| 43 | margin:0pt; |
| 44 | padding:8px 20px; |
| 45 | text-align:left; |
| 46 | } |
| 47 | table th, table td { |
| 48 | border-bottom:1px solid #B5B5B5; |
| 49 | margin:0pt; |
| 50 | padding:8px 20px; |
| 51 | text-align:center; |
| 52 | } |
| 53 | table th.name, table td.name { |
| 54 | text-align:left; |
| 55 | } |
| 56 | table th { |
| 57 | color:#999999; |
| 58 | } |
| 59 | table tr.odd { |
| 60 | background:#E6E6E6 none repeat scroll 0%; |
| 61 | } |
| 62 | table tr.even { |
| 63 | background:#F1F1F1 none repeat scroll 0%; |
| 64 | } |
| 65 | table td a { |
| 66 | display:block; |
| 67 | font-weight:bold; |
| 68 | } |
| toggle raw diff |
--- /dev/null
+++ b/sinatra/stylesheet.css
@@ -0,0 +1,68 @@
+body {
+ background:#B5B5B5 none repeat scroll 0%;
+ font-family:Verdana,Arial,"Bitstream Vera Sans",Helvetica,sans-serif;
+ line-height:160%;
+ margin:0pt;
+ padding:30px;
+ }
+h1 {
+ display:block;
+ padding-bottom:5px;
+ }
+a {
+ color:black;
+ }
+form label {
+ float:left;
+ font-weight:bold;
+ width:120px;
+ }
+form input, form textarea {
+ margin-bottom:5px;
+ width:180px;
+ }
+form input.submit {
+ margin-left:120px;
+ margin-top:5px;
+ width:90px;
+ }
+form br {
+ clear:left;
+ }
+table {
+ background:#FFFFFF none repeat scroll 0%;
+ border:1px solid #000000;
+ border-collapse:collapse;
+ width:100%;
+ }
+table caption {
+ background:#FFFFFF none repeat scroll 0%;
+ border-color:#000000 rgb(0, 0, 0) -moz-use-text-color;
+ border-style:solid solid none;
+ border-width:1px 1px medium;
+ margin:0pt;
+ padding:8px 20px;
+ text-align:left;
+ }
+table th, table td {
+ border-bottom:1px solid #B5B5B5;
+ margin:0pt;
+ padding:8px 20px;
+ text-align:center;
+ }
+table th.name, table td.name {
+ text-align:left;
+ }
+table th {
+ color:#999999;
+ }
+table tr.odd {
+ background:#E6E6E6 none repeat scroll 0%;
+ }
+table tr.even {
+ background:#F1F1F1 none repeat scroll 0%;
+ }
+table td a {
+ display:block;
+ font-weight:bold;
+ }
\ No newline at end of file |
| |   |
| 1 | module Events |
| 2 | module Configurations |
| 3 | class Default < Waves::Configurations::Default |
| 4 | database :host => host, :adapter => 'mysql', :database => 'events', |
| 5 | :user => 'root', :password => '' |
| 6 | end |
| 7 | end |
| 8 | end |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/configurations/default.rb
@@ -0,0 +1,8 @@
+module Events
+ module Configurations
+ class Default < Waves::Configurations::Default
+ database :host => host, :adapter => 'mysql', :database => 'events',
+ :user => 'root', :password => ''
+ end
+ end
+end |
| |   |
| 1 | module Events |
| 2 | |
| 3 | module Controllers |
| 4 | |
| 5 | class Default |
| 6 | |
| 7 | include Waves::Controllers::Mixin |
| 8 | |
| 9 | def attributes; params[model_name.singular.intern]; end |
| 10 | |
| 11 | def all; model.all; end |
| 12 | |
| 13 | def find( name ); model[ :name => name ] or not_found; end |
| 14 | |
| 15 | def create; model.create( attributes ); end |
| 16 | |
| 17 | def update( name ) |
| 18 | instance = find( name ) |
| 19 | instance.set( attributes ) |
| 20 | instance.save_changes |
| 21 | end |
| 22 | |
| 23 | def delete( name ); find( name ).destroy; end |
| 24 | |
| 25 | end |
| 26 | |
| 27 | end |
| 28 | |
| 29 | end |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/controllers/default.rb
@@ -0,0 +1,29 @@
+module Events
+
+ module Controllers
+
+ class Default
+
+ include Waves::Controllers::Mixin
+
+ def attributes; params[model_name.singular.intern]; end
+
+ def all; model.all; end
+
+ def find( name ); model[ :name => name ] or not_found; end
+
+ def create; model.create( attributes ); end
+
+ def update( name )
+ instance = find( name )
+ instance.set( attributes )
+ instance.save_changes
+ end
+
+ def delete( name ); find( name ).destroy; end
+
+ end
+
+ end
+
+end |
| |   |
| 1 | module Events |
| 2 | module Helpers |
| 3 | module Default |
| 4 | attr_reader :request, :content |
| 5 | include Waves::ResponseMixin |
| 6 | include Waves::Helpers::Common |
| 7 | include Waves::Helpers::Formatting |
| 8 | include Waves::Helpers::Model |
| 9 | include Waves::Helpers::View |
| 10 | include Waves::Helpers::Form |
| 11 | end |
| 12 | end |
| 13 | end |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/helpers/default.rb
@@ -0,0 +1,13 @@
+module Events
+ module Helpers
+ module Default
+ attr_reader :request, :content
+ include Waves::ResponseMixin
+ include Waves::Helpers::Common
+ include Waves::Helpers::Formatting
+ include Waves::Helpers::Model
+ include Waves::Helpers::View
+ include Waves::Helpers::Form
+ end
+ end
+end
\ No newline at end of file |
| |   |
| 1 | require 'sequel' |
| 2 | module Events |
| 3 | |
| 4 | extend Autocreate; extend Autoload; extend Reloadable |
| 5 | autoload true; directories :lib |
| 6 | |
| 7 | [ :Configurations, :Models, :Views, :Controllers, :Helpers ].each do | name | |
| 8 | autocreate( name, Module.new ) do |
| 9 | |
| 10 | # dynamically access module constants |
| 11 | def self.[]( cname ) |
| 12 | eval("#{name}::#{cname.to_s.camel_case}") |
| 13 | end |
| 14 | |
| 15 | # first try to load and only create if that fails |
| 16 | # which means install autoload *after* autocreate |
| 17 | extend Autocreate; extend Autoload |
| 18 | |
| 19 | # autoload any files in appropriately named directories |
| 20 | # exampe: models/blog.rb for Blog |
| 21 | autoload true; directories name.to_s.snake_case |
| 22 | |
| 23 | # autocreate declarations ... |
| 24 | case name |
| 25 | # don't autocreate configs |
| 26 | when :Configurations then nil |
| 27 | # set the dataset for Models |
| 28 | when :Models |
| 29 | autocreate true, eval("Events::Models::Default") do |
| 30 | set_dataset Events.database[ basename.snake_case.plural.intern ] |
| 31 | end |
| 32 | # everything else just use the exemplar |
| 33 | else |
| 34 | autocreate true, eval("Events::#{name}::Default") |
| 35 | end |
| 36 | |
| 37 | end |
| 38 | |
| 39 | end |
| 40 | |
| 41 | # accessor methods for modules and other key application objects ... |
| 42 | class << self |
| 43 | def config ; Waves::Server.config rescue nil || Waves::Console.config ; end |
| 44 | def database ; @database ||= Sequel.mysql( config.database ) ; end |
| 45 | def configurations ; Events::Configurations ; end |
| 46 | def controllers ; Events::Controllers ; end |
| 47 | def models ; Events::Models ; end |
| 48 | def helpers ; Events::Helpers ; end |
| 49 | def views ; Events::Views ; end |
| 50 | end |
| 51 | |
| 52 | end |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/lib/events.rb
@@ -0,0 +1,52 @@
+require 'sequel'
+module Events
+
+ extend Autocreate; extend Autoload; extend Reloadable
+ autoload true; directories :lib
+
+ [ :Configurations, :Models, :Views, :Controllers, :Helpers ].each do | name |
+ autocreate( name, Module.new ) do
+
+ # dynamically access module constants
+ def self.[]( cname )
+ eval("#{name}::#{cname.to_s.camel_case}")
+ end
+
+ # first try to load and only create if that fails
+ # which means install autoload *after* autocreate
+ extend Autocreate; extend Autoload
+
+ # autoload any files in appropriately named directories
+ # exampe: models/blog.rb for Blog
+ autoload true; directories name.to_s.snake_case
+
+ # autocreate declarations ...
+ case name
+ # don't autocreate configs
+ when :Configurations then nil
+ # set the dataset for Models
+ when :Models
+ autocreate true, eval("Events::Models::Default") do
+ set_dataset Events.database[ basename.snake_case.plural.intern ]
+ end
+ # everything else just use the exemplar
+ else
+ autocreate true, eval("Events::#{name}::Default")
+ end
+
+ end
+
+ end
+
+ # accessor methods for modules and other key application objects ...
+ class << self
+ def config ; Waves::Server.config rescue nil || Waves::Console.config ; end
+ def database ; @database ||= Sequel.mysql( config.database ) ; end
+ def configurations ; Events::Configurations ; end
+ def controllers ; Events::Controllers ; end
+ def models ; Events::Models ; end
+ def helpers ; Events::Helpers ; end
+ def views ; Events::Views ; end
+ end
+
+end
\ No newline at end of file |
| |   |
| 1 | namespace :cluster do |
| 2 | |
| 3 | desc 'Start a cluster of waves applications.' |
| 4 | task :start do |task| |
| 5 | ( Waves::Console.config.ports || [ Waves::Console.config.port ] ).each do |port| |
| 6 | cmd = "waves-server -p #{port} -c #{ENV['mode']||'development'} -d" |
| 7 | puts cmd ; `#{cmd}` |
| 8 | end |
| 9 | end |
| 10 | |
| 11 | desc 'Stop a cluster of waves applications.' |
| 12 | task :stop do |task| |
| 13 | Dir[ :log / '*.pid' ].each do |path| |
| 14 | pid = File.basename(path,'.pid').to_i |
| 15 | puts "Stopping process #{pid} ..." |
| 16 | Process.kill( 'INT', pid ) rescue nil |
| 17 | end |
| 18 | end |
| 19 | |
| 20 | desc 'Restart a cluster of waves applications.' |
| 21 | task :restart => [ :stop, :start ] do |task| |
| 22 | end |
| 23 | |
| 24 | end |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/lib/tasks/cluster.rb
@@ -0,0 +1,24 @@
+namespace :cluster do
+
+ desc 'Start a cluster of waves applications.'
+ task :start do |task|
+ ( Waves::Console.config.ports || [ Waves::Console.config.port ] ).each do |port|
+ cmd = "waves-server -p #{port} -c #{ENV['mode']||'development'} -d"
+ puts cmd ; `#{cmd}`
+ end
+ end
+
+ desc 'Stop a cluster of waves applications.'
+ task :stop do |task|
+ Dir[ :log / '*.pid' ].each do |path|
+ pid = File.basename(path,'.pid').to_i
+ puts "Stopping process #{pid} ..."
+ Process.kill( 'INT', pid ) rescue nil
+ end
+ end
+
+ desc 'Restart a cluster of waves applications.'
+ task :restart => [ :stop, :start ] do |task|
+ end
+
+end |
| |   |
| 1 | namespace :generate do |
| 2 | desc 'Generate a new model' |
| 3 | task :model do |task| |
| 4 | template = File.read :models / 'default.rb' |
| 5 | File.write( :models / ENV['name'] + '.rb', |
| 6 | template.gsub('class Default < Sequel::Model', |
| 7 | "class #{ENV['name'].camel_case} < Sequel::Model(:#{ENV['name'].plural})") ) |
| 8 | end |
| 9 | desc 'Generate a new controller' |
| 10 | task :controller do |task| |
| 11 | template = File.read :controllers / 'default.rb' |
| 12 | File.write( :controllers / ENV['name'] + '.rb', |
| 13 | template.gsub('class Default',"class #{ENV['name'].camel_case}") ) |
| 14 | end |
| 15 | end |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/lib/tasks/generate.rb
@@ -0,0 +1,15 @@
+namespace :generate do
+ desc 'Generate a new model'
+ task :model do |task|
+ template = File.read :models / 'default.rb'
+ File.write( :models / ENV['name'] + '.rb',
+ template.gsub('class Default < Sequel::Model',
+ "class #{ENV['name'].camel_case} < Sequel::Model(:#{ENV['name'].plural})") )
+ end
+ desc 'Generate a new controller'
+ task :controller do |task|
+ template = File.read :controllers / 'default.rb'
+ File.write( :controllers / ENV['name'] + '.rb',
+ template.gsub('class Default',"class #{ENV['name'].camel_case}") )
+ end
+end
\ No newline at end of file |
| |   |
| 1 | require 'sequel' |
| 2 | namespace :schema do |
| 3 | |
| 4 | desc 'Create a new Sequel Migration using name.' |
| 5 | task :migration do |task| |
| 6 | |
| 7 | version = ( ENV['version'].nil? ? |
| 8 | Sequel::Migrator.get_current_migration_version( Blog.database ) : |
| 9 | ENV['version'].to_i ) + 1 |
| 10 | |
| 11 | name = ENV['name'] || 'migration' |
| 12 | class_name = name.camel_case |
| 13 | |
| 14 | template = ( ENV['template'] || 'empty' ) + '.rb.erb' |
| 15 | source = :schema / :migrations / :templates / template |
| 16 | destination = :schema / :migrations / "#{'%03d' % version}_#{name}.rb" |
| 17 | code = Erubis::Eruby.new( File.read( source ) ).result( binding ) |
| 18 | File.write( destination, code ) |
| 19 | |
| 20 | end |
| 21 | |
| 22 | desc 'Performs migration from version, to version.' |
| 23 | task :migrate do |task| |
| 24 | version = ENV['version']; version = version.to_i unless version.nil? |
| 25 | Sequel::Migrator.apply( Waves.application.database, :schema / :migrations , version ) |
| 26 | end |
| 27 | |
| 28 | end |
| 29 | |
| toggle raw diff |
--- /dev/null
+++ b/waves/events/lib/tasks/schema.rb
@@ -0,0 +1,29 @@
+require 'sequel'
+namespace :schema do
+
+ desc 'Create a new Sequel Migration using name.'
+ task :migration do |task|
+
+ version = ( ENV['version'].nil? ?
+ Sequel::Migrator.get_current_migration_version( Blog.database ) :
+ ENV['version'].to_i ) + 1
+
+ name = ENV['name'] || 'migration'
+ class_name = name.camel_case
+
+ template = ( ENV['template'] || 'empty' ) + '.rb.erb'
+ source = :schema / :migrations / :templates / template
+ destination = :schema / :migrations / "#{'%03d' % version}_#{name}.rb"
+ code = Erubis::Eruby.new( File.read( source ) ).result( binding )
+ File.write( destination, code )
+
+ end
+
+ desc 'Performs migration from version, to version.'
+ task :migrate do |task|
+ version = ENV['version']; version = version.to_i unless version.nil?
+ Sequel::Migrator.apply( Waves.application.database, :schema / :migrations , version )
+ end
+
+end
+
\ No newline at end of file |