zscaffold_admin 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,17 +30,17 @@ module ScaffoldAdmin
30
30
  end
31
31
 
32
32
  def inject_code_helper
33
- path = IO.readlines("#{Rails.root}/config/routes.rb")
33
+ path = IO.readlines("config/routes.rb")
34
34
  content = File.open(File.expand_path("../templates/code_application_helper.rb", __FILE__), 'r') {|file| file.read}
35
35
  sentinel = /module ApplicationHelper/
36
36
  app = /::Application/
37
37
  engine = /::Engine/
38
- application = path.first.gsub(/::(.*)/, "").gsub("\n", "").underscore
38
+ application = path.first.gsub(/::(.*)/, "").chomp.underscore
39
39
 
40
40
  if path.first =~ app
41
- inject_into_file "#{Rails.root}/app/helpers/application_helper.rb", "\n#{content}\n", { :after => sentinel, :verbose => false }
41
+ inject_into_file "app/helpers/application_helper.rb", "\n#{content}\n", { :after => sentinel, :verbose => false }
42
42
  elsif path.first =~ engine
43
- inject_into_file "#{Rails.root}/app/helpers/#{application}/application_helper.rb", "\n#{content}\n", { :after => sentinel, :verbose => false }
43
+ inject_into_file "app/helpers/#{application}/application_helper.rb", "\n#{content}\n", { :after => sentinel, :verbose => false }
44
44
  end
45
45
  end
46
46
 
@@ -39,9 +39,9 @@ class ScaffoldAdminGenerator < Rails::Generators::Base
39
39
  def create_migration
40
40
  migration_number = Time.now.strftime('%Y%m%d%H%M%S')
41
41
  if namespace_name
42
- template 'migration.rb', "db/migrate/#{migration_number}_create_#{namespace_underscore}_#{plural_name}.rb"
42
+ migration_template "migration.rb", "db/migrate/create_#{namespace_underscore}_#{plural_name}.rb"
43
43
  else
44
- template 'migration.rb', "db/migrate/#{migration_number}_create_#{plural_name}.rb"
44
+ migration_template "migration.rb", "db/migrate/create_#{plural_name}.rb"
45
45
  end
46
46
  end
47
47
 
@@ -106,4 +106,14 @@ class ScaffoldAdminGenerator < Rails::Generators::Base
106
106
  end
107
107
  end
108
108
 
109
+ # FIXME: Should be proxied to ActiveRecord::Generators::Base
110
+ # Implement the required interface for Rails::Generators::Migration.
111
+ def self.next_migration_number(dirname) #:nodoc:
112
+ if ActiveRecord::Base.timestamped_migrations
113
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
114
+ else
115
+ "%.3d" % (current_migration_number(dirname) + 1)
116
+ end
117
+ end
118
+
109
119
  end
@@ -2,7 +2,10 @@
2
2
  module <%= module_name %>
3
3
  <%- end -%>
4
4
  class <%= plural_class %>Controller < ApplicationController
5
- layout 'admin'
5
+
6
+ before_filter :init, :only => [:show, :edit, :update, :destroy]
7
+
8
+ layout 'admin'
6
9
  respond_to :html, :xml, :js
7
10
 
8
11
  def index
@@ -11,9 +14,7 @@ class <%= plural_class %>Controller < ApplicationController
11
14
  respond_with @<%= plural_name %>
12
15
  end
13
16
 
14
- def show
15
- @<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
16
-
17
+ def show
17
18
  respond_with @<%= singular_name %>
18
19
  end
19
20
 
@@ -24,7 +25,6 @@ class <%= plural_class %>Controller < ApplicationController
24
25
  end
25
26
 
26
27
  def edit
27
- @<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
28
28
  respond_with @<%= singular_name %>
29
29
  end
30
30
 
@@ -39,9 +39,7 @@ class <%= plural_class %>Controller < ApplicationController
39
39
  end
40
40
  end
41
41
 
42
- def update
43
- @<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
44
-
42
+ def update
45
43
  if @<%= singular_name %>.update_attributes params[:<%= singular_name %>]
46
44
  flash[:notice] = I18n.t :<%= singular_name %>_updated
47
45
  respond_with @<%= singular_name %>
@@ -51,11 +49,14 @@ class <%= plural_class %>Controller < ApplicationController
51
49
  end
52
50
 
53
51
  def destroy
54
- @<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
55
52
  @<%= singular_name %>.destroy
56
53
 
57
54
  respond_with @<%= singular_name %>
58
55
  end
56
+
57
+ def init
58
+ @<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
59
+ end
59
60
 
60
61
  end
61
62
  <%- if namespace_name -%>
@@ -49,7 +49,7 @@
49
49
  <%= render :partial => 'shared/menu'%>
50
50
  <footer>
51
51
  <hr />
52
- <p><strong>Copyright &copy; 2011 Cidadelas</strong></p>
52
+ <p><strong>MIT-LICENSE</strong></p>
53
53
  <p>Theme by <a href="http://www.medialoot.com">MediaLoot</a></p>
54
54
  </footer>
55
55
  </aside><!-- end of sidebar -->
@@ -14,7 +14,7 @@
14
14
 
15
15
  <%- model_attributes.each do |attribute| -%>
16
16
  <fieldset>
17
- <label><b><%%= I18n.t :<%= attribute.name %> %></label></b>
17
+ <label><b><%%= I18n.t :<%= attribute.name %> %></b></label>
18
18
  <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
19
19
  </fieldset>
20
20
  <%- end -%>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Vagner Zampieri
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-04 00:00:00 -03:00
17
+ date: 2011-08-15 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20