typus 0.9.32 → 0.9.33
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/{lib/typus/templates → generators/typus/templates/auto}/index.html.erb +2 -2
- data/{lib/typus/templates → generators/typus/templates/auto}/resource_controller.rb.erb +0 -0
- data/{lib/typus/templates → generators/typus/templates/auto}/resource_controller_test.rb.erb +1 -0
- data/{lib/typus/templates → generators/typus/templates/auto}/resources_controller.rb.erb +0 -0
- data/generators/typus/typus_generator.rb +41 -3
- data/lib/typus.rb +0 -10
- data/typus.gemspec +5 -6
- metadata +5 -6
- data/lib/typus/generator.rb +0 -81
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.33
|
@@ -6,6 +6,6 @@
|
|
6
6
|
|
7
7
|
<!-- Content -->
|
8
8
|
|
9
|
-
<h2
|
9
|
+
<h2><%= params[:controller].split('/').last.titleize.capitalize %></h2>
|
10
10
|
|
11
|
-
<p>Find me in app/views/<%= params[:controller] %>/index.html.erb</p>
|
11
|
+
<p>Find me in app/views/<%= params[:controller] %>/index.html.erb</p>
|
File without changes
|
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ftools'
|
2
|
+
|
1
3
|
class TypusGenerator < Rails::Generator::Base
|
2
4
|
|
3
5
|
def manifest
|
@@ -10,14 +12,14 @@ class TypusGenerator < Rails::Generator::Base
|
|
10
12
|
# To create <tt>application.yml</tt> and <tt>application_roles.yml</tt>
|
11
13
|
# detect available AR models on the application.
|
12
14
|
models = Dir['app/models/*.rb'].collect { |x| File.basename(x).sub(/\.rb$/,'').camelize }
|
13
|
-
ar_models = []
|
15
|
+
@ar_models = []
|
14
16
|
|
15
17
|
models.each do |model|
|
16
18
|
begin
|
17
19
|
klass = model.constantize
|
18
20
|
active_record_model = klass.superclass.equal?(ActiveRecord::Base) && !klass.abstract_class?
|
19
21
|
active_record_model_with_sti = klass.superclass.superclass.equal?(ActiveRecord::Base)
|
20
|
-
ar_models << klass if active_record_model || active_record_model_with_sti
|
22
|
+
@ar_models << klass if active_record_model || active_record_model_with_sti
|
21
23
|
rescue Exception => error
|
22
24
|
puts "=> [typus] #{error.message} on '#{model.class.name}'."
|
23
25
|
exit
|
@@ -30,7 +32,7 @@ class TypusGenerator < Rails::Generator::Base
|
|
30
32
|
|
31
33
|
configuration = { :base => '', :roles => '' }
|
32
34
|
|
33
|
-
ar_models.sort{ |x,y| x.class_name <=> y.class_name }.each do |model|
|
35
|
+
@ar_models.sort{ |x,y| x.class_name <=> y.class_name }.each do |model|
|
34
36
|
|
35
37
|
# Detect all relationships except polymorphic belongs_to using reflection.
|
36
38
|
relationships = [ :belongs_to, :has_and_belongs_to_many, :has_many, :has_one ].map do |relationship|
|
@@ -118,6 +120,42 @@ class TypusGenerator < Rails::Generator::Base
|
|
118
120
|
m.file file, file
|
119
121
|
end
|
120
122
|
|
123
|
+
%w( app/views/admin app/controllers/admin test/functional/admin ).each do |folder|
|
124
|
+
FileUtils.mkdir_p(folder) unless File.directory?(folder)
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Generate:
|
129
|
+
# `app/controllers/admin/#{resource}_controller.rb`
|
130
|
+
# `test/functional/admin/#{resource}_controller_test.rb`
|
131
|
+
#
|
132
|
+
Typus.models.each do |model|
|
133
|
+
|
134
|
+
m.template "auto/resources_controller.rb.erb",
|
135
|
+
"app/controllers/admin/#{model.tableize}_controller.rb",
|
136
|
+
:assigns => { :model => model }
|
137
|
+
|
138
|
+
m.template "auto/resource_controller_test.rb.erb",
|
139
|
+
"test/functional/admin/#{model.tableize}_controller_test.rb",
|
140
|
+
:assigns => { :model => model }
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Generate controllers for tableless models.
|
146
|
+
#
|
147
|
+
Typus.resources.each do |resource|
|
148
|
+
|
149
|
+
m.template "auto/resource_controller.rb.erb",
|
150
|
+
"app/controllers/admin/#{resource.underscore}_controller.rb",
|
151
|
+
:assigns => { :resource => resource }
|
152
|
+
|
153
|
+
views_folder = "app/views/admin/#{resource.underscore}"
|
154
|
+
FileUtils.mkdir_p(views_folder) unless File.directory?(views_folder)
|
155
|
+
m.file "auto/index.html.erb", "#{views_folder}/index.html.erb"
|
156
|
+
|
157
|
+
end
|
158
|
+
|
121
159
|
# Migration file
|
122
160
|
|
123
161
|
m.migration_template 'db/create_typus_users.rb', 'db/migrate',
|
data/lib/typus.rb
CHANGED
@@ -70,11 +70,6 @@ module Typus
|
|
70
70
|
|
71
71
|
def boot!
|
72
72
|
|
73
|
-
commands = [ 'script/generate',
|
74
|
-
'script/destroy' ]
|
75
|
-
|
76
|
-
return if commands.include?($0)
|
77
|
-
|
78
73
|
if testing?
|
79
74
|
Typus::Configuration.options[:config_folder] = 'vendor/plugins/typus/test/config/working'
|
80
75
|
end
|
@@ -110,11 +105,6 @@ module Typus
|
|
110
105
|
require 'vendor/paginator'
|
111
106
|
require 'vendor/rss_parser'
|
112
107
|
|
113
|
-
commands = [ '/usr/local/bin/thin',
|
114
|
-
'script/server' ]
|
115
|
-
|
116
|
-
generator if commands.include?($0)
|
117
|
-
|
118
108
|
end
|
119
109
|
|
120
110
|
end
|
data/typus.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{typus}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.33"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Francesc Esplugas"]
|
@@ -64,6 +64,10 @@ Gem::Specification.new do |s|
|
|
64
64
|
"config/locales/pt-BR.yml",
|
65
65
|
"config/locales/ru.yml",
|
66
66
|
"config/routes.rb",
|
67
|
+
"generators/typus/templates/auto/index.html.erb",
|
68
|
+
"generators/typus/templates/auto/resource_controller.rb.erb",
|
69
|
+
"generators/typus/templates/auto/resource_controller_test.rb.erb",
|
70
|
+
"generators/typus/templates/auto/resources_controller.rb.erb",
|
67
71
|
"generators/typus/templates/config/initializers/typus.rb",
|
68
72
|
"generators/typus/templates/config/typus/README",
|
69
73
|
"generators/typus/templates/config/typus/application.yml",
|
@@ -106,7 +110,6 @@ Gem::Specification.new do |s|
|
|
106
110
|
"lib/typus/extensions/routes.rb",
|
107
111
|
"lib/typus/extensions/routes_hack.rb",
|
108
112
|
"lib/typus/format.rb",
|
109
|
-
"lib/typus/generator.rb",
|
110
113
|
"lib/typus/hash.rb",
|
111
114
|
"lib/typus/object.rb",
|
112
115
|
"lib/typus/preferences.rb",
|
@@ -114,10 +117,6 @@ Gem::Specification.new do |s|
|
|
114
117
|
"lib/typus/quick_edit.rb",
|
115
118
|
"lib/typus/reloader.rb",
|
116
119
|
"lib/typus/string.rb",
|
117
|
-
"lib/typus/templates/index.html.erb",
|
118
|
-
"lib/typus/templates/resource_controller.rb.erb",
|
119
|
-
"lib/typus/templates/resource_controller_test.rb.erb",
|
120
|
-
"lib/typus/templates/resources_controller.rb.erb",
|
121
120
|
"lib/typus/user.rb",
|
122
121
|
"lib/vendor/active_record.rb",
|
123
122
|
"lib/vendor/paginator.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesc Esplugas
|
@@ -70,6 +70,10 @@ files:
|
|
70
70
|
- config/locales/pt-BR.yml
|
71
71
|
- config/locales/ru.yml
|
72
72
|
- config/routes.rb
|
73
|
+
- generators/typus/templates/auto/index.html.erb
|
74
|
+
- generators/typus/templates/auto/resource_controller.rb.erb
|
75
|
+
- generators/typus/templates/auto/resource_controller_test.rb.erb
|
76
|
+
- generators/typus/templates/auto/resources_controller.rb.erb
|
73
77
|
- generators/typus/templates/config/initializers/typus.rb
|
74
78
|
- generators/typus/templates/config/typus/README
|
75
79
|
- generators/typus/templates/config/typus/application.yml
|
@@ -112,7 +116,6 @@ files:
|
|
112
116
|
- lib/typus/extensions/routes.rb
|
113
117
|
- lib/typus/extensions/routes_hack.rb
|
114
118
|
- lib/typus/format.rb
|
115
|
-
- lib/typus/generator.rb
|
116
119
|
- lib/typus/hash.rb
|
117
120
|
- lib/typus/object.rb
|
118
121
|
- lib/typus/preferences.rb
|
@@ -120,10 +123,6 @@ files:
|
|
120
123
|
- lib/typus/quick_edit.rb
|
121
124
|
- lib/typus/reloader.rb
|
122
125
|
- lib/typus/string.rb
|
123
|
-
- lib/typus/templates/index.html.erb
|
124
|
-
- lib/typus/templates/resource_controller.rb.erb
|
125
|
-
- lib/typus/templates/resource_controller_test.rb.erb
|
126
|
-
- lib/typus/templates/resources_controller.rb.erb
|
127
126
|
- lib/typus/user.rb
|
128
127
|
- lib/vendor/active_record.rb
|
129
128
|
- lib/vendor/paginator.rb
|
data/lib/typus/generator.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'ftools'
|
2
|
-
|
3
|
-
module Typus
|
4
|
-
|
5
|
-
def self.generator
|
6
|
-
|
7
|
-
# Create needed folders if doesn't exist.
|
8
|
-
admin_controllers_folder = "#{Rails.root}/app/controllers/admin"
|
9
|
-
admin_views_folder = "#{Rails.root}/app/views/admin"
|
10
|
-
|
11
|
-
[ admin_controllers_folder, admin_views_folder ].each do |folder|
|
12
|
-
Dir.mkdir(folder) unless File.directory?(folder)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Create test/functional/admin if doesn't exist.
|
16
|
-
admin_controller_tests_folder = "#{Rails.root}/test/functional/admin"
|
17
|
-
if File.directory?("#{Rails.root}/test")
|
18
|
-
Dir.mkdir(admin_controller_tests_folder) unless File.directory?(admin_controller_tests_folder)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Get a list of controllers under `app/controllers/admin`.
|
22
|
-
admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{admin_controllers_folder}/*.rb"]
|
23
|
-
admin_controllers = admin_controllers.map { |i| File.basename(i) }
|
24
|
-
|
25
|
-
# Get a list of functional tests under `test/functional/admin`.
|
26
|
-
admin_controller_tests = Dir["#{admin_controller_tests_folder}/*.rb"]
|
27
|
-
admin_controller_tests = admin_controller_tests.map { |i| File.basename(i) }
|
28
|
-
|
29
|
-
# Generate controllers for tableless models.
|
30
|
-
resources.each do |resource|
|
31
|
-
|
32
|
-
controller_filename = "#{resource.underscore}_controller.rb"
|
33
|
-
controller_location = "#{admin_controllers_folder}/#{controller_filename}"
|
34
|
-
|
35
|
-
if !admin_controllers.include?(controller_filename)
|
36
|
-
template = File.read("#{File.dirname(__FILE__)}/templates/resource_controller.rb.erb")
|
37
|
-
content = ERB.new(template).result(binding)
|
38
|
-
File.open(controller_location, "w+") { |f| f << content }
|
39
|
-
end
|
40
|
-
|
41
|
-
# And now we create the view.
|
42
|
-
view_folder = "#{admin_views_folder}/#{resource.underscore}"
|
43
|
-
view_filename = "index.html.erb"
|
44
|
-
|
45
|
-
if !File.exist?("#{view_folder}/#{view_filename}")
|
46
|
-
Dir.mkdir(view_folder) unless File.directory?(view_folder)
|
47
|
-
origin = "#{File.dirname(__FILE__)}/templates/index.html.erb"
|
48
|
-
destination = "#{view_folder}/#{view_filename}"
|
49
|
-
File.copy(origin, destination)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
# Generate:
|
55
|
-
# `app/controllers/admin/#{resource}_controller.rb`
|
56
|
-
# `test/functional/admin/#{resource}_controller_test.rb`
|
57
|
-
models.each do |model|
|
58
|
-
|
59
|
-
controller_filename = "#{model.tableize}_controller.rb"
|
60
|
-
controller_location = "#{admin_controllers_folder}/#{controller_filename}"
|
61
|
-
|
62
|
-
if !admin_controllers.include?(controller_filename)
|
63
|
-
template = File.read("#{File.dirname(__FILE__)}/templates/resources_controller.rb.erb")
|
64
|
-
content = ERB.new(template).result(binding)
|
65
|
-
File.open(controller_location, "w+") { |f| f << content }
|
66
|
-
end
|
67
|
-
|
68
|
-
test_filename = "#{model.tableize}_controller_test.rb"
|
69
|
-
test_location = "#{admin_controller_tests_folder}/#{test_filename}"
|
70
|
-
|
71
|
-
if !admin_controller_tests.include?(test_filename) && File.directory?("#{Rails.root}/test")
|
72
|
-
template = File.read("#{File.dirname(__FILE__)}/templates/resource_controller_test.rb.erb")
|
73
|
-
content = ERB.new(template).result(binding)
|
74
|
-
File.open(test_location, "w+") { |f| f << content }
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|