bivouac 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -20,17 +20,26 @@ Bivouac is a simple generator for camping[http://code.whytheluckystiff.net/campi
20
20
 
21
21
  == FEATURES/PROBLEMS:
22
22
 
23
+ === 0.2.4:
24
+
25
+ * Add rc file for script/console
26
+ * script/generate view is deprecated.
27
+ * controller generator now support view :
28
+ ruby script/generate controller my_controller my_view_one my_view_two ...
29
+ * Add RemoveColumnsFromTable-like migration
30
+ * Rewrite generators help
31
+ * cookies_sessions move from lib to lib/camping
32
+ * Improved support for multiple layouts: add the layout helper for controller. You can use 'layout :mylayout' instead of '@layout = "mylayout"' in your controller. Use 'layout :none' if you don't want to use a layout.
33
+
23
34
  === 0.2.3:
24
35
 
25
36
  * Ruby 1.9... not yet !
26
37
  * Database configuration use YAML
27
38
  * Add not_found controller and view
28
39
  * Remove :id column definition in migrate.rb
29
- * Add helper FormView#editable_content from
30
- http://blog.codahale.com/2006/01/14/a-rails-howto-simplify-in-place-editing-with-scriptaculous/
31
- Example at http://bivouac.rubyforge.org/svn/trunk/bivouac/examples/bivouac_sample/
40
+ * Add helper FormView#editable_content from http://blog.codahale.com/2006/01/14/a-rails-howto-simplify-in-place-editing-with-scriptaculous/ Example at http://bivouac.rubyforge.org/svn/trunk/bivouac/examples/bivouac_sample/
32
41
  * model generator now work with column name and type. Example :
33
- ruby script/generate model user name:string mail:string
42
+ ruby script/generate model user name:string mail:string
34
43
  * Add Multiple Layouts support (see http://rubyforge.org/pipermail/camping-list/2008-May/000729.html)
35
44
  * Thin is not more the default server (because layouts don't work with Thin :()
36
45
  * Add Cookie session support. Use -S to specify session type (db or cookie - default).
@@ -164,8 +173,10 @@ Bivouac is a simple generator for camping[http://code.whytheluckystiff.net/campi
164
173
  for ruby 1.8.6 (2007-06-07) [universal-darwin9.0]
165
174
 
166
175
  Specific options:
176
+ -d, --database NAME Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).
167
177
  -P, --port PORT Which port to bind to (3301)
168
178
  -a, --address ADDR Address to bind to (0.0.0.0)
179
+ -S, --session TYPE Session type (db|cookie). Default : cookie
169
180
 
170
181
  Common options:
171
182
  -?, --help Show this message
data/bin/bivouac CHANGED
@@ -125,6 +125,7 @@ createDir( "#{@conf.appdir}/app/controllers" )
125
125
  createDir( "#{@conf.appdir}/app/helpers" )
126
126
  createDir( "#{@conf.appdir}/app/models" )
127
127
  createDir( "#{@conf.appdir}/app/views" )
128
+ createDir( "#{@conf.appdir}/app/views/layouts" )
128
129
  createDir( "#{@conf.appdir}/db" )
129
130
  createDir( "#{@conf.appdir}/db/migrate" )
130
131
  createDir( "#{@conf.appdir}/public" )
@@ -177,6 +178,11 @@ createFile( "#{@conf.appdir}/script/console", true ) { |io|
177
178
  io.puts template( "console" )
178
179
  }
179
180
 
181
+ # Create console.rc view
182
+ createFile( "#{@conf.appdir}/script/console.rc" ) { |io|
183
+ io.puts template( "static/console_rc" )
184
+ }
185
+
180
186
  # Create plugin script
181
187
  createFile( "#{@conf.appdir}/script/plugin", true ) { |io|
182
188
  io.puts template( "plugin" )
@@ -211,6 +217,6 @@ createFile( "#{@conf.appdir}/app/views/not_found.rb" ) { |io|
211
217
  }
212
218
 
213
219
  # Create default_layout view
214
- createFile( "#{@conf.appdir}/app/views/default_layout.rb" ) { |io|
220
+ createFile( "#{@conf.appdir}/app/views/layouts/default_layout.rb" ) { |io|
215
221
  io.puts template( "static/default_layout_view" )
216
222
  }
data/doc/rdoc/created.rid CHANGED
@@ -1 +1 @@
1
- Tue, 03 Jun 2008 16:18:13 +0200
1
+ Fri, 06 Jun 2008 00:06:38 +0200
@@ -87,7 +87,7 @@ end</strong>
87
87
  <div id="README" class="page_shade">
88
88
  <div class="page">
89
89
  <div class="header">
90
- <div class="path">README / Tue Jun 03 16:17:16 +0200 2008</div>
90
+ <div class="path">README / Fri Jun 06 00:06:06 +0200 2008</div>
91
91
  </div>
92
92
 
93
93
  <h1>Bivouac</h1>
@@ -130,6 +130,36 @@ href="http://code.whytheluckystiff.net/camping">camping</a>.
130
130
  </li>
131
131
  </ul>
132
132
  <h2>FEATURES/PROBLEMS:</h2>
133
+ <h3>0.2.4:</h3>
134
+ <ul>
135
+ <li>Add rc file for script/console
136
+
137
+ </li>
138
+ <li>script/generate view is deprecated.
139
+
140
+ </li>
141
+ <li>controller generator now support view :
142
+
143
+ <pre>
144
+ ruby script/generate controller my_controller my_view_one my_view_two ...
145
+ </pre>
146
+ </li>
147
+ <li>Add RemoveColumnsFromTable-like migration
148
+
149
+ </li>
150
+ <li>Rewrite generators help
151
+
152
+ </li>
153
+ <li>cookies_sessions move from lib to lib/camping
154
+
155
+ </li>
156
+ <li>Improved support for multiple layouts: add the layout helper for
157
+ controller. You can use &#8216;layout :mylayout&#8217; instead of
158
+ &#8217;@layout = &quot;mylayout&quot;&#8217; in your controller. Use
159
+ &#8216;layout :none&#8217; if you don&#8216;t want to use a layout.
160
+
161
+ </li>
162
+ </ul>
133
163
  <h3>0.2.3:</h3>
134
164
  <ul>
135
165
  <li>Ruby 1.9&#8230; not yet !
@@ -144,17 +174,16 @@ href="http://code.whytheluckystiff.net/camping">camping</a>.
144
174
  <li>Remove :id column definition in migrate.rb
145
175
 
146
176
  </li>
147
- <li>Add helper FormView#editable_content from
177
+ <li>Add helper FormView#editable_content from <a
178
+ href="http://blog.codahale.com/2006/01/14/a-rails-howto-simplify-in-place-editing-with-scriptaculous">blog.codahale.com/2006/01/14/a-rails-howto-simplify-in-place-editing-with-scriptaculous</a>/
179
+ Example at <a
180
+ href="http://bivouac.rubyforge.org/svn/trunk/bivouac/examples/bivouac_sample">bivouac.rubyforge.org/svn/trunk/bivouac/examples/bivouac_sample</a>/
148
181
 
149
- <pre>
150
- http://blog.codahale.com/2006/01/14/a-rails-howto-simplify-in-place-editing-with-scriptaculous/
151
- Example at http://bivouac.rubyforge.org/svn/trunk/bivouac/examples/bivouac_sample/
152
- </pre>
153
182
  </li>
154
183
  <li>model generator now work with column name and type. Example :
155
184
 
156
185
  <pre>
157
- ruby script/generate model user name:string mail:string
186
+ ruby script/generate model user name:string mail:string
158
187
  </pre>
159
188
  </li>
160
189
  <li>Add Multiple Layouts support (see <a
@@ -471,8 +500,10 @@ change <tt>do_GET(req, res)</tt> to <tt>do_GET(req, resp)</tt>
471
500
  for ruby 1.8.6 (2007-06-07) [universal-darwin9.0]
472
501
 
473
502
  Specific options:
503
+ -d, --database NAME Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).
474
504
  -P, --port PORT Which port to bind to (3301)
475
505
  -a, --address ADDR Address to bind to (0.0.0.0)
506
+ -S, --session TYPE Session type (db|cookie). Default : cookie
476
507
 
477
508
  Common options:
478
509
  -?, --help Show this message
@@ -10,6 +10,7 @@ require 'bivouac/utils'
10
10
  require 'active_support'
11
11
  require 'active_record'
12
12
  require 'find'
13
+ require 'fileutils'
13
14
  require File.dirname($0) + '/../config/environment.rb'
14
15
 
15
16
  module Bivouac
@@ -61,7 +62,7 @@ module Bivouac
61
62
  puts "Usage: script/generate generator [options] [args]"
62
63
  puts ""
63
64
  puts "Generators"
64
- puts " Builtin: controller, model, migration, view, test"
65
+ puts " Builtin: controller, model, migration, test"
65
66
  puts " Plugins: " + @@plugins_generators.join(", ") if @@plugins_generators.size > 0
66
67
  puts ""
67
68
  puts "Commun options:"
@@ -79,13 +80,7 @@ module Bivouac
79
80
  opts.on("-v", "--no-view", "Do not generate any view for the controller") { |controller_options.noview|
80
81
  controller_options.noview = true
81
82
  }
82
- opts.on("-d", "--no-route", "Do not add the default route to the controller (/controller_name)") { |controller_options.default_route|
83
- controller_options.default_route = false
84
- }
85
- opts.on("-r", "--route ROUTE,ROUTE,...", "Add ROUTES to the controller") { |routes|
86
- controller_options.routes = routes.split(',')
87
- }
88
- opts.on("-t", "--no-test", "Do not generate any test for the controller") { |controller_options.notest|
83
+ opts.on("-t", "--no-test", "Do not generate any test for the controller") { |controller_options.notest|
89
84
  controller_options.notest = true
90
85
  }
91
86
 
@@ -93,6 +88,13 @@ module Bivouac
93
88
  opts.on_tail("-h", "--help", "Show this message") do
94
89
  help
95
90
  puts opts
91
+ puts ""
92
+ puts "Description:"
93
+ puts " Stubs out a new controller and its views. Pass the controller name, either"
94
+ puts " CamelCased or under_scored, and a list of views as arguments."
95
+ puts ""
96
+ puts "Example:"
97
+ puts " ruby script/generate controller my_controller my_view_one my_view_two ..."
96
98
  exit
97
99
  end
98
100
  end
@@ -102,44 +104,75 @@ module Bivouac
102
104
  if @script_arguments.length < 1
103
105
  help
104
106
  puts argument_options
107
+ puts ""
108
+ puts "Description:"
109
+ puts " Stubs out a new controller and its views. Pass the controller name, either"
110
+ puts " CamelCased or under_scored, and a list of views as arguments."
111
+ puts ""
112
+ puts "Example:"
113
+ puts " ruby script/generate controller my_controller my_view_one my_view_two ..."
105
114
  exit
106
115
  end
107
-
108
- @script_arguments.each do |controller_name|
109
- # Controller class name, passed to the template
110
- @controller_class_name = controller_name.classify
111
- # File name for the template
112
- controller_file_name = @controller_class_name.underscore
113
-
114
- # Destination file
115
- destination_file = File.dirname( $0 ) + "/../app/controllers/" + controller_file_name + ".rb"
116
+
117
+ # List of routes for test
118
+ routes = []
119
+
120
+ # Get controller
121
+ controller = @script_arguments.shift
122
+ # File name for the template
123
+ controller_file_name = controller.underscore
124
+
125
+ # Views directory
126
+ views_directory = File.dirname( $0 ) + "/../app/views/" + controller_file_name
127
+ # Create views directory
128
+ createDir( views_directory )
129
+
130
+ # Destination file
131
+ controller_file = File.dirname( $0 ) + "/../app/controllers/" + controller_file_name + ".rb"
132
+
133
+ # Create controller
134
+ createFile( controller_file ) do |io|
135
+ io.puts template( "generate/controller_begin", binding )
136
+
137
+ # Create views
138
+ @script_arguments.each do |view|
139
+ # Controller class name, passed to the template
140
+ @controller_class_name = controller.classify + view.classify
141
+
142
+ # Set view name, passed to the template
143
+ @view_name = @controller_class_name.underscore
144
+
145
+ # File name for the view
146
+ @view_file = views_directory + "/" + view.underscore + ".rb"
147
+
148
+ # Set controller route
149
+ new_route = controller.underscore + "/" + view.underscore
150
+ routes << new_route
151
+ @controller_routes = " < R '/" + new_route + "'"
116
152
 
117
- # Set view name, passed to the template
118
- @view_name = @controller_class_name.underscore
119
-
120
- # Set routes, passed to the template
121
- default_route = @view_name
122
- controller_options.routes << default_route if controller_options.default_route and controller_options.routes.include?( default_route ) == false
123
- @controller_routes = if controller_options.routes.size > 0
124
- " < R '/" + controller_options.routes.join("', '/") + "'"
125
- else
126
- ""
127
- end
128
-
129
- # Create controller
130
- createFile( destination_file ) do |io|
131
- io.puts template( "generate/controller", binding )
153
+ # Update controller
154
+ io.puts template( "generate/controller_action", binding )
155
+
156
+ # Create view view_name
157
+ createFile( @view_file ) do |io_view|
158
+ io_view.puts template( "generate/view", binding )
159
+ end
160
+
132
161
  end
133
162
 
134
- # Create view @view_name
135
- view( @view_name ) if controller_options.noview == false
136
-
137
163
  # Create test for @view_name with routes controller_options.routes
138
- test( @view_name, controller_options.routes ) if controller_options.notest == false
164
+ test( controller, routes ) if controller_options.notest == false
165
+
166
+ # Write controller end
167
+ io.puts template( "generate/controller_end", binding )
139
168
  end
140
169
  end
141
170
 
171
+ # DEPRECATED
142
172
  def view( view_name = nil )
173
+ warn "View generator is deprecated."
174
+ return
175
+
143
176
  if @app.environment.orgtype.downcase == "erb"
144
177
  raise "ERB applications are no longer supported. Sorry!"
145
178
  end
@@ -191,6 +224,13 @@ module Bivouac
191
224
  opts.on_tail("-h", "--help", "Show this message") do
192
225
  help
193
226
  puts opts
227
+ puts ""
228
+ puts "Description:"
229
+ puts " Stubs out a new test. Pass the name of the test, either"
230
+ puts " CamelCased or under_scored, as an argument."
231
+ puts ""
232
+ puts "Example:"
233
+ puts " ruby script/generate test my_test /route/one /route/two ..."
194
234
  exit
195
235
  end
196
236
  end
@@ -201,6 +241,13 @@ module Bivouac
201
241
  if @script_arguments.length < 1
202
242
  help
203
243
  puts argument_options
244
+ puts ""
245
+ puts "Description:"
246
+ puts " Stubs out a new test. Pass the name of the test, either"
247
+ puts " CamelCased or under_scored, as an argument."
248
+ puts ""
249
+ puts "Example:"
250
+ puts " ruby script/generate test my_test /route/one /route/two ..."
204
251
  exit
205
252
  end
206
253
 
@@ -213,7 +260,9 @@ module Bivouac
213
260
  createFile( destination_file ) do |io|
214
261
  io.puts template( "generate/test_begin", binding )
215
262
 
216
- routes.each do |@test_route|
263
+ routes.each do |route|
264
+ @route = route
265
+ @test_name = route.gsub( /\//, '_' )
217
266
  io.puts template( "generate/test_views", binding )
218
267
  end
219
268
 
@@ -229,6 +278,16 @@ module Bivouac
229
278
  opts.on_tail("-h", "--help", "Show this message") do
230
279
  help
231
280
  puts opts
281
+ puts ""
282
+ puts "Description:"
283
+ puts " Stubs out a new model. Pass the model name, either CamelCased or"
284
+ puts " under_scored, and an optional list of attribute pairs as arguments."
285
+ puts ""
286
+ puts " Attribute pairs are column_name:sql_type arguments specifying the"
287
+ puts " model's attributes."
288
+ puts ""
289
+ puts "Example:"
290
+ puts " ruby script/generate model MyModel name:string age:integer ..."
232
291
  exit
233
292
  end
234
293
  end
@@ -239,6 +298,16 @@ module Bivouac
239
298
  if @script_arguments.length < 1
240
299
  help
241
300
  puts argument_options
301
+ puts ""
302
+ puts "Description:"
303
+ puts " Stubs out a new model. Pass the model name, either CamelCased or"
304
+ puts " under_scored, and an optional list of attribute pairs as arguments."
305
+ puts ""
306
+ puts " Attribute pairs are column_name:sql_type arguments specifying the"
307
+ puts " model's attributes."
308
+ puts ""
309
+ puts "Example:"
310
+ puts " ruby script/generate model MyModel name:string age:integer ..."
242
311
  exit
243
312
  end
244
313
  model_list = @script_arguments
@@ -268,7 +337,18 @@ module Bivouac
268
337
  opts.on_tail("-h", "--help", "Show this message") do
269
338
  help
270
339
  puts opts
271
- exit
340
+ puts ""
341
+ puts "Description:"
342
+ puts " Stubs out a new database migration. Pass the migration name, either"
343
+ puts " CamelCased or under_scored, and an optional list of attribute pairs as arguments."
344
+ puts ""
345
+ puts " You can name your migration in either of these formats to generate add/remove"
346
+ puts " column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable"
347
+ puts ""
348
+ puts "Example:"
349
+ puts " ruby script/generate migration AddTrucToPost truc:string"
350
+ puts " ruby script/generate migration RemoveTrucFromPost truc:string"
351
+ exit
272
352
  end
273
353
  end
274
354
 
@@ -278,6 +358,17 @@ module Bivouac
278
358
  if @script_arguments.length < 1
279
359
  help
280
360
  puts argument_options
361
+ puts ""
362
+ puts "Description:"
363
+ puts " Stubs out a new database migration. Pass the migration name, either"
364
+ puts " CamelCased or under_scored, and an optional list of attribute pairs as arguments."
365
+ puts ""
366
+ puts " You can name your migration in either of these formats to generate add/remove"
367
+ puts " column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable"
368
+ puts ""
369
+ puts "Example:"
370
+ puts " ruby script/generate migration AddTrucToPost truc:string"
371
+ puts " ruby script/generate migration RemoveTrucFromPost truc:string"
281
372
  exit
282
373
  end
283
374
 
@@ -338,15 +429,33 @@ module Bivouac
338
429
  # Model table name
339
430
  @model_table_name = (@app.environment.appname.downcase + "_" + (model_name.underscore.split( /_/ ))[-1]).tableize
340
431
  io.puts template( "generate/migration_begin", binding )
341
- model.each do |column|
342
- @model_data_name, @model_data_type = column.split( /:/ )
343
- io.puts template( "generate/migration_add", binding )
344
- end
345
- io.puts template( "generate/migration_middle", binding )
346
- model.each do |column|
347
- @model_data_name, @model_data_type = column.split( /:/ )
348
- io.puts template( "generate/migration_remove", binding )
349
- end
432
+
433
+ # AddColumnsToTable
434
+ if r = /add_([^_]*)_to_([^_]*)/.match( model_name.underscore )
435
+ model.each do |column|
436
+ @model_data_name, @model_data_type = column.split( /:/ )
437
+ io.puts template( "generate/migration_add", binding )
438
+ end
439
+ io.puts template( "generate/migration_middle", binding )
440
+ model.each do |column|
441
+ @model_data_name, @model_data_type = column.split( /:/ )
442
+ io.puts template( "generate/migration_remove", binding )
443
+ end
444
+ # RemoveColumnsToTable
445
+ elsif r = /remove_([^_]*)_from_([^_]*)/.match( model_name.underscore )
446
+ model.each do |column|
447
+ @model_data_name, @model_data_type = column.split( /:/ )
448
+ io.puts template( "generate/migration_remove", binding )
449
+ end
450
+ io.puts template( "generate/migration_middle", binding )
451
+ model.each do |column|
452
+ @model_data_name, @model_data_type = column.split( /:/ )
453
+ io.puts template( "generate/migration_add", binding )
454
+ end
455
+ # Nor Add or Remove
456
+ else
457
+ io.puts template( "generate/migration_middle", binding )
458
+ end
350
459
  io.puts template( "generate/migration_end", binding )
351
460
  end
352
461
  end
@@ -19,12 +19,9 @@ task :environment do
19
19
  # Load models from app/models
20
20
  files( 'models' ) { |file| require( file ) }
21
21
 
22
- # Load create
22
+ # Load create and database schema
23
23
  files( '../db' ) { |file| require( file ) }
24
24
 
25
- # Load database schema from db/migrate
26
- files( '../db/migrate' ) { |file| require( file ) }
27
-
28
25
  require "#{ENV['BIVOUAC_ROOT']}/config/environment.rb"
29
26
  config = Bivouac::Environment.new( )
30
27
  database_connection = config.environment.db
@@ -147,9 +147,7 @@ class <%= @conf.appname %>Daemon < SimpleDaemon::Base
147
147
 
148
148
  require 'irb'
149
149
  require 'irb/completion'
150
- if File.exists? ".irbrc"
151
- ENV['IRBRC'] = ".irbrc"
152
- end
150
+ ENV['IRBRC'] = DIRNAME + "/console.rc"
153
151
  IRB.start
154
152
  end
155
153
  end
@@ -20,7 +20,7 @@ module <%= @conf.appname %>
20
20
  include Camping::Session
21
21
  end
22
22
  <% else %>
23
- require 'cookies_sessions'
23
+ require 'camping/cookies_sessions'
24
24
  module <%= @conf.appname %>
25
25
  include Camping::CookieSessions
26
26
  @@state_secret = "You want a really really long string of rubbish nobody could ever ever guess! Don't tell anyone! Not even your girlfriend or dog!"
@@ -47,7 +47,7 @@ files( 'helpers' ) { |file| require( file ) }
47
47
  # Load models from app/models
48
48
  files( 'models' ) { |file| require( file ) }
49
49
 
50
- # Load database schema from db/migrate
50
+ # Load create and database schema from db/migrate
51
51
  files( '../db/migrate' ) { |file| require( file ) }
52
52
 
53
53
  # Load views from app/views
@@ -80,8 +80,27 @@ module <%= @conf.appname %>::Controllers
80
80
  end
81
81
  end
82
82
 
83
- # Load create
84
- files( '../db' ) { |file| require( file ) }
83
+ # Multiple Layout support. Add
84
+ # layout :my_layout
85
+ # in your controller else, default_layout will be used
86
+ # If you don't want to use layout add
87
+ # layout :none
88
+ # in your controller
89
+ module <%= @conf.appname %>::Helpers
90
+ def layout( l )
91
+ @layout = l
92
+ end
93
+ end
94
+ module <%= @conf.appname %>::Views
95
+ def layout
96
+ @layout ||= :default
97
+ unless @layout == :none
98
+ send("#{@layout.to_s}_layout") { yield }
99
+ else
100
+ yield
101
+ end
102
+ end
103
+ end
85
104
 
86
105
  # Load postamble and configuration
87
106
  if __FILE__ == $0
@@ -0,0 +1,8 @@
1
+ class <%= @controller_class_name %><%= @controller_routes %>
2
+ def get
3
+ render :<%= @view_name %>
4
+ end
5
+ def post
6
+ render :<%= @view_name %>
7
+ end
8
+ end
@@ -6,12 +6,3 @@
6
6
  #
7
7
 
8
8
  module <%= @app.environment.appname %>::Controllers
9
- class <%= @controller_class_name %><%= @controller_routes %>
10
- def get
11
- render :<%= @view_name %>
12
- end
13
- def post
14
- render :<%= @view_name %>
15
- end
16
- end
17
- end
File without changes
@@ -14,4 +14,4 @@ require ENV['BIVOUAC_ROOT'] + "/app/<%= @app.environment.appdir %>"
14
14
  <%= @app.environment.appname %>.create if <%= @app.environment.appname %>.respond_to? :create
15
15
  include <%= @app.environment.appname %>::Models
16
16
 
17
- class Test<%= @app.environment.appname %> < Camping::FunctionalTest
17
+ class Tests<%= @app.environment.appname %> < Camping::FunctionalTest
@@ -1,4 +1,4 @@
1
- def test_<%= @test_route %>
2
- get '/<%= @test_route %>'
1
+ def test_<%= @test_name %>
2
+ get '/<%= @route %>'
3
3
  assert_response :success
4
4
  end
@@ -8,6 +8,6 @@
8
8
  module <%= @app.environment.appname %>::Views
9
9
  def <%= @view_name %>
10
10
  h1.header { "<%= @app.environment.appname %>::Views#<%= @view_name %>" }
11
- p "Find me in <%= @destination_file.gsub( /script\/\.\.\//, "" ) %>"
11
+ p "Find me in <%= @view_file.gsub( /script\/\.\.\//, "" ) %>"
12
12
  end
13
13
  end
@@ -0,0 +1,12 @@
1
+ #
2
+ # Project <%= @conf.appname %>
3
+ #
4
+ # Created using bivouac on <%= Time.now %>.
5
+ # Copyright (c) <%= Time.now.year %> __My__. All rights reserved.
6
+ #
7
+
8
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
9
+ IRB.conf[:AUTO_INDENT] = true
10
+
11
+ ## DO NOT REMOVE OR CHANGE LINES BELLOW
12
+ include <%= @conf.appname %>::Models
@@ -21,13 +21,5 @@ module <%= @conf.appname %>::Views
21
21
  end
22
22
  end
23
23
  end
24
-
25
- # Multiple Layout support :
26
- # add @layout = "my_layout" in your controller else, default_layout will be used
27
- # If you don't want to use layout, remove this file'
28
- def layout
29
- @layout ||= 'default'
30
- send("#{@layout}_layout") { yield }
31
- end
32
24
 
33
25
  end
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'erb'
2
3
 
3
4
  module Bivouac
data/lib/bivouac.rb CHANGED
@@ -3,12 +3,12 @@ module Bivouac
3
3
  @@_plugins_controller_helpers = []
4
4
 
5
5
  def files( xPath, *options, &block )
6
- path = File.dirname($0) + "/" + xPath.to_s + "/*.rb"
6
+ path = File.dirname($0) + "/" + xPath.to_s
7
7
  if ENV['BIVOUAC_ROOT']
8
- path = ENV['BIVOUAC_ROOT'] + "/app/" + xPath.to_s + "/*.rb"
8
+ path = ENV['BIVOUAC_ROOT'] + "/app/" + xPath.to_s
9
9
  end
10
10
 
11
- Dir[path].each do |file|
11
+ Dir.glob("#{path}/**/*.rb").each do |file|
12
12
  if options[0]
13
13
  if options[0].keys.include?( :except )
14
14
  if options[0][:except].include?(File.basename(file)) == false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bivouac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Gr\xC3\xA9goire Lejeune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-03 00:00:00 +02:00
12
+ date: 2008-06-06 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -115,7 +115,6 @@ files:
115
115
  - lib/bivouac
116
116
  - lib/bivouac/commands
117
117
  - lib/bivouac/commands/generate.rb
118
- - lib/bivouac/commands/generate.rb_OLD
119
118
  - lib/bivouac/commands/plugin.rb
120
119
  - lib/bivouac/helpers
121
120
  - lib/bivouac/helpers/view
@@ -134,7 +133,9 @@ files:
134
133
  - lib/bivouac/template/console.rb
135
134
  - lib/bivouac/template/environment.rb
136
135
  - lib/bivouac/template/generate
137
- - lib/bivouac/template/generate/controller.rb
136
+ - lib/bivouac/template/generate/controller_action.rb
137
+ - lib/bivouac/template/generate/controller_begin.rb
138
+ - lib/bivouac/template/generate/controller_end.rb
138
139
  - lib/bivouac/template/generate/create.rb
139
140
  - lib/bivouac/template/generate/migrate.rb
140
141
  - lib/bivouac/template/generate/migrate_begin.rb
@@ -150,7 +151,7 @@ files:
150
151
  - lib/bivouac/template/generate/test_begin.rb
151
152
  - lib/bivouac/template/generate/test_end.rb
152
153
  - lib/bivouac/template/generate/test_views.rb
153
- - lib/bivouac/template/generate/view_goh.rb
154
+ - lib/bivouac/template/generate/view.rb
154
155
  - lib/bivouac/template/generate.rb
155
156
  - lib/bivouac/template/plugin.rb
156
157
  - lib/bivouac/template/Rakefile.rb
@@ -159,6 +160,7 @@ files:
159
160
  - lib/bivouac/template/static/autocomplete.css
160
161
  - lib/bivouac/template/static/builder.js
161
162
  - lib/bivouac/template/static/camping.png
163
+ - lib/bivouac/template/static/console_rc.rb
162
164
  - lib/bivouac/template/static/controls.js
163
165
  - lib/bivouac/template/static/default_layout_view.rb
164
166
  - lib/bivouac/template/static/dragdrop.js
@@ -176,7 +178,8 @@ files:
176
178
  - lib/bivouac/template.rb
177
179
  - lib/bivouac/utils.rb
178
180
  - lib/bivouac.rb
179
- - lib/cookies_sessions.rb
181
+ - lib/camping
182
+ - lib/camping/cookies_sessions.rb
180
183
  - examples/bivouac_sample
181
184
  - examples/bivouac_sample/app
182
185
  - examples/bivouac_sample/app/bivouac_sample.rb
@@ -1,342 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # bivouac
3
- # (c)2007, 2008 Grégoire Lejeune
4
-
5
- require 'rubygems'
6
- require 'optparse'
7
- require 'ostruct'
8
- require 'bivouac/template'
9
- require 'bivouac/utils'
10
- require 'active_support'
11
- require 'active_record'
12
- require 'find'
13
- require File.dirname($0) + '/../config/environment.rb'
14
-
15
- module Bivouac
16
- class Generate
17
- include Bivouac::Template
18
- # Initialize the optionnal generators table
19
- add_generator []
20
-
21
- def initialize( argv )
22
- # Generator type (controller, model, migration, view, ...)
23
- @generator_type = argv.shift
24
-
25
- # Display help if asked
26
- if ['-h', '--help'].include?( @generator_type )
27
- help
28
- exit
29
- end
30
-
31
- # Generator arguments.
32
- # Example :
33
- # script/generate controller Hello World
34
- # @script_arguments = ['Hello', 'World']
35
- @script_arguments = argv.dup
36
-
37
- # Application environment
38
- @app = Bivouac::Environment.new( )
39
-
40
- # Database configuration
41
- @database_configuration = @app.environment.db
42
- if @database_configuration[:adapter] =~ /sqlite/
43
- @database_configuration[:database] = File.expand_path( File.dirname( $0 ) + "/../" + @database_configuration[:database] )
44
- end
45
- end
46
-
47
- def run
48
- # If the générator is not installed, display help and exit
49
- unless ( ["controller", "model", "migration", "view", "test"] + @@plugins_generators ).include?( @generator_type )
50
- help
51
- exit
52
- end
53
-
54
- # Call generator
55
- send( @generator_type.to_sym )
56
- return
57
- end
58
-
59
- private
60
- def help
61
- puts "Usage: script/generate generator [options] [args]"
62
- puts ""
63
- puts "Generators"
64
- puts " Builtin: controller, model, migration, view, test"
65
- puts " Plugins: " + @@plugins_generators.join(", ") if @@plugins_generators.size > 0
66
- puts ""
67
- puts "Commun options:"
68
- puts " -h, --help Show general help message"
69
- end
70
-
71
- def controller
72
- # controller generator options
73
- controller_options = OpenStruct.new( :noview => false, :notest => false, :default_route => true, :routes => [] )
74
-
75
- # Controller options
76
- argument_options = OptionParser.new do |opts|
77
- opts.banner = ""
78
- opts.separator "controller generator options:"
79
- opts.on("-v", "--no-view", "Do not generate any view for the controller") { |controller_options.noview|
80
- controller_options.noview = true
81
- }
82
- opts.on("-d", "--no-route", "Do not add the default route to the controller (/controller_name)") { |controller_options.default_route|
83
- controller_options.default_route = false
84
- }
85
- opts.on("-r", "--route ROUTE,ROUTE,...", "Add ROUTES to the controller") { |routes|
86
- controller_options.routes = routes.split(',')
87
- }
88
- opts.on("-t", "--no-test", "Do not generate any test for the controller") { |controller_options.notest|
89
- controller_options.notest = true
90
- }
91
-
92
- opts.separator ""
93
- opts.on_tail("-h", "--help", "Show this message") do
94
- help
95
- puts opts
96
- exit
97
- end
98
- end
99
-
100
- # parse options
101
- argument_options.parse! @script_arguments
102
- if @script_arguments.length < 1
103
- help
104
- puts argument_options
105
- exit
106
- end
107
-
108
- @script_arguments.each do |controller_name|
109
- # Controller class name, passed to the template
110
- @controller_class_name = controller_name.classify
111
- # File name for the template
112
- controller_file_name = @controller_class_name.underscore
113
-
114
- # Destination file
115
- destination_file = File.dirname( $0 ) + "/../app/controllers/" + controller_file_name + ".rb"
116
-
117
- # Set view name, passed to the template
118
- @view_name = @controller_class_name.underscore
119
-
120
- # Set routes, passed to the template
121
- default_route = @view_name
122
- controller_options.routes << default_route if controller_options.default_route and controller_options.routes.include?( default_route ) == false
123
- @controller_routes = if controller_options.routes.size > 0
124
- " < R '/" + controller_options.routes.join("', '/") + "'"
125
- else
126
- ""
127
- end
128
-
129
- # Create controller
130
- createFile( destination_file ) do |io|
131
- io.puts template( "generate/controller", binding )
132
- end
133
-
134
- # Create view @view_name
135
- view( @view_name ) if controller_options.noview == false
136
-
137
- # Create test for @view_name with routes controller_options.routes
138
- test( @view_name, controller_options.routes ) if controller_options.notest == false
139
- end
140
- end
141
-
142
- def view( view_name = nil )
143
- if @app.environment.orgtype.downcase == "erb"
144
- raise "ERB applications are no longer supported. Sorry!"
145
- end
146
-
147
- # View options
148
- argument_options = OptionParser.new do |opts|
149
- opts.banner = ""
150
- opts.separator "view generator options:"
151
- opts.on_tail("-h", "--help", "Show this message") do
152
- help
153
- puts opts
154
- exit
155
- end
156
- end
157
-
158
- # parse options if view name is not passed
159
- if view_name.nil?
160
- argument_options.parse! @script_arguments
161
- if @script_arguments.length < 1
162
- help
163
- puts argument_options
164
- exit
165
- end
166
-
167
- view_name = @script_arguments
168
- else
169
- view_name = [ view_name ]
170
- end
171
-
172
- view_name.each do |view|
173
- # Set view name, passed to the template
174
- @view_name = view.underscore
175
-
176
- # Set destination file, passed to the template
177
- @destination_file = File.dirname( $0 ) + "/../app/views/" + @view_name.underscore + ".rb"
178
-
179
- # Create view file
180
- createFile( @destination_file ) do |io|
181
- io.puts template( "generate/view_goh", binding )
182
- end
183
- end
184
- end
185
-
186
- def test( test_name = nil, routes = nil )
187
- # Test options
188
- argument_options = OptionParser.new do |opts|
189
- opts.banner = ""
190
- opts.separator "test generator options:"
191
- opts.on_tail("-h", "--help", "Show this message") do
192
- help
193
- puts opts
194
- exit
195
- end
196
- end
197
-
198
- # parse options if view name is not passed
199
- if test_name.nil?
200
- argument_options.parse! @script_arguments
201
- if @script_arguments.length < 1
202
- help
203
- puts argument_options
204
- exit
205
- end
206
-
207
- test_name = @script_arguments.shift
208
- routes = @script_arguments
209
- end
210
-
211
- # Create test file
212
- destination_file = File.dirname( $0 ) + "/../test/test_" + test_name.underscore + ".rb"
213
- createFile( destination_file ) do |io|
214
- io.puts template( "generate/test_begin", binding )
215
-
216
- routes.each do |@test_route|
217
- io.puts template( "generate/test_views", binding )
218
- end
219
-
220
- io.puts template( "generate/test_end", binding )
221
- end
222
- end
223
-
224
- def model( model = nil )
225
- # Model options
226
- argument_options = OptionParser.new do |opts|
227
- opts.banner = ""
228
- opts.separator "model generator options:"
229
- opts.on_tail("-h", "--help", "Show this message") do
230
- help
231
- puts opts
232
- exit
233
- end
234
- end
235
-
236
- # parse options
237
- if model.nil?
238
- argument_options.parse! @script_arguments
239
- if @script_arguments.length < 1
240
- help
241
- puts argument_options
242
- exit
243
- end
244
- model_list = @script_arguments
245
- else
246
- model_list = [ model ]
247
- end
248
-
249
- model_list.each do |model_name|
250
- # Model class name, passed to the template
251
- @model_class_name = model_name.classify
252
-
253
- destination_file = File.dirname( $0 ) + "/../app/models/" + @model_class_name.underscore + ".rb"
254
- createFile( destination_file ) do |io|
255
- io.puts template( "generate/model", binding )
256
- end
257
-
258
- migration( model_name )
259
- end
260
- end
261
-
262
- def migration( model = nil )
263
- # Test options
264
- argument_options = OptionParser.new do |opts|
265
- opts.banner = ""
266
- opts.separator "migration generator options:"
267
- opts.on_tail("-h", "--help", "Show this message") do
268
- help
269
- puts opts
270
- exit
271
- end
272
- end
273
-
274
- # parse options if view name is not passed
275
- if model.nil?
276
- argument_options.parse! @script_arguments
277
- if @script_arguments.length < 1
278
- help
279
- puts argument_options
280
- exit
281
- end
282
-
283
- model = @script_arguments
284
- from_model = false
285
- else
286
- model = [ model ]
287
- from_model = true
288
- end
289
-
290
- # Get old and new version
291
- old_version = 0.0
292
- begin
293
- ActiveRecord::Base.establish_connection @database_configuration
294
- conn = ActiveRecord::Base.connection
295
- table = nil
296
- conn.tables.each { |t| table = t if t =~ /_schema_infos$/ }
297
- version_info = conn.select_all( "select * from #{table}" )
298
- old_version = version_info[0]['version'].to_f
299
- rescue
300
- end
301
- @new_version = old_version + 1
302
-
303
- # Get prefix for file
304
- files = []
305
- Find.find( File.dirname( $0 ) + "/../db/migrate/" ) do |f|
306
- fn = File.basename( f )
307
- files << fn if fn =~ /^\d\d\d/
308
- end
309
- file_prefix = "001"
310
- if files.size > 0
311
- files = files.sort {|x,y| y[0,3] <=> x[0,3]}
312
- file_prefix = sprintf( "%03d", (files[0][0,3].to_i + 1) )
313
- end
314
-
315
- puts "\t* Migration from version #{old_version} to version #{@new_version}" if old_version > 0.0
316
-
317
- model.each do |model_name|
318
- # Model class name
319
- @model_class_name = model_name.classify
320
-
321
- # Model class name
322
- @model_table_name = (@app.environment.appname.downcase + "_" + model_name).tableize
323
-
324
- destination_file = File.dirname( $0 ) + "/../db/migrate/" + file_prefix + "_" + model_name.underscore + ".rb"
325
- createFile( destination_file ) do |io|
326
- if from_model
327
- io.puts template( "generate/migrate", binding )
328
- else
329
- io.puts template( "generate/migration", binding )
330
- end
331
- end
332
- end
333
-
334
- destination_file = File.dirname( $0 ) + "/../db/create.rb"
335
- createFile( destination_file, false, false ) do |io|
336
- io.puts template( "generate/create", binding )
337
- end
338
- end
339
- end
340
- end
341
-
342
- Bivouac::Generate.new( ARGV ).run( )