sunrise-scaffold 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/Gemfile.lock +75 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +6 -3
- data/Rakefile +2 -2
- data/lib/generators/sunrise/scaffold/USAGE +6 -0
- data/lib/generators/sunrise/scaffold/manage_generator.rb +114 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/controller.rb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/functional_test.rb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/helper.rb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/edit.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/form.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/index.html.erb +1 -1
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/item.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/model_filter.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/new.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/show.html.erb +2 -2
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/controller.rb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/functional_test.rb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/helper.rb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/edit.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/form.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/index.html.erb +1 -1
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/item.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/model_filter.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/new.html.erb +0 -0
- data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/show.html.erb +2 -2
- data/lib/sunrise/scaffold/utils.rb +48 -0
- data/lib/sunrise/scaffold/version.rb +6 -0
- data/lib/sunrise/scaffold.rb +6 -0
- data/lib/sunrise-scaffold.rb +2 -0
- metadata +35 -29
- data/lib/generators/sunrise_scaffold/USAGE +0 -6
- data/lib/generators/sunrise_scaffold/manage_generator.rb +0 -112
- data/lib/sunrise_scaffold/utils.rb +0 -46
- data/lib/sunrise_scaffold/version.rb +0 -4
- data/lib/sunrise_scaffold.rb +0 -5
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.9)
|
6
|
+
actionpack (= 3.0.9)
|
7
|
+
mail (~> 2.2.19)
|
8
|
+
actionpack (3.0.9)
|
9
|
+
activemodel (= 3.0.9)
|
10
|
+
activesupport (= 3.0.9)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.9)
|
19
|
+
activesupport (= 3.0.9)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.9)
|
23
|
+
activemodel (= 3.0.9)
|
24
|
+
activesupport (= 3.0.9)
|
25
|
+
arel (~> 2.0.10)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.9)
|
28
|
+
activemodel (= 3.0.9)
|
29
|
+
activesupport (= 3.0.9)
|
30
|
+
activesupport (3.0.9)
|
31
|
+
arel (2.0.10)
|
32
|
+
builder (2.1.2)
|
33
|
+
erubis (2.6.6)
|
34
|
+
abstract (>= 1.0.0)
|
35
|
+
i18n (0.5.0)
|
36
|
+
mail (2.2.19)
|
37
|
+
activesupport (>= 2.3.6)
|
38
|
+
i18n (>= 0.4.0)
|
39
|
+
mime-types (~> 1.16)
|
40
|
+
treetop (~> 1.4.8)
|
41
|
+
mime-types (1.16)
|
42
|
+
polyglot (0.3.1)
|
43
|
+
rack (1.2.3)
|
44
|
+
rack-mount (0.6.14)
|
45
|
+
rack (>= 1.0.0)
|
46
|
+
rack-test (0.5.7)
|
47
|
+
rack (>= 1.0)
|
48
|
+
rails (3.0.9)
|
49
|
+
actionmailer (= 3.0.9)
|
50
|
+
actionpack (= 3.0.9)
|
51
|
+
activerecord (= 3.0.9)
|
52
|
+
activeresource (= 3.0.9)
|
53
|
+
activesupport (= 3.0.9)
|
54
|
+
bundler (~> 1.0)
|
55
|
+
railties (= 3.0.9)
|
56
|
+
railties (3.0.9)
|
57
|
+
actionpack (= 3.0.9)
|
58
|
+
activesupport (= 3.0.9)
|
59
|
+
rake (>= 0.8.7)
|
60
|
+
rdoc (~> 3.4)
|
61
|
+
thor (~> 0.14.4)
|
62
|
+
rake (0.9.2)
|
63
|
+
rdoc (3.8)
|
64
|
+
sqlite3 (1.3.3)
|
65
|
+
thor (0.14.6)
|
66
|
+
treetop (1.4.9)
|
67
|
+
polyglot (>= 0.3.1)
|
68
|
+
tzinfo (0.3.29)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
ruby
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
rails (= 3.0.9)
|
75
|
+
sqlite3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 Aimbulance
|
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.
|
data/README.rdoc
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
== USAGE
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
Before this, you must generate model (rails g model model_name) and create it in db (rake db:migrate)
|
6
|
+
|
7
|
+
rails generate sunrise:scaffold:manage model_name
|
7
8
|
|
8
|
-
rails generate
|
9
|
+
rails generate sunrise:scaffold:manage model_name --parent=parent_model
|
10
|
+
|
11
|
+
Copyright (c) 2011 Aimbulance, released under the MIT license
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rake/rdoctask'
|
5
|
-
require File.join(File.dirname(__FILE__), 'lib', '
|
5
|
+
require File.join(File.dirname(__FILE__), 'lib', 'sunrise', 'scaffold', 'version')
|
6
6
|
|
7
7
|
desc 'Default: run unit tests.'
|
8
8
|
task :default => :test
|
@@ -28,7 +28,7 @@ begin
|
|
28
28
|
require 'jeweler'
|
29
29
|
Jeweler::Tasks.new do |s|
|
30
30
|
s.name = "sunrise-scaffold"
|
31
|
-
s.version =
|
31
|
+
s.version = Sunrise::Scaffold::VERSION.dup
|
32
32
|
s.summary = "Rails CMS"
|
33
33
|
s.description = "Sunrise is a Aimbulance CMS"
|
34
34
|
s.email = "galeta.igor@gmail.com"
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'sunrise/scaffold/utils'
|
3
|
+
|
4
|
+
module Sunrise
|
5
|
+
module Scaffold
|
6
|
+
class ManageGenerator < Rails::Generators::NamedBase
|
7
|
+
check_class_collision :suffix => "Controller"
|
8
|
+
|
9
|
+
class_option :parent, :type => :string, :default => nil,
|
10
|
+
:desc => "Parent model"
|
11
|
+
|
12
|
+
def self.source_root
|
13
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), "/templates"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_controller_files
|
17
|
+
template "#{generator_dir}/controller.rb",
|
18
|
+
File.join('app/controllers', manage_path, "#{controller_file_name}_controller.rb")
|
19
|
+
|
20
|
+
template "#{generator_dir}/helper.rb",
|
21
|
+
File.join('app/helpers', manage_path, "#{controller_file_name}_helper.rb")
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_tests_files
|
25
|
+
template "#{generator_dir}/functional_test.rb",
|
26
|
+
File.join('test/functional', manage_path, "#{controller_file_name}_controller_test.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_views_files
|
30
|
+
# model form
|
31
|
+
template "#{generator_dir}/views/form.html.erb",
|
32
|
+
File.join('app/views', manage_path, controller_file_name, "_form.html.erb")
|
33
|
+
|
34
|
+
# search filter
|
35
|
+
template "#{generator_dir}/views/model_filter.html.erb",
|
36
|
+
File.join('app/views', manage_path, controller_file_name, "_model_filter.html.erb")
|
37
|
+
|
38
|
+
# collection view partial
|
39
|
+
template "#{generator_dir}/views/item.html.erb",
|
40
|
+
File.join('app/views', manage_path, controller_file_name, "_#{singular_name}.html.erb")
|
41
|
+
|
42
|
+
# other templates
|
43
|
+
[:index, :new, :edit, :show].each do |action|
|
44
|
+
template "#{generator_dir}/views/#{action}.html.erb",
|
45
|
+
File.join('app/views', manage_path, controller_file_name, "#{action}.html.erb")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def manage_path
|
52
|
+
"manage"
|
53
|
+
end
|
54
|
+
|
55
|
+
def klass
|
56
|
+
# First priority is the namespaced modek, e.g. User::Group
|
57
|
+
@klass ||= begin
|
58
|
+
namespaced_class = name.singularize
|
59
|
+
namespaced_class.constantize
|
60
|
+
rescue NameError
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# Second priority the camelcased c, i.e. UserGroup
|
65
|
+
@klass ||= begin
|
66
|
+
camelcased_class = name.gsub('::', '').singularize
|
67
|
+
camelcased_class.constantize
|
68
|
+
rescue NameError
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
@klass ||= model_name.constantize
|
73
|
+
|
74
|
+
@klass
|
75
|
+
end
|
76
|
+
|
77
|
+
def model
|
78
|
+
@model ||= klass.new
|
79
|
+
end
|
80
|
+
|
81
|
+
def model_name
|
82
|
+
@model_name ||= name.camelize
|
83
|
+
@model_name
|
84
|
+
end
|
85
|
+
|
86
|
+
def controller_class_name
|
87
|
+
@controller_class_name ||= name.pluralize.camelize
|
88
|
+
end
|
89
|
+
|
90
|
+
def controller_file_name
|
91
|
+
@controller_file_name ||= file_name.pluralize
|
92
|
+
end
|
93
|
+
|
94
|
+
def generator_dir
|
95
|
+
options[:parent] ? "multiplay" : "single"
|
96
|
+
end
|
97
|
+
|
98
|
+
def parent_class_name
|
99
|
+
@parent_class_name ||= parent_singular_name.camelize
|
100
|
+
@parent_class_name
|
101
|
+
end
|
102
|
+
|
103
|
+
def parent_singular_name
|
104
|
+
@parent_singular_name ||= options[:parent].singularize
|
105
|
+
@parent_singular_name
|
106
|
+
end
|
107
|
+
|
108
|
+
def translated_columns
|
109
|
+
@translated_columns ||= klass.translated_attribute_names if klass.respond_to?(:translated_attribute_names)
|
110
|
+
@translated_columns ||= []
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/functional_test.rb
RENAMED
File without changes
|
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/edit.html.erb
RENAMED
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/form.html.erb
RENAMED
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/index.html.erb
RENAMED
@@ -13,7 +13,7 @@
|
|
13
13
|
</div>
|
14
14
|
<div id="<%= plural_name %>" class="stage">
|
15
15
|
<%%= render :partial=>"manage/<%= plural_name %>/<%= singular_name %>", :collection=>@<%= plural_name %> %>
|
16
|
-
<%%= paginate @<%= plural_name
|
16
|
+
<%%= paginate @<%= plural_name %>, :theme => 'manage' %>
|
17
17
|
</div>
|
18
18
|
|
19
19
|
<script type='text/javascript'>
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/item.html.erb
RENAMED
File without changes
|
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/new.html.erb
RENAMED
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/multiplay/views/show.html.erb
RENAMED
@@ -4,9 +4,9 @@
|
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="act-bl">
|
7
|
-
<%%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id,
|
7
|
+
<%%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id, @<%= singular_name %>.id), :class=>"icons" %>
|
8
8
|
|
9
|
-
<%%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id,
|
9
|
+
<%%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id, @<%= singular_name %>.id), :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
|
10
10
|
</div>
|
11
11
|
</div>
|
12
12
|
|
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/functional_test.rb
RENAMED
File without changes
|
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/edit.html.erb
RENAMED
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/form.html.erb
RENAMED
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/index.html.erb
RENAMED
@@ -13,7 +13,7 @@
|
|
13
13
|
</div>
|
14
14
|
<div id="<%= plural_name %>" class="stage">
|
15
15
|
<%%= render :partial=>"manage/<%= plural_name %>/<%= singular_name %>", :collection=>@<%= plural_name %> %>
|
16
|
-
<%%= paginate @<%= plural_name
|
16
|
+
<%%= paginate @<%= plural_name %>, :theme => 'manage' %>
|
17
17
|
</div>
|
18
18
|
<script type='text/javascript'>
|
19
19
|
$(document).ready(function(){
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/item.html.erb
RENAMED
File without changes
|
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/new.html.erb
RENAMED
File without changes
|
data/lib/generators/{sunrise_scaffold → sunrise/scaffold}/templates/single/views/show.html.erb
RENAMED
@@ -4,9 +4,9 @@
|
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="act-bl">
|
7
|
-
<%%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_<%= singular_name %>_path(:id
|
7
|
+
<%%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_<%= singular_name %>_path(:id=>@<%= singular_name %>.id), :class=>"icons" %>
|
8
8
|
|
9
|
-
<%%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_<%= singular_name %>_path(:id
|
9
|
+
<%%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_<%= singular_name %>_path(:id=>@<%= singular_name %>.id), :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
|
10
10
|
</div>
|
11
11
|
</div>
|
12
12
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Sunrise
|
3
|
+
module Scaffold
|
4
|
+
class Utils
|
5
|
+
class << self
|
6
|
+
def parameterize_filename(filename)
|
7
|
+
extension = File.extname(filename)
|
8
|
+
basename = filename.gsub(/#{extension}$/, "")
|
9
|
+
|
10
|
+
[basename.parameterize('_'), extension].join.downcase
|
11
|
+
end
|
12
|
+
|
13
|
+
def form_field(form_name, field_name, column, options={})
|
14
|
+
field = case column.type
|
15
|
+
when :string, :binary, :integer, :float, :decimal then
|
16
|
+
options[:class] = "'text'"
|
17
|
+
"text_field"
|
18
|
+
when :boolean then "check_box"
|
19
|
+
when :datetime, :date, :timestamp, :time then
|
20
|
+
options[:extra_html] ||= "<script type='text/javascript'>
|
21
|
+
$(function() {
|
22
|
+
$('\##{form_name}_#{field_name}').datepicker({
|
23
|
+
numberOfMonths: 1,
|
24
|
+
dateFormat: 'dd.mm.yy'
|
25
|
+
});
|
26
|
+
});
|
27
|
+
</script>"
|
28
|
+
'text_field'
|
29
|
+
when :text then
|
30
|
+
options[:cols] ||= 70
|
31
|
+
options[:rows] ||= 5
|
32
|
+
"text_area"
|
33
|
+
end
|
34
|
+
|
35
|
+
extra_html = options.delete(:extra_html) || ''
|
36
|
+
|
37
|
+
options_fields = []
|
38
|
+
options.each { |k, v| options_fields << ":#{k}=>#{v}" }
|
39
|
+
|
40
|
+
options_str = ", {#{options_fields.join(', ')}}" unless options_fields.empty?
|
41
|
+
options_str ||= ''
|
42
|
+
|
43
|
+
"<%= #{form_name}.#{field} #{field_name}#{options_str} %>#{extra_html}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunrise-scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Galeta
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-07-22 00:00:00 +03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -27,35 +27,41 @@ executables: []
|
|
27
27
|
extensions: []
|
28
28
|
|
29
29
|
extra_rdoc_files:
|
30
|
+
- Gemfile.lock
|
31
|
+
- MIT-LICENSE
|
30
32
|
- README.rdoc
|
31
33
|
files:
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- MIT-LICENSE
|
32
37
|
- README.rdoc
|
33
38
|
- Rakefile
|
34
|
-
- lib/generators/
|
35
|
-
- lib/generators/
|
36
|
-
- lib/generators/
|
37
|
-
- lib/generators/
|
38
|
-
- lib/generators/
|
39
|
-
- lib/generators/
|
40
|
-
- lib/generators/
|
41
|
-
- lib/generators/
|
42
|
-
- lib/generators/
|
43
|
-
- lib/generators/
|
44
|
-
- lib/generators/
|
45
|
-
- lib/generators/
|
46
|
-
- lib/generators/
|
47
|
-
- lib/generators/
|
48
|
-
- lib/generators/
|
49
|
-
- lib/generators/
|
50
|
-
- lib/generators/
|
51
|
-
- lib/generators/
|
52
|
-
- lib/generators/
|
53
|
-
- lib/generators/
|
54
|
-
- lib/generators/
|
55
|
-
- lib/generators/
|
56
|
-
- lib/
|
57
|
-
- lib/
|
58
|
-
- lib/
|
39
|
+
- lib/generators/sunrise/scaffold/USAGE
|
40
|
+
- lib/generators/sunrise/scaffold/manage_generator.rb
|
41
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/controller.rb
|
42
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/functional_test.rb
|
43
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/helper.rb
|
44
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/edit.html.erb
|
45
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/form.html.erb
|
46
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/index.html.erb
|
47
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/item.html.erb
|
48
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/model_filter.html.erb
|
49
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/new.html.erb
|
50
|
+
- lib/generators/sunrise/scaffold/templates/multiplay/views/show.html.erb
|
51
|
+
- lib/generators/sunrise/scaffold/templates/single/controller.rb
|
52
|
+
- lib/generators/sunrise/scaffold/templates/single/functional_test.rb
|
53
|
+
- lib/generators/sunrise/scaffold/templates/single/helper.rb
|
54
|
+
- lib/generators/sunrise/scaffold/templates/single/views/edit.html.erb
|
55
|
+
- lib/generators/sunrise/scaffold/templates/single/views/form.html.erb
|
56
|
+
- lib/generators/sunrise/scaffold/templates/single/views/index.html.erb
|
57
|
+
- lib/generators/sunrise/scaffold/templates/single/views/item.html.erb
|
58
|
+
- lib/generators/sunrise/scaffold/templates/single/views/model_filter.html.erb
|
59
|
+
- lib/generators/sunrise/scaffold/templates/single/views/new.html.erb
|
60
|
+
- lib/generators/sunrise/scaffold/templates/single/views/show.html.erb
|
61
|
+
- lib/sunrise-scaffold.rb
|
62
|
+
- lib/sunrise/scaffold.rb
|
63
|
+
- lib/sunrise/scaffold/utils.rb
|
64
|
+
- lib/sunrise/scaffold/version.rb
|
59
65
|
has_rdoc: true
|
60
66
|
homepage: https://github.com/galetahub/sunrise-scaffold
|
61
67
|
licenses: []
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'sunrise_scaffold/utils'
|
3
|
-
|
4
|
-
module SunriseScaffold
|
5
|
-
class ManageGenerator < Rails::Generators::NamedBase
|
6
|
-
check_class_collision :suffix => "Controller"
|
7
|
-
|
8
|
-
class_option :parent, :type => :string, :default => nil,
|
9
|
-
:desc => "Parent model"
|
10
|
-
|
11
|
-
def self.source_root
|
12
|
-
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), "/templates"))
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_controller_files
|
16
|
-
template "#{generator_dir}/controller.rb",
|
17
|
-
File.join('app/controllers', manage_path, "#{controller_file_name}_controller.rb")
|
18
|
-
|
19
|
-
template "#{generator_dir}/helper.rb",
|
20
|
-
File.join('app/helpers', manage_path, "#{controller_file_name}_helper.rb")
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_tests_files
|
24
|
-
template "#{generator_dir}/functional_test.rb",
|
25
|
-
File.join('test/functional', manage_path, "#{controller_file_name}_controller_test.rb")
|
26
|
-
end
|
27
|
-
|
28
|
-
def create_views_files
|
29
|
-
# model form
|
30
|
-
template "#{generator_dir}/views/form.html.erb",
|
31
|
-
File.join('app/views', manage_path, controller_file_name, "_form.html.erb")
|
32
|
-
|
33
|
-
# search filter
|
34
|
-
template "#{generator_dir}/views/model_filter.html.erb",
|
35
|
-
File.join('app/views', manage_path, controller_file_name, "_model_filter.html.erb")
|
36
|
-
|
37
|
-
# collection view partial
|
38
|
-
template "#{generator_dir}/views/item.html.erb",
|
39
|
-
File.join('app/views', manage_path, controller_file_name, "_#{singular_name}.html.erb")
|
40
|
-
|
41
|
-
# other templates
|
42
|
-
[:index, :new, :edit, :show].each do |action|
|
43
|
-
template "#{generator_dir}/views/#{action}.html.erb",
|
44
|
-
File.join('app/views', manage_path, controller_file_name, "#{action}.html.erb")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
protected
|
49
|
-
|
50
|
-
def manage_path
|
51
|
-
"manage"
|
52
|
-
end
|
53
|
-
|
54
|
-
def klass
|
55
|
-
# First priority is the namespaced modek, e.g. User::Group
|
56
|
-
@klass ||= begin
|
57
|
-
namespaced_class = name.singularize
|
58
|
-
namespaced_class.constantize
|
59
|
-
rescue NameError
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
|
63
|
-
# Second priority the camelcased c, i.e. UserGroup
|
64
|
-
@klass ||= begin
|
65
|
-
camelcased_class = name.gsub('::', '').singularize
|
66
|
-
camelcased_class.constantize
|
67
|
-
rescue NameError
|
68
|
-
nil
|
69
|
-
end
|
70
|
-
|
71
|
-
@klass ||= model_name.constantize
|
72
|
-
|
73
|
-
@klass
|
74
|
-
end
|
75
|
-
|
76
|
-
def model
|
77
|
-
@model ||= klass.new
|
78
|
-
end
|
79
|
-
|
80
|
-
def model_name
|
81
|
-
@model_name ||= name.camelize
|
82
|
-
@model_name
|
83
|
-
end
|
84
|
-
|
85
|
-
def controller_class_name
|
86
|
-
@controller_class_name ||= name.pluralize.camelize
|
87
|
-
end
|
88
|
-
|
89
|
-
def controller_file_name
|
90
|
-
@controller_file_name ||= file_name.pluralize
|
91
|
-
end
|
92
|
-
|
93
|
-
def generator_dir
|
94
|
-
options[:parent] ? "multiplay" : "single"
|
95
|
-
end
|
96
|
-
|
97
|
-
def parent_class_name
|
98
|
-
@parent_class_name ||= parent_singular_name.camelize
|
99
|
-
@parent_class_name
|
100
|
-
end
|
101
|
-
|
102
|
-
def parent_singular_name
|
103
|
-
@parent_singular_name ||= options[:parent].singularize
|
104
|
-
@parent_singular_name
|
105
|
-
end
|
106
|
-
|
107
|
-
def translated_columns
|
108
|
-
@translated_columns ||= klass.translated_attribute_names if klass.respond_to?(:translated_attribute_names)
|
109
|
-
@translated_columns ||= []
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module SunriseScaffold
|
3
|
-
class Utils
|
4
|
-
class << self
|
5
|
-
def parameterize_filename(filename)
|
6
|
-
extension = File.extname(filename)
|
7
|
-
basename = filename.gsub(/#{extension}$/, "")
|
8
|
-
|
9
|
-
[basename.parameterize('_'), extension].join.downcase
|
10
|
-
end
|
11
|
-
|
12
|
-
def form_field(form_name, field_name, column, options={})
|
13
|
-
field = case column.type
|
14
|
-
when :string, :binary, :integer, :float, :decimal then
|
15
|
-
options[:class] = "'text'"
|
16
|
-
"text_field"
|
17
|
-
when :boolean then "check_box"
|
18
|
-
when :datetime, :date, :timestamp, :time then
|
19
|
-
options[:extra_html] ||= "<script type='text/javascript'>
|
20
|
-
$(function() {
|
21
|
-
$('\##{form_name}_#{field_name}').datepicker({
|
22
|
-
numberOfMonths: 1,
|
23
|
-
dateFormat: 'dd.mm.yy'
|
24
|
-
});
|
25
|
-
});
|
26
|
-
</script>"
|
27
|
-
'text_field'
|
28
|
-
when :text then
|
29
|
-
options[:cols] ||= 70
|
30
|
-
options[:rows] ||= 5
|
31
|
-
"text_area"
|
32
|
-
end
|
33
|
-
|
34
|
-
extra_html = options.delete(:extra_html) || ''
|
35
|
-
|
36
|
-
options_fields = []
|
37
|
-
options.each { |k, v| options_fields << ":#{k}=>#{v}" }
|
38
|
-
|
39
|
-
options_str = ", {#{options_fields.join(', ')}}" unless options_fields.empty?
|
40
|
-
options_str ||= ''
|
41
|
-
|
42
|
-
"<%= #{form_name}.#{field} #{field_name}#{options_str} %>#{extra_html}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|