Revisions

gist: 40105 Download_button fork
public
Public Clone URL: git://gist.github.com/40105.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#
# All this code is from a merb_sequel plugin, a good example of Templater generators extensibility
#
 
#
# Hook Sequel model generator and migration generation hook
#
Merb::Generators::ModelGenerator.template :model_sequel, :orm => :sequel do |t|
  t.source = File.dirname(__FILE__) / "templates/model/app/models/%file_name%.rb"
  t.destination = "app/models" / base_path / "#{file_name}.rb"
end
 
Merb::Generators::ModelGenerator.invoke :migration, :orm => :sequel do |generator|
  generator.new(destination_root, options.merge(:model => true), file_name, attributes)
end
 
 
#
# Migration generator for Sequel
#
Merb::Generators::MigrationGenerator.template :migration_sequel, :orm => :sequel do |t|
  t.source = File.dirname(__FILE__) / 'templates/migration/schema/migrations/%file_name%.rb'
  t.destination = "#{destination_directory}/#{file_name}.rb"
end
 
#
# Resource controller generator for Sequel
#
Merb::Generators::ResourceControllerGenerator.template :controller_sequel, :orm => :sequel do |t|
  t.source = File.dirname(__FILE__) / "templates/resource_controller/app/controllers/%file_name%.rb"
  t.destination = "app/controllers" / base_path / "#{file_name}.rb"
end
 
[:index, :show, :edit, :new].each do |view|
  Merb::Generators::ResourceControllerGenerator.template "view_#{view}_sequel".to_sym,
      :orm => :sequel, :template_engine => :erb do |t|
    t.source = File.dirname(__FILE__) / "templates/resource_controller/app/views/%file_name%/#{view}.html.erb"
    t.destination = "app/views" / base_path / "#{file_name}/#{view}.html.erb"
  end
end