beautiful_scaffold 0.3.0.pre → 0.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/README.rdoc +13 -7
- data/beautiful_scaffold.gemspec +1 -1
- data/lib/generators/beautiful_locale_generator.rb +3 -1
- data/lib/generators/beautiful_migration_generator.rb +0 -2
- data/lib/generators/beautiful_scaffold_common_methods.rb +15 -0
- data/lib/generators/beautiful_scaffold_generator.rb +11 -10
- data/lib/generators/templates/app/controllers/base.rb +6 -2
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
* Update prawn version 1.0.0.rc2
|
12
12
|
* Big refactoring with javascript
|
13
13
|
* Using twitter-bootstrap-rails with turbolinks compatibility and last version of bootstrap and fontawesome
|
14
|
+
* Generate locale file with auto translation
|
14
15
|
|
15
16
|
* Bugfix
|
16
17
|
* Avoid to re-generate created_at, updated_at, id search field at each migration
|
data/README.rdoc
CHANGED
@@ -15,7 +15,7 @@ gem 'beautiful_scaffold', '0.2.7'
|
|
15
15
|
=== RubyOnRails 4.X
|
16
16
|
|
17
17
|
Add this in your Gemfile :
|
18
|
-
gem 'beautiful_scaffold', '0.3.0'
|
18
|
+
gem 'beautiful_scaffold', '0.3.0.rc1'
|
19
19
|
|
20
20
|
=== Next
|
21
21
|
|
@@ -39,19 +39,25 @@ type available :
|
|
39
39
|
* wysiwyg
|
40
40
|
|
41
41
|
# Example : products
|
42
|
-
rails
|
42
|
+
rails g beautiful_scaffold product name:string price:price tva:float description:richtext visible:boolean && rake db:migrate
|
43
43
|
|
44
44
|
# Example : admin products
|
45
|
-
rails
|
45
|
+
rails g beautiful_scaffold product name:string price:price tva:float description:richtext overview_description:richtext visible:boolean --namespace=admin && rake db:migrate
|
46
46
|
|
47
|
-
===
|
47
|
+
=== Migration (Use Add[Field]To[ModelPluralize] syntax)
|
48
48
|
|
49
|
-
rails
|
49
|
+
rails g beautiful_migration AddFieldToModels field:type
|
50
|
+
|
51
|
+
=== Locale (i18n) (Example)
|
52
|
+
|
53
|
+
rails g beautiful_locale all
|
54
|
+
rails g beautiful_locale fr
|
55
|
+
rails g beautiful_locale de
|
50
56
|
|
51
57
|
=== Join Table (has_and_belongs_to_many relation)
|
52
58
|
|
53
|
-
rails
|
59
|
+
rails g beautiful_jointable model1 model2
|
54
60
|
|
55
61
|
=== Install et Configure Devise (authentification) and Cancan (authorization)
|
56
62
|
|
57
|
-
rails
|
63
|
+
rails g beautiful_devisecancan model
|
data/beautiful_scaffold.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "beautiful_scaffold"
|
6
|
-
s.version = "0.3.0.
|
6
|
+
s.version = "0.3.0.rc1"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.summary = "Beautiful Scaffold generate fully customizable scaffold"
|
9
9
|
s.email = "claudel.sylvain@gmail.com"
|
@@ -60,7 +60,7 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
60
60
|
|
61
61
|
Dir.glob("app/models/**/*").each { |model_file|
|
62
62
|
puts model_file
|
63
|
-
next if File.directory?(model_file)
|
63
|
+
next if File.directory?(model_file) or File.basename(model_file).first == '.'
|
64
64
|
model = File.basename(model_file, File.extname(model_file))
|
65
65
|
klass = model.camelize.constantize
|
66
66
|
|
@@ -105,6 +105,8 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
105
105
|
file.close
|
106
106
|
end
|
107
107
|
|
108
|
+
private
|
109
|
+
|
108
110
|
def translate_string(locale, str)
|
109
111
|
# See http://www.microsofttranslator.com/dev/
|
110
112
|
#
|
@@ -39,10 +39,8 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
39
39
|
if ['references', 'reference'].include?(t) then
|
40
40
|
inject_into_file("app/models/#{model}.rb", "\n belongs_to :#{a}", :after => "ActiveRecord::Base")
|
41
41
|
inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ActiveRecord::Base")
|
42
|
-
inject_into_file("app/models/#{a}.rb", ":#{model}_ids, ", :after => "attr_accessible ")
|
43
42
|
a += "_id"
|
44
43
|
end
|
45
|
-
inject_into_file("app/models/#{model}.rb", ":#{a}, ", :after => "attr_accessible ")
|
46
44
|
}
|
47
45
|
end
|
48
46
|
|
@@ -124,6 +124,21 @@ module BeautifulScaffoldCommonMethods
|
|
124
124
|
return newmyattributes
|
125
125
|
end
|
126
126
|
|
127
|
+
def attributes_without_type
|
128
|
+
newmyattributes = []
|
129
|
+
myattributes.each{ |attr|
|
130
|
+
a,t = attr.split(':')
|
131
|
+
|
132
|
+
if ['references', 'reference'].include?(t) then
|
133
|
+
a = a + '_id'
|
134
|
+
end
|
135
|
+
|
136
|
+
newmyattributes << a
|
137
|
+
}
|
138
|
+
|
139
|
+
return newmyattributes
|
140
|
+
end
|
141
|
+
|
127
142
|
def fulltext_attribute
|
128
143
|
fulltext_field = []
|
129
144
|
myattributes.each{ |attr|
|
@@ -132,19 +132,22 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
132
132
|
|
133
133
|
order("#{attribute} #{direction}")
|
134
134
|
}
|
135
|
-
# You can OVERRIDE this method used in model form and search form (in belongs_to relation)
|
136
|
-
def caption
|
137
|
-
(self["name"] || self["label"] || self["description"] || "##{id}")
|
138
|
-
end', :after => "class #{model_camelize} < ActiveRecord::Base")
|
139
|
-
|
140
|
-
inject_into_file("app/models/#{model}.rb",'
|
141
|
-
include BeautifulScaffoldModule
|
142
135
|
|
136
|
+
include BeautifulScaffoldModule
|
143
137
|
before_save :fulltext_field_processing
|
144
138
|
|
139
|
+
# You can OVERRIDE this method used in model form and search form (in belongs_to relation)
|
140
|
+
def caption
|
141
|
+
(self["name"] || self["label"] || self["description"] || "##{id}")
|
142
|
+
end
|
143
|
+
|
145
144
|
def fulltext_field_processing
|
146
145
|
# You can preparse with own things here
|
147
146
|
generate_fulltext_field([' + fulltext_attribute.map{ |e| ('"' + e + '"') }.join(",") + '])
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.permitted_attributes
|
150
|
+
return ' + attributes_without_type.map{ |attr| ":#{attr}" }.join(",") + '
|
148
151
|
end', :after => "class #{model_camelize} < ActiveRecord::Base")
|
149
152
|
|
150
153
|
inject_into_file("config/application.rb", ' config.autoload_paths += %W(#{config.root}/app/modules)' + "\n", :after => "< Rails::Application\n")
|
@@ -154,14 +157,12 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
|
|
154
157
|
end
|
155
158
|
|
156
159
|
def add_to_model
|
157
|
-
# Add relation
|
160
|
+
# Add relation
|
158
161
|
myattributes.each{ |attr|
|
159
162
|
a,t = attr.split(':')
|
160
163
|
if ['references', 'reference'].include?(t) then
|
161
|
-
inject_into_file("app/models/#{model}.rb", ":#{a}_id, ", :after => "attr_accessible ")
|
162
164
|
begin
|
163
165
|
inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ActiveRecord::Base")
|
164
|
-
inject_into_file("app/models/#{a}.rb", ":#{model}_ids, ", :after => "attr_accessible ")
|
165
166
|
rescue
|
166
167
|
end
|
167
168
|
end
|
@@ -97,7 +97,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def create
|
100
|
-
@<%= model %> = <%= model_camelize %>.create(
|
100
|
+
@<%= model %> = <%= model_camelize %>.create(params_for_model)
|
101
101
|
|
102
102
|
respond_to do |format|
|
103
103
|
if @<%= model %>.save
|
@@ -125,7 +125,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
125
125
|
def update
|
126
126
|
|
127
127
|
respond_to do |format|
|
128
|
-
if @<%= model %>.update_attributes(
|
128
|
+
if @<%= model %>.update_attributes(params_for_model)
|
129
129
|
format.html { redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :notice => t(:update_success, :model => "<%= model %>") }
|
130
130
|
format.json { head :ok }
|
131
131
|
else
|
@@ -199,5 +199,9 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
199
199
|
def load_<%= model %>
|
200
200
|
@<%= model %> = <%= model_camelize %>.find(params[:id])
|
201
201
|
end
|
202
|
+
|
203
|
+
def params_for_model
|
204
|
+
params.require(:<%= model %>).permit(<%= model_camelize %>.permitted_attributes)
|
205
|
+
end
|
202
206
|
end
|
203
207
|
|