ixtlan-generators 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/lib/generators/ixtlan/base.rb +45 -0
  3. data/lib/generators/ixtlan/configuration_model/configuration_model_generator.rb +12 -0
  4. data/lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb +12 -0
  5. data/lib/generators/ixtlan/setup/setup_generator.rb +38 -0
  6. data/lib/generators/ixtlan/setup/templates/application_layout.html.erb +17 -0
  7. data/lib/generators/ixtlan/setup/templates/database.yml.example +48 -0
  8. data/lib/generators/ixtlan/setup/templates/error.html.erb +1 -0
  9. data/lib/generators/ixtlan/setup/templates/error_with_session.html.erb +1 -0
  10. data/lib/generators/ixtlan/setup/templates/gitignore +2 -0
  11. data/lib/generators/ixtlan/setup/templates/initializer.rb +64 -0
  12. data/lib/generators/ixtlan/setup/templates/preinitializer.rb +31 -0
  13. data/lib/generators/ixtlan/setup/templates/production.yml.example +8 -0
  14. data/lib/generators/ixtlan/setup/templates/stale.html.erb +2 -0
  15. data/lib/generators/model/model_generator.rb +12 -0
  16. data/lib/generators/rails/active_record/active_record_generator.rb +40 -0
  17. data/lib/generators/rails/active_record/model/migration.rb +19 -0
  18. data/lib/generators/rails/active_record/model/model.rb +16 -0
  19. data/lib/generators/rails/erb/erb_generator.rb +37 -0
  20. data/lib/generators/rails/erb/scaffold/_form.html.erb +28 -0
  21. data/lib/generators/rails/erb/scaffold/edit.html.erb +24 -0
  22. data/lib/generators/rails/erb/scaffold/index.html.erb +49 -0
  23. data/lib/generators/rails/erb/scaffold/new.html.erb +11 -0
  24. data/lib/generators/rails/erb/scaffold/show.html.erb +30 -0
  25. data/lib/generators/rails/scaffold_controller/scaffold_controller/controller.rb +129 -0
  26. data/lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb +43 -0
  27. data/lib/generators/scaffold/scaffold_generator.rb +35 -0
  28. data/lib/generators/scaffold_controller/scaffold_controller_generator.rb +34 -0
  29. data/lib/ixtlan-generators.rb +3 -0
  30. data/lib/ixtlan/railtie.rb +9 -0
  31. metadata +143 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Kristian Meier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ require 'rails/generators/named_base'
