Skip to content
Browse files

fix problem with generators

  • Loading branch information...
1 parent b5b7af7 commit 4588afc70ec25866d425f77b3098d21b7fdf08e5 @jcieslar committed Feb 24, 2012
View
12 Gemfile.lock
@@ -1,8 +1,14 @@
PATH
remote: .
specs:
- customize_admin (0.0.4)
+ customize_admin (0.0.9)
+ devise (= 2.0.0)
+ formtastic (= 2.0.2)
+ has_scope (= 0.5.1)
+ inherited_resources (= 1.3.0)
rails (~> 3.1.1)
+ twitter-bootstrap-rails (= 1.4.3)
+ will_paginate (= 3.0.2)
GEM
remote: http://rubygems.org/
@@ -79,7 +85,6 @@ GEM
subexec (~> 0.2.1)
multi_json (1.0.4)
orm_adapter (0.0.6)
- pg (0.12.2)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
@@ -144,6 +149,5 @@ DEPENDENCIES
inherited_resources
jquery-rails
mini_magick
- pg
- twitter-bootstrap-rails
+ twitter-bootstrap-rails (= 1.4.3)
will_paginate
View
28 README.rdoc
@@ -15,3 +15,31 @@ And then execute:
After this run install generator:
rails g customize_admin:install
+
+== Useage
+
+=== Scaffold
+CustomizeAdmin allows you to create new resources and add them to your admin. For example:
+
+ rails g customize_admin:scaffold product name:string description:text
+
+=== Add resource
+CustomizeAdmin allows you to add new admin resource to your CustomizeAdmin using existing models
+ rails g customize_admin:add_resource NEW_ADMIN_RESOURCE EXISTING_RESOURCE
+
+For example:
+ rails g customize_admin:add_resource account user
+
+
+= Coming soon description of how to:
+== Customize views
+
+== Customize controllers
+
+=== Search query
+Default search query is set like this:
+
+ SEARCH_QUERY = "name LIKE ?"
+
+So, you can overwrite this in your current CustomizeAdmin controller and set different value
+
View
3 app/assets/stylesheets/customize_admin/application.css
@@ -35,6 +35,7 @@ form .input {
}
.right{
margin-left:auto;
+ width: 100px;
margin-right:auto;
}
#search{
@@ -65,7 +66,7 @@ margin-right:auto;
background: white;
cursor: default;
-
+
/* self-clearing method: */ }
.digg_pagination a, .digg_pagination span, .digg_pagination em {
line-height:34px;
View
2 app/views/customize_admin/base/_form.html.erb
@@ -1,4 +1,4 @@
-<%= semantic_form_for([:admin, resource]) do |f| %>
+<%= semantic_form_for( resource, :url => collection_path, :namespace => "#{CustomizeAdmin.name_space}") do |f| %>
<%= render :partial => "all_form_inputs", :locals => { :f => f } %>
<%= render :partial => "more_form_inputs", :locals => { :f => f } %>
<div class="right"><%= f.submit "Save", :class => "btn large primary" %> </div>
View
10 customize_admin.gemspec
@@ -17,11 +17,11 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 3.1.1"
- s.add_dependency 'inherited_resources'
- s.add_dependency 'has_scope'
- s.add_dependency 'formtastic'
- s.add_dependency 'will_paginate'
- s.add_dependency 'devise'
+ s.add_dependency 'inherited_resources', '1.3.0'
+ s.add_dependency 'has_scope', '0.5.1'
+ s.add_dependency 'formtastic', '2.0.2'
+ s.add_dependency 'will_paginate', '3.0.2'
+ s.add_dependency 'devise', '2.0.0'
s.add_dependency 'twitter-bootstrap-rails', '1.4.3'
# s.add_dependency "jquery-rails"
View
11 lib/customize_admin.rb
@@ -1,4 +1,15 @@
require "customize_admin/engine"
module CustomizeAdmin
+
+ mattr_accessor :name_space
+ @@name_space = "admin"
+
+ mattr_accessor :admin_user
+ @@admin_user = "AdminUser"
+
+ def self.setup
+ yield self
+ end
+
end
View
2 lib/customize_admin/version.rb
@@ -1,3 +1,3 @@
module CustomizeAdmin
- VERSION = "0.0.7"
+ VERSION = "0.0.9"
end
View
8 lib/generators/customize_admin/add_resource/USAGE
@@ -0,0 +1,8 @@
+Description:
+ Explain the generator
+
+Example:
+ rails generate scaffold Thing
+
+ This will create:
+ what/will/it/create
View
26 lib/generators/customize_admin/add_resource/add_resource_generator.rb
@@ -0,0 +1,26 @@
+class CustomizeAdmin::AddResourceGenerator < Rails::Generators::NamedBase
+ include Rails::Generators::ResourceHelpers
+ source_root File.expand_path('../templates', __FILE__)
+ argument :resource_class
+
+ def generate_controller
+ @namespace_class = CustomizeAdmin.name_space.camelize
+ @namespace = CustomizeAdmin.name_space
+ @controller_name = plural_name.camelize
+ @resource = resource_class.camelize
+ @collection_name = resource_class.pluralize
+ @instance_name = resource_class
+
+ template "controller_template.rb", "app/controllers/#{@namespace}/#{plural_name}_controller.rb"
+
+ insert_into_file "config/routes.rb", :after => "namespace :#{@namespace} do\n #customize_admin:\n" do
+ " resources :#{plural_name}\n"
+ end
+
+ insert_into_file "app/views/customize_admin/application/_admin_menu.html.erb", :after => "<li></li>\n" do
+ "<li><%= link_to '#{@controller_name}', #{@namespace +"_"+ plural_name}_path %></li>\n"
+ end
+
+ end
+
+end
View
46 lib/generators/customize_admin/add_resource/add_resource_generator.rb~
@@ -0,0 +1,46 @@
+class CustomizeAdmin::ScaffoldGenerator < Rails::Generators::NamedBase
+
+ source_root File.expand_path('../templates', __FILE__)
+ #argument :model_name, :type => :string
+ argument :fields, :type => :array, :banner => "field:type"
+ #argument :namespace, :type => :string, :default => "admin" #, :required => false
+
+ def generate_controller
+ puts file_name
+ #puts class_name
+ puts plural_name
+ puts options
+ puts namespace
+
+ @controller_name = plural_name[0].capitalize + plural_name.slice(1..-1)
+ #namespace = ask("Tell the admin namespace")
+ namespace = "admin"
+ @namespace = namespace[0].capitalize + namespace.slice(1..-1)
+ if namespace.present?
+ template "controller_template.rb", "app/controllers/#{namespace}/#{plural_name}_controller.rb"
+ insert_into_file "config/routes.rb", :after => "namespace :#{namespace} do\n #customize_admin:\n" do
+ " resources :#{plural_name}\n"
+ end
+ else
+ template "controller_template.rb", "app/controllers/#{plural_name}_controller.rb"
+ route("resources :#{plural_name}")
+ end
+
+ insert_into_file "app/views/customize_admin/application/_admin_menu.html.erb", :after => "customize_admin\n" do
+ "<%= link_to '#{@controller_name}', #{namespace +"_"+ plural_name}_path %>\n"
+ end
+
+ end
+
+ def add_to_menu
+ end
+
+ def generate_model
+ s = ""
+ fields.each do |f|
+ s += f + " "
+ end
+ generate "model #{file_name} #{s}"
+ end
+
+end
View
3 lib/generators/customize_admin/add_resource/templates/controller_template.rb
@@ -0,0 +1,3 @@
+class <%=@namespace_class%>::<%=@controller_name%>Controller < CustomizeAdmin::BaseController
+ defaults :resource_class => <%= @resource %>, :collection_name => "<%=@collection_name %>", :instance_name => "<%= @instance_name %>"
+end
View
16 lib/generators/customize_admin/install/install_generator.rb
@@ -1,10 +1,10 @@
class CustomizeAdmin::InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
+
def add_gems
insert_into_file "Gemfile", :after => "source 'http://rubygems.org'\n" do
- "# CustomizeAdmin gems:\n gem 'inherited_resources'\n gem 'has_scope'\n gem 'formtastic'\n gem 'will_paginate'\n gem 'devise'\n gem 'twitter-bootstrap-rails', '1.4.3' \n \n"
+ "# CustomizeAdmin gems:\n gem 'inherited_resources', '1.3.0'\n gem 'has_scope', '0.5.1'\n gem 'formtastic', '2.0.2'\n gem 'will_paginate', '3.0.2'\n gem 'devise', '2.0.0'\n gem 'twitter-bootstrap-rails', '1.4.3' \n \n"
end
-
end
def add_routes
@@ -16,7 +16,11 @@ def add_routes
def create_menu_file
create_file "app/views/customize_admin/application/_admin_menu.html.erb" do
- "<%= link_to 'Dashboard', #{@name_space}_path, :class => 'brand' %> \n"
+ "<%= link_to 'Dashboard', #{@name_space}_path, :class => 'brand' %>
+ <ul class='nav'>
+ <li></li>
+ </ul>
+ "
end
end
@@ -29,6 +33,8 @@ def run_devise_generator
end
def create_admin_user_table
+ #@devise_name = ask("Tell me devise admin user model (default is AdminUser)")
+ #@devise_name.blank? ? @devise_name = "AdminUser" : ""
generate "devise AdminUser"
end
@@ -68,4 +74,8 @@ def layout_by_resource
end
+ def add_config
+ template "customize_admin.rb", "config/initializers/customize_admin.rb"
+ end
+
end
View
5 lib/generators/customize_admin/install/templates/customize_admin.rb
@@ -0,0 +1,5 @@
+# Use this hook to configure devise mailer, warden hooks and so forth.
+# Many of these configuration options can be set straight in your model.
+CustomizeAdmin.setup do |config|
+ config.name_space = "<%= @name_space %>"
+end
View
21 lib/generators/customize_admin/scaffold/scaffold_generator.rb
@@ -1,21 +1,13 @@
class CustomizeAdmin::ScaffoldGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
- #argument :model_name, :type => :string
argument :fields, :type => :array, :banner => "field:type"
- #argument :namespace, :type => :string, :default => "admin" #, :required => false
def generate_controller
- puts file_name
- #puts class_name
- puts plural_name
- puts options
- puts namespace
- @controller_name = plural_name[0].capitalize + plural_name.slice(1..-1)
- #namespace = ask("Tell the admin namespace")
- namespace = "admin"
- @namespace = namespace[0].capitalize + namespace.slice(1..-1)
+ @controller_name = plural_name.pluralize.camelize
+ namespace = CustomizeAdmin.name_space
+ @namespace = namespace.camelize
if namespace.present?
template "controller_template.rb", "app/controllers/#{namespace}/#{plural_name}_controller.rb"
insert_into_file "config/routes.rb", :after => "namespace :#{namespace} do\n #customize_admin:\n" do
@@ -26,15 +18,12 @@ def generate_controller
route("resources :#{plural_name}")
end
- insert_into_file "app/views/customize_admin/application/_admin_menu.html.erb", :after => "customize_admin\n" do
- "<%= link_to '#{@controller_name}', #{namespace +"_"+ plural_name}_path %>\n"
+ insert_into_file "app/views/customize_admin/application/_admin_menu.html.erb", :after => "</li>\n" do
+ "<li><%= link_to '#{@controller_name}', #{namespace +"_"+ plural_name}_path %></li>\n"
end
end
- def add_to_menu
- end
-
def generate_model
s = ""
fields.each do |f|

0 comments on commit 4588afc

Please sign in to comment.
Something went wrong with that request. Please try again.