admin_template 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +5 -0
  2. data/Rakefile +25 -0
  3. data/lib/admin_template.rb +113 -0
  4. metadata +62 -0
data/README ADDED
@@ -0,0 +1,5 @@
1
+ this gem depend on the meta_search
2
+
3
+ plesse run
4
+
5
+ gem install meta_search
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env rake
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the admin_template plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the admin_template plugin.'
17
+ RDoc::Task.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'AdminTemplate'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+ require 'rubygems'
25
+ require 'rake'
@@ -0,0 +1,113 @@
1
+ module AdminTemplate
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def init_action
9
+ before_filter :init_model_string
10
+ include AdminTemplate::InstanceMethods
11
+
12
+ end
13
+ end
14
+
15
+
16
+ module InstanceMethods
17
+
18
+
19
+
20
+ def index
21
+
22
+ @title = t('labels.manager', :model => @model.model_name.human)
23
+ @search = @model.search(params[:search])
24
+
25
+ unless params[:keyword].blank?
26
+ keyword = split_keyword(params[:keyword])
27
+ keyword.each do |word|
28
+ @search.conditions.group do |group|
29
+ group.or_name_like = word
30
+ end
31
+ end
32
+ end
33
+
34
+ instance_variable_set("@#{@model_string.pluralize}" ,@search.page(params[:page] || 1).per(10))
35
+
36
+ end
37
+
38
+ def new
39
+ @title = t('labels.manager', :model => @model.model_name.human)
40
+ instance_variable_set("@#{@model_string}" ,@model.new)
41
+ end
42
+
43
+ def create
44
+
45
+ instance_variable_set("@#{@model_string}" ,@model.new(params["#{@model_string}"]))
46
+ if instance_variable_get("@#{@model_string}").save
47
+ flash[:notice] = t('labels.created_success')
48
+ if @model_string.pluralize == @model_string
49
+ redirect_to eval("admin_#{@model_string.pluralize}_index_path")
50
+ else
51
+ redirect_to eval("admin_#{@model_string.pluralize}_path")
52
+ end
53
+ else
54
+ render :action => :new
55
+ end
56
+ end
57
+
58
+ def edit
59
+ @title = t('labels.manager', :model => @model.model_name.human)
60
+ instance_variable_set("@#{@model_string}" ,@model.find(params[:id]))
61
+ end
62
+
63
+ def show
64
+ instance_variable_set("@#{@model_string}" ,@model.find(params[:id]))
65
+ render :edit
66
+ end
67
+
68
+ def update
69
+
70
+ instance_variable_set("@#{@model_string}" ,@model.find(params[:id]))
71
+ if instance_variable_get("@#{@model_string}").update_attributes(params["#{@model_string}"])
72
+ flash[:notice] = t('labels.update_success')
73
+ if @model_string.pluralize == @model_string
74
+ redirect_to eval("admin_#{@model_string.pluralize}_index_path")
75
+ else
76
+ redirect_to eval("admin_#{@model_string.pluralize}_path")
77
+ end
78
+ else
79
+ render :action => 'edit'
80
+ end
81
+ end
82
+
83
+ def destroy
84
+ instance_variable_set("@#{@model_string}" ,@model.find(params[:id]))
85
+
86
+ instance_variable_get("@#{@model_string}").destroy
87
+ respond_to do |format|
88
+ format.html {
89
+ if @model_string.pluralize == @model_string
90
+ redirect_to eval("admin_#{@model_string.pluralize}_index_path")
91
+ else
92
+ redirect_to eval("admin_#{@model_string.pluralize}_path")
93
+ end
94
+
95
+ }
96
+ format.xml { head :ok }
97
+ end
98
+ end
99
+
100
+
101
+
102
+ def init_model_string
103
+ begin
104
+ @model = self.class.to_s.split('::').last.sub(/Controller$/, '').singularize.classify.constantize
105
+ @model_string = self.class.to_s.split('::').last.sub(/Controller$/, '').singularize.downcase
106
+ rescue
107
+ p 'ERROR_BASE'
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: admin_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anthony Wang
9
+ - Rick Olson
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &2156862900 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2156862900
26
+ description: This admin_template plugin provides a foundation for securely managing
27
+ user.
28
+ email: vwangzhen@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README
34
+ - Rakefile
35
+ - lib/admin_template.rb
36
+ homepage: http://rubygems.org/gems/admin_template
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --main
41
+ - README.makdown
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.6
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: admin controller template
62
+ test_files: []