2
+ module Ixtlan
3
+ module Generators
4
+ class Base < Rails::Generators::Base
5
+
6
+ argument :name, :type => :string, :required => false
7
+
8
+ protected
9
+ def generator_name
10
+ raise "please overwrite generator_name"
11
+ end
12
+
13
+ public
14
+ def create
15
+ args = []
16
+ if name
17
+ args << ARGV.shift
18
+ else
19
+ args << "configuration"
20
+ end
21
+
22
+ if defined? ::Ixtlan::Errors
23
+ args << "errors_keep_dump:integer"
24
+ args << "errors_dir:string"
25
+ args << "errors_from:string"
26
+ args << "errors_to:string"
27
+ end
28
+
29
+ if defined? ::Ixtlan::Sessions
30
+ args << "idle_session_timeout:integer"
31
+ end
32
+
33
+ if defined? ::Ixtlan::Audit
34
+ args << "audit_keep_log:integer"
35
+ end
36
+
37
+ args += ARGV[0, 10000] || []
38
+
39
+ args << "--singleton"
40
+
41
+ generate generator_name, *args
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ require 'generators/ixtlan/base'
2
+ module Ixtlan
3
+ module Generators
4
+ class ConfigurationModelGenerator < Base
5
+
6
+ protected
7
+ def generator_name
8
+ "model"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'generators/ixtlan/base'
2
+ module Ixtlan
3
+ module Generators
4
+ class ConfigurationScaffoldGenerator < Base
5
+
6
+ protected
7
+ def generator_name
8
+ "scaffold"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ require 'rails/generators/base'
2
+ module Ixtlan
3
+ module Generators
4
+ class SetupGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def create_preinitializer_files
9
+ template 'preinitializer.rb', File.join('config', "preinitializer.rb")
10
+ template 'gitignore', File.join('config', ".gitignore")
11
+ template 'production.yml.example', File.join('config', "production.yml.example")
12
+ template 'database.yml.example', File.join('config', "database.yml.example")
13
+ end
14
+
15
+ def create_initializer_file
16
+ template 'initializer.rb', File.join('config', "initializers", "ixtlan.rb")
17
+ end
18
+
19
+ # TODO make only if template-engine is ERB
20
+ def error_templates
21
+ if defined? Ixtlan::Errors
22
+ views_dir = File.join('app', 'views', 'errors')
23
+ ['error', 'error_with_session', 'stale'].each do |f|
24
+ file = "#{f}.html.erb"
25
+ template file, File.join(views_dir, file)
26
+ end
27
+ end
28
+ end
29
+
30
+ def create_application_layout_file
31
+ if defined? Ixtlan::Sessions
32
+ layout = File.join('app', 'views', 'layouts', 'application.html.erb')
33
+ template 'application_layout.html.erb', layout
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= app_const_base %></title>
5
+ <%%= stylesheet_link_tag :all %>
6
+ <%%= javascript_include_tag :defaults %>
7
+ <%%= csrf_meta_tag %>
8
+ <%% if controller.respond_to?(:current_user) && controller.send(:current_user) != nil %>
9
+ <meta http-equiv="refresh" content="<%%= controller.send(:idle_session_timeout) * 60 + 5 %>" />
10
+ <%% end %>
11
+ </head>
12
+ <body>
13
+
14
+ <%%= yield %>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,48 @@
1
+ # MySQL. Versions 4.1 and 5.0 are recommended.
2
+ #
3
+ # Install the MySQL driver:
4
+ # gem install mysql
5
+ # On Mac OS X:
6
+ # sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
7
+ # On Mac OS X Leopard:
8
+ # sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
9
+ # This sets the ARCHFLAGS environment variable to your native architecture
10
+ # On Windows:
11
+ # gem install mysql
12
+ # Choose the win32 build.
13
+ # Install MySQL and put its /bin directory on your path.
14
+ #
15
+ # And be sure to use new-style password hashing:
16
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
17
+ development:
18
+ adapter: mysql
19
+ encoding: utf8
20
+ reconnect: false
21
+ database: test_development
22
+ pool: 5
23
+ username: root
24
+ password:
25
+ socket: /var/run/mysqld/mysqld.sock
26
+
27
+ # Warning: The database defined as "test" will be erased and
28
+ # re-generated from your development database when you run "rake".
29
+ # Do not set this db to the same as development or production.
30
+ test:
31
+ adapter: mysql
32
+ encoding: utf8
33
+ reconnect: false
34
+ database: test_test
35
+ pool: 5
36
+ username: root
37
+ password:
38
+ socket: /var/run/mysqld/mysqld.sock
39
+
40
+ production:
41
+ adapter: mysql
42
+ encoding: utf8
43
+ reconnect: false
44
+ database: CONFIG[:db][:database]
45
+ pool: 5
46
+ username: CONFIG[:db][:username]
47
+ password: CONFIG[:db][:password]
48
+ socket: /var/run/mysqld/mysqld.sock
@@ -0,0 +1 @@
1
+ <h1><%%= @notice %></h1>
@@ -0,0 +1 @@
1
+ <h1><%%= @notice %></h1>
@@ -0,0 +1,2 @@
1
+ production.yml
2
+ *.example
@@ -0,0 +1,64 @@
1
+ # dynamic configuration through a Configuration singleton model
2
+
3
+ # configuration model
4
+ # -------------------
5
+ # CONFIGURATION = Configuration
6
+ # config.configuration_model = CONFIGURATION
7
+ begin
8
+ config_instance = CONFIGURATION.instance
9
+ rescue
10
+ # allow rake tasks to work without configuration migrated
11
+ return
12
+ end
13
+
14
+ # notification email on errors and dump directory for the system dump
15
+ # the error dumps will be cleanup after the days to keeps dump expired
16
+ # --------------------------------------------------------------------
17
+ # config_instance.register("error_dumper") do |config|
18
+ # Rails.configuration.error_dumper.dump_dir = config.errors_dir
19
+ # Rails.configuration.error_dumper.email_from = config.errors_from
20
+ # Rails.configuration.error_dumper.email_to = config.errors_to
21
+ # Rails.configuration.error_dumper.keep_dumps = config.errors_keep_dump # days
22
+ # end
23
+
24
+ # idle session timeout configuration (in minutes)
25
+ # -----------------------------------------------
26
+ # config_instance.register("session_idle_timeout") do |config|
27
+ # Rails.configuration.session_idle_timeout = config.session_idle_timeout
28
+ # end
29
+
30
+ # audit log manager
31
+ # -----------------
32
+
33
+ # config.audit_manager.model = MyAudit # default: Audit
34
+ # config.audit_manager.username_method = :username # default: :login
35
+
36
+ # config_instance.register("audit_manager") do |config|
37
+ # Rails.configuration.audit_manager.keep_log = config.keep_log # days
38
+ # end
39
+
40
+ # --------------------
41
+ # static configuration
42
+ # --------------------
43
+
44
+ # error dumper
45
+ # ------------
46
+ # notification email on errors and dump directory for the system dump. per
47
+ # default there is no email notification and if email_from or email_to is
48
+ # missing then there is no email too
49
+
50
+ # config.error_dumper.dump_dir = Rails.root + "/log/errors" # default: log/errors
51
+ # config.error_dumper.email_from = "no-reply@example.com"
52
+ # config.error_dumper.email_to = "developer1@example.com,developer2@example.com"
53
+ # config.error_dumper.keep_dumps = 30 # days
54
+ # config.skip_rescue_module = true # do not include the predefined Rescue
55
+
56
+ # idle session timeout configuration
57
+ # ----------------------------------
58
+ # config.session_idle_timeout = 30 #minutes
59
+
60
+ # audit log manager
61
+ # -----------------
62
+ # config.audit_manager.model = MyAudit # default: Audit
63
+ # config.audit_manager.username_method = :username # default: :login
64
+ # config.audit_manager.keep_log = 30 # days
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+ module Ixtlan
4
+ class Configurator
5
+
6
+ def self.symbolize_keys(h)
7
+ result = {}
8
+
9
+ h.each do |k, v|
10
+ v = ' ' if v.nil?
11
+ if v.is_a?(Hash)
12
+ result[k.to_sym] = symbolize_keys(v) unless v.size == 0
13
+ else
14
+ result[k.to_sym] = v unless k.to_sym == v.to_sym
15
+ end
16
+ end
17
+
18
+ result
19
+ end
20
+
21
+ def self.load(file)
22
+ if File.exists?(file)
23
+ symbolize_keys(YAML::load(ERB.new(IO.read(file)).result))
24
+ else
25
+ warn "no file #{file} to load - maybe the is a #{file}.example"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ CONFIG = Ixtlan::Configurator.load(File.join(File.dirname(__FILE__), 'production.yml')) || {}
@@ -0,0 +1,8 @@
1
+ db:
2
+ database: production
3
+ username: worker
4
+ password: behappy
5
+ smtp:
6
+ host: mail.example.com
7
+ username: mailworker
8
+ password: secret
@@ -0,0 +1,2 @@
1
+ <h1>stale resource</h1>
2
+ <p>please reload resource and change it again</p>
@@ -0,0 +1,12 @@
1
+ module Rails
2
+ module Generators
3
+ class ModelGenerator < NamedBase #metagenerator
4
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
5
+ hook_for :orm, :required => true
6
+
7
+ if defined? Resty
8
+ hook_for :resty, :type => :boolean, :default => true
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ class ModelGenerator < Base
6
+ include ::Ixtlan::Core::Singleton
7
+
8
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
+
10
+ check_class_collision
11
+
12
+ class_option :migration, :type => :boolean
13
+ class_option :timestamps, :type => :boolean
14
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
15
+
16
+ def create_migration_file
17
+ return unless options[:migration] && options[:parent].nil?
18
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
19
+ end
20
+
21
+ def create_model_file
22
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
23
+ end
24
+
25
+ def create_module_file
26
+ return if class_path.empty?
27
+ template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
28
+ end
29
+
30
+ hook_for :test_framework
31
+
32
+ protected
33
+
34
+ def parent_class_name
35
+ options[:parent] || "ActiveRecord::Base"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.select {|attr| ![:has_one, :has_many].include?(attr.type) }.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ <% if options[:timestamps] %>
8
+ t.timestamps
9
+ <% end -%>
10
+ <% if options[:modified_by] %>
11
+ t.references :modified_by
12
+ <% end -%>
13
+ end
14
+ end
15
+
16
+ def self.down
17
+ drop_table :<%= table_name %>
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ class <%= class_name %> < <%= parent_class_name.classify %>
2
+ <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
3
+ belongs_to :<%= attribute.name %>
4
+ <% end -%>
5
+ <% attributes.select {|attr| [:has_one, :has_many].include?(attr.type) }.each do |attribute| -%>
6
+ <%= attribute.type %> :<%= attribute.name %>
7
+ <% end -%>
8
+ <% if options[:modified_by] -%>
9
+ belongs_to :modified_by, :class_name => "<%= options[:user_model] %>"
10
+ <% end -%>
11
+ <% if options[:singleton] -%>
12
+ def self.instance
13
+ self.first || self.new
14
+ end
15
+ <% end -%>
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'rails/generators/erb'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Erb
5
+ module Generators
6
+ class ScaffoldGenerator < Base
7
+ include Rails::Generators::ResourceHelpers
8
+
9
+ class_option :optimistic, :type => :boolean, :default => false
10
+ class_option :singleton, :type => :boolean, :default => false
11
+ class_option :timestamps, :type => :boolean, :default => true
12
+
13
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
14
+
15
+ def create_root_folder
16
+ empty_directory File.join("app/views", controller_file_path)
17
+ end
18
+
19
+ def copy_view_files
20
+ available_views.each do |view|
21
+ filename = filename_with_extensions(view)
22
+ template filename, File.join("app/views", controller_file_path, filename)
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def available_views
29
+ if options[:singleton]
30
+ %w(edit show _form)
31
+ else
32
+ %w(index edit show new _form)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ <%%= form_for(@<%= singular_table_name %><% if options[:singleton] -%>
2
+ , :url => <%= singular_table_name %>_path, :html => { :method => :put, :class => "edit_<%= singular_table_name %>", :id => "edit_<%= singular_table_name %>"}<% end -%>
3
+ ) do |f| %>
4
+ <%% if @<%= singular_table_name %>.errors.any? %>
5
+ <div id="error_explanation">
6
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
7
+
8
+ <ul>
9
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
10
+ <li><%%= msg %></li>
11
+ <%% end %>
12
+ </ul>
13
+ </div>
14
+ <%% end %>
15
+
16
+ <% for attribute in attributes -%>
17
+ <div class="field"><!-- begin - <%= attribute.name %> -->
18
+ <%%= f.label :<%= attribute.name %> %><br />
19
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
20
+ </div><!-- end - <%= attribute.name %> -->
21
+ <% end -%>
22
+ <div class="actions">
23
+ <% if options[:optimistic] && options[:timestamps] -%>
24
+ <%%= f.hidden_field :updated_at %>
25
+ <% end -%>
26
+ <%%= f.submit %>
27
+ </div>
28
+ <%% end %>
@@ -0,0 +1,24 @@
1
+ <h1>Editing <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <% if defined? ::Ixtlan::Guard -%>
6
+ <%% if allowed?(:<%= table_name %>, :show) %>
7
+ <% end -%>
8
+ <% if options[:singleton] -%>
9
+ <%%= link_to 'Show', <%= singular_table_name %>_path %>
10
+ <% else -%>
11
+ <%%= link_to 'Show', @<%= singular_table_name %> %>
12
+ <% end -%>
13
+ <% if defined? ::Ixtlan::Guard -%>
14
+ <%% end %>
15
+ <% end -%>
16
+ <% unless options[:singleton] -%>
17
+ <% if defined? ::Ixtlan::Guard -%>
18
+ <%% if allowed?(:<%= table_name %>, :index) %>
19
+ <% end -%>
20
+ | <%%= link_to 'Back', <%= index_helper %>_path %>
21
+ <% if defined? ::Ixtlan::Guard -%>
22
+ <%% end %>
23
+ <% end -%>
24
+ <% end -%>
@@ -0,0 +1,49 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% for attribute in attributes -%>
6
+ <th><%= attribute.human_name %></th>
7
+ <% end -%>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
14
+ <tr>
15
+ <% for attribute in attributes -%>
16
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
17
+ <% end -%>
18
+ <% if defined? ::Ixtlan::Guard -%>
19
+ <%% if allowed?(:<%= table_name %>, :show) %>
20
+ <% end -%>
21
+ <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
22
+ <% if defined? ::Ixtlan::Guard -%>
23
+ <%% end %>
24
+ <%% if allowed?(:<%= table_name %>, :update) %>
25
+ <% end -%>
26
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
27
+ <% if defined? ::Ixtlan::Guard -%>
28
+ <%% end %>
29
+ <%% if allowed?(:<%= table_name %>, :destroy) %>
30
+ <% end -%>
31
+ <td><% if options[:optimistic] && options[:timestamps] -%>
32
+ <%%= link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>) + "?<%= singular_table_name %>[updated_at]=#{<%= singular_table_name %>.updated_at.utc.strftime('%Y-%m-%d %H:%M:%S') + ("%06d" % <%= singular_table_name %>.updated_at.utc)}", :confirm => 'Are you sure?', :method => :delete %><% else -%><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete %>
33
+ <% end -%></td>
34
+ <% if defined? ::Ixtlan::Guard -%>
35
+ <%% end %>
36
+ <% end -%>
37
+ </tr>
38
+ <%% end %>
39
+ </table>
40
+
41
+ <br />
42
+
43
+ <% if defined? ::Ixtlan::Guard -%>
44
+ <%% if allowed?(:<%= table_name %>, :create) %>
45
+ <% end -%>
46
+ <%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
47
+ <% if defined? ::Ixtlan::Guard -%>
48
+ <%% end %>
49
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ <h1>New <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <% if defined? ::Ixtlan::Guard -%>
6
+ <%% if allowed?(:<%= table_name %>, :index) %>
7
+ <% end -%>
8
+ <%%= link_to 'Back', <%= index_helper %>_path %>
9
+ <% if defined? ::Ixtlan::Guard -%>
10
+ <%% end %>
11
+ <% end -%>
@@ -0,0 +1,30 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% for attribute in attributes -%>
4
+ <p>
5
+ <b><%= attribute.human_name %>:</b>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end -%>
10
+
11
+ <% if defined? ::Ixtlan::Guard -%>
12
+ <%% if allowed?(:<%= table_name %>, :update) %>
13
+ <% end -%>
14
+ <% if options[:singleton] -%>
15
+ <%%= link_to 'Edit', edit_<%= singular_table_name %>_path %>
16
+ <% else -%>
17
+ <%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %>
18
+ <% end -%>
19
+ <% if defined? ::Ixtlan::Guard -%>
20
+ <%% end %>
21
+ <% end -%>
22
+ <% unless options[:singleton] -%>
23
+ <% if defined? ::Ixtlan::Guard -%>
24
+ <%% if allowed?(:<%= table_name %>, :index) %>
25
+ <% end -%>
26
+ | <%%= link_to 'Back', <%= index_helper %>_path %>
27
+ <% if defined? ::Ixtlan::Guard -%>
28
+ <%% end %>
29
+ <% end -%>
30
+ <% end -%>
@@ -0,0 +1,129 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ # GET <%= route_url %>
3
+ # GET <%= route_url %>.xml
4
+ # GET <%= route_url %>.json
5
+ def index
6
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.xml { render :xml => @<%= plural_table_name %> }
11
+ format.json { render :json => @<%= plural_table_name %> }
12
+ end
13
+ end
14
+
15
+ # GET <%= route_url %>/1
16
+ # GET <%= route_url %>/1.xml
17
+ # GET <%= route_url %>/1.json
18
+ def show
19
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
20
+
21
+ respond_to do |format|
22
+ format.html # show.html.erb
23
+ format.xml { render :xml => @<%= singular_table_name %> }
24
+ format.json { render :json => @<%= singular_table_name %> }
25
+ end
26
+ end
27
+
28
+ # GET <%= route_url %>/new
29
+ def new
30
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
31
+ end
32
+
33
+ # GET <%= route_url %>/1/edit
34
+ def edit
35
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
36
+ end
37
+
38
+ # POST <%= route_url %>
39
+ # POST <%= route_url %>.xml
40
+ # POST <%= route_url %>.json
41
+ def create
42
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
43
+ <% if options[:modified_by] -%>
44
+ @<%= singular_table_name %>.current_user = current_user
45
+ <% end -%>
46
+
47
+ respond_to do |format|
48
+ if @<%= orm_instance.save %>
49
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.') }
50
+ format.xml { render :xml => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
51
+ format.json { render :json => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
52
+ else
53
+ format.html { render :action => "new" }
54
+ format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
55
+ format.json { render :json => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
56
+ end
57
+ end
58
+ end
59
+
60
+ # PUT <%= route_url %>/1
61
+ # PUT <%= route_url %>/1.xml
62
+ # PUT <%= route_url %>/1.json
63
+ def update
64
+ <% if options[:optimistic] && options[:timestamps] -%>
65
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "(params[:#{singular_table_name}]||[]).delete(:updated_at), params[:id]").sub(/\.(get|find)/, '.optimistic_\1') %>
66
+
67
+ if @<%= singular_table_name %>.nil?
68
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
69
+ respond_to do |format|
70
+ format.html { render :action => "edit" }
71
+ format.xml { render :xml => nil, :status => :conflict }
72
+ format.json { render :json => nil, :status => :conflict }
73
+ end
74
+ return
75
+ end
76
+ <% else -%>
77
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
78
+ (params[:<%= singular_table_name %>]||[]).delete(:updated_at)
79
+ <% end -%>
80
+ (params[:<%= singular_table_name %>]||[]).delete(:id)
81
+ <% if options[:modified_by] -%>
82
+ @<%= singular_table_name %>.current_user = current_user
83
+ <% end -%>
84
+
85
+ respond_to do |format|
86
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
87
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.') }
88
+ format.xml { render :xml => @<%= singular_table_name %> }
89
+ format.json { render :json => @<%= singular_table_name %> }
90
+ else
91
+ format.html { render :action => "edit" }
92
+ format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
93
+ format.json { render :json => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
94
+ end
95
+ end
96
+ end
97
+
98
+ # DELETE <%= route_url %>/1
99
+ # DELETE <%= route_url %>/1.xml
100
+ # DELETE <%= route_url %>/1.json
101
+ def destroy
102
+ <% if options[:optimistic] && options[:timestamps] -%>
103
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "(params[:#{singular_table_name}]||[]).delete(:updated_at), params[:id]").sub(/\.(get|find)/, '.optimistic_\1') %>
104
+
105
+ if @<%= singular_table_name %>.nil?
106
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
107
+ respond_to do |format|
108
+ format.html { render :action => "edit" }
109
+ format.xml { render :xml => nil, :status => :conflict }
110
+ format.json { render :json => nil, :status => :conflict }
111
+ end
112
+ return
113
+ end
114
+ <% else -%>
115
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
116
+ <% end -%>
117
+ <% if options[:modified_by] -%>
118
+ @<%= singular_table_name %>.current_user = current_user
119
+ <% end -%>
120
+
121
+ @<%= orm_instance.destroy %>
122
+
123
+ respond_to do |format|
124
+ format.html { redirect_to(<%= index_helper %>_url) }
125
+ format.xml { head :ok }
126
+ format.json { head :ok }
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,43 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+
3
+ # GET <%= route_url %>
4
+ # GET <%= route_url %>.xml
5
+ # GET <%= route_url %>.json
6
+ def show
7
+ @<%= singular_table_name %> = <%= class_name %>.instance
8
+
9
+ respond_to do |format|
10
+ format.html # show.html.erb
11
+ format.xml { render :xml => @<%= singular_table_name %> }
12
+ format.json { render :json => @<%= singular_table_name %> }
13
+ end
14
+ end
15
+
16
+ # GET <%= route_url %>/edit
17
+ def edit
18
+ @<%= singular_table_name %> = <%= class_name %>.instance
19
+ end
20
+
21
+ # PUT <%= route_url %>
22
+ # PUT <%= route_url %>.xml
23
+ # PUT <%= route_url %>.json
24
+ def update
25
+ @<%= singular_table_name %> = <%= class_name %>.instance
26
+ <% orm_class.find(class_name)
27
+ if options[:modified_by] -%>
28
+ @<%= singular_table_name %>.current_user = current_user
29
+ <% end -%>
30
+
31
+ respond_to do |format|
32
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
33
+ format.html { redirect_to(<%= singular_table_name %>_path, :notice => '<%= human_name %> was successfully updated.') }
34
+ format.xml { render :xml => @<%= singular_table_name %> }
35
+ format.json { render :json => @<%= singular_table_name %> }
36
+ else
37
+ format.html { render :action => "edit" }
38
+ format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
39
+ format.json { render :json => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails/generators/rails/resource/resource_generator'
2
+
3
+ module Rails
4
+ module Generators
5
+ class ScaffoldGenerator < ResourceGenerator #metagenerator
6
+ remove_hook_for :resource_controller
7
+ remove_class_option :actions
8
+
9
+ class_option :singleton, :type => :boolean, :default => false
10
+
11
+ hook_for :scaffold_controller, :required => true, :in => :scaffold_controller
12
+ hook_for :stylesheets
13
+
14
+ if defined? Resty
15
+ hook_for :resty, :type => :boolean, :default => true
16
+ end
17
+
18
+ if defined? ::Ixtlan::Guard
19
+ hook_for :guard, :type => :boolean, :default => true
20
+ end
21
+
22
+ def add_resource_route
23
+ return if options[:actions].present?
24
+ route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
25
+ if options[:singleton]
26
+ route_config << "resource :#{file_name}"
27
+ else
28
+ route_config << "resources :#{file_name.pluralize}"
29
+ end
30
+ route_config << " end" * class_path.size
31
+ route route_config
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ require 'rails/generators/resource_helpers'
2
+ require 'rails/generators/named_base'
3
+
4
+ module ScaffoldController
5
+ module Generators
6
+ class ScaffoldControllerGenerator < ::Rails::Generators::NamedBase
7
+ include ::Rails::Generators::ResourceHelpers
8
+
9
+ check_class_collision :suffix => "Controller"
10
+
11
+ class_option :orm, :banner => "NAME", :type => :string, :required => true,
12
+ :desc => "ORM to generate the controller for"
13
+
14
+ class_option :singleton, :type => :boolean, :default => false
15
+ class_option :optimistic, :type => :boolean, :default => false
16
+ class_option :timestamps, :type => :boolean, :default => true
17
+
18
+ def create_controller_files
19
+ if options[:singleton]
20
+ template 'singleton_controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
21
+ else
22
+ template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
23
+ end
24
+ end
25
+
26
+ hook_for :template_engine, :test_framework, :as => :scaffold, :in => :rails
27
+
28
+ # Invoke the helper using the controller name (pluralized)
29
+ hook_for :helper, :as => :scaffold, :in => :rails do |invoked|
30
+ invoke invoked, [ controller_name ]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ if defined?(Rails)
2
+ require 'ixtlan/railtie'
3
+ end
@@ -0,0 +1,9 @@
1
+ module Ixtlan
2
+ class Railtie < Rails::Railtie
3
+ config.generators do |config|
4
+
5
+ config.templates << File.expand_path('../../generators/rails', __FILE__)
6
+
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ixtlan-generators
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - mkristian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-05 00:00:00 +05:30
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ixtlan-core
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0.5"
25
+ - - <
26
+ - !ruby/object:Gem::Version
27
+ version: "0.99999"
28
+ type: :development
29
+ version_requirements: *id001
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ prerelease: false
33
+ requirement: &id002 !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - "="
37
+ - !ruby/object:Gem::Version
38
+ version: 3.0.9
39
+ type: :development
40
+ version_requirements: *id002
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ prerelease: false
44
+ requirement: &id003 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - "="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.6.0
50
+ type: :development
51
+ version_requirements: *id003
52
+ - !ruby/object:Gem::Dependency
53
+ name: cucumber
54
+ prerelease: false
55
+ requirement: &id004 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - "="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.9.4
61
+ type: :development
62
+ version_requirements: *id004
63
+ - !ruby/object:Gem::Dependency
64
+ name: ruby-maven
65
+ prerelease: false
66
+ requirement: &id005 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - "="
70
+ - !ruby/object:Gem::Version
71
+ version: 0.8.3.0.3.0.28.3
72
+ type: :development
73
+ version_requirements: *id005
74
+ description: rails generator templates for ixtlan gems
75
+ email:
76
+ - m.kristian@web.de
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files: []
82
+
83
+ files:
84
+ - MIT-LICENSE
85
+ - lib/ixtlan-generators.rb
86
+ - lib/generators/model/model_generator.rb
87
+ - lib/generators/scaffold/scaffold_generator.rb
88
+ - lib/generators/scaffold_controller/scaffold_controller_generator.rb
89
+ - lib/generators/rails/erb/erb_generator.rb
90
+ - lib/generators/rails/erb/scaffold/new.html.erb
91
+ - lib/generators/rails/erb/scaffold/_form.html.erb
92
+ - lib/generators/rails/erb/scaffold/index.html.erb
93
+ - lib/generators/rails/erb/scaffold/show.html.erb
94
+ - lib/generators/rails/erb/scaffold/edit.html.erb
95
+ - lib/generators/rails/scaffold_controller/scaffold_controller/controller.rb
96
+ - lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb
97
+ - lib/generators/rails/active_record/active_record_generator.rb
98
+ - lib/generators/rails/active_record/model/model.rb
99
+ - lib/generators/rails/active_record/model/migration.rb
100
+ - lib/generators/ixtlan/base.rb
101
+ - lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb
102
+ - lib/generators/ixtlan/setup/setup_generator.rb
103
+ - lib/generators/ixtlan/setup/templates/database.yml.example
104
+ - lib/generators/ixtlan/setup/templates/error_with_session.html.erb
105
+ - lib/generators/ixtlan/setup/templates/error.html.erb
106
+ - lib/generators/ixtlan/setup/templates/application_layout.html.erb
107
+ - lib/generators/ixtlan/setup/templates/preinitializer.rb
108
+ - lib/generators/ixtlan/setup/templates/initializer.rb
109
+ - lib/generators/ixtlan/setup/templates/gitignore
110
+ - lib/generators/ixtlan/setup/templates/stale.html.erb
111
+ - lib/generators/ixtlan/setup/templates/production.yml.example
112
+ - lib/generators/ixtlan/configuration_model/configuration_model_generator.rb
113
+ - lib/ixtlan/railtie.rb
114
+ has_rdoc: true
115
+ homepage: http://github.com/mkristian/ixtlan-generators
116
+ licenses:
117
+ - MIT-LICENSE
118
+ post_install_message:
119
+ rdoc_options: []
120
+
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.5.1
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: rails generator templates for ixtlan gems
142
+ test_files: []
143
+