refinerycms-core 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/refinery/admin.js.erb +28 -33
- data/app/assets/javascripts/refinery/modal_dialogs.js.erb +29 -31
- data/app/assets/javascripts/refinery/submit_continue.js.coffee.erb +1 -0
- data/app/assets/javascripts/wymeditor/lang/nl.js +55 -45
- data/app/assets/javascripts/wymeditor/lang/pl.js +12 -1
- data/app/controllers/refinery/admin/core_controller.rb +1 -1
- data/app/controllers/refinery/admin/dialogs_controller.rb +25 -9
- data/app/views/refinery/admin/_form_actions.html.erb +3 -1
- data/lib/generators/refinery/dummy/dummy_generator.rb +2 -2
- data/lib/generators/refinery/dummy/templates/rails/{application.rb → application.rb.erb} +0 -0
- data/lib/generators/refinery/dummy/templates/rails/{boot.rb → boot.rb.erb} +0 -0
- data/lib/generators/refinery/engine/engine_generator.rb +5 -1
- data/lib/generators/refinery/engine/templates/app/controllers/refinery/namespace/admin/{plural_name_controller.rb → plural_name_controller.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/app/controllers/refinery/namespace/{plural_name_controller.rb → plural_name_controller.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/app/models/refinery/namespace/{singular_name.rb → singular_name.rb.erb} +7 -9
- data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_singular_name.html.erb +1 -1
- data/lib/generators/refinery/engine/templates/config/locales/sk.yml +28 -0
- data/lib/generators/refinery/engine/templates/config/{routes.rb → routes.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/db/migrate/{1_create_namespace_plural_name.rb → 1_create_namespace_plural_name.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/db/{seeds.rb → seeds.rb.erb} +1 -1
- data/lib/generators/refinery/engine/templates/lib/generators/refinery/{extension_plural_name_generator.rb → extension_plural_name_generator.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/lib/refinery/{plural_name.rb → plural_name.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/lib/refinery/plural_name/{engine.rb → engine.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/lib/{refinerycms-extension_plural_name.rb → refinerycms-extension_plural_name.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/spec/models/refinery/namespace/{singular_name_spec.rb → singular_name_spec.rb.erb} +0 -0
- data/lib/generators/refinery/engine/templates/spec/requests/refinery/namespace/admin/{plural_name_spec.rb → plural_name_spec.rb.erb} +6 -6
- data/lib/generators/refinery/engine/templates/spec/spec_helper.rb +0 -2
- data/lib/generators/refinery/engine/templates/spec/support/factories/refinery/{plural_name.rb → plural_name.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/app/controllers/refinery/namespace/admin/{plural_name_controller.rb → plural_name_controller.rb.erb} +4 -4
- data/lib/generators/refinery/form/templates/app/controllers/refinery/namespace/admin/settings_controller.rb.erb +45 -0
- data/lib/generators/refinery/form/templates/app/controllers/refinery/namespace/{plural_name_controller.rb → plural_name_controller.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/app/mailers/refinery/namespace/{mailer.rb → mailer.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/app/models/refinery/namespace/{setting.rb → setting.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/app/models/refinery/namespace/{singular_name.rb → singular_name.rb.erb} +19 -14
- data/lib/generators/refinery/form/templates/app/views/refinery/namespace/admin/plural_name/_singular_name.html.erb +1 -1
- data/lib/generators/refinery/form/templates/app/views/refinery/namespace/admin/settings/_confirmation_email_form.html.erb +1 -1
- data/lib/generators/refinery/form/templates/app/views/refinery/namespace/admin/settings/_notification_recipients_form.html.erb +1 -1
- data/lib/generators/refinery/form/templates/app/views/refinery/namespace/plural_name/new.html.erb +4 -4
- data/lib/generators/refinery/form/templates/config/locales/cs.yml +78 -0
- data/lib/generators/refinery/form/templates/config/locales/sk.yml +78 -0
- data/lib/generators/refinery/form/templates/config/{routes.rb → routes.rb.erb} +2 -2
- data/lib/generators/refinery/form/templates/db/migrate/{1_create_plural_name.rb → 1_create_plural_name.rb.erb} +5 -4
- data/lib/generators/refinery/form/templates/db/{seeds.rb → seeds.rb.erb} +1 -1
- data/lib/generators/refinery/form/templates/lib/generators/refinery/{plural_name_generator.rb → plural_name_generator.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/lib/refinery/{plural_name.rb → plural_name.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/lib/refinery/plural_name/{engine.rb → engine.rb.erb} +0 -0
- data/lib/generators/refinery/form/templates/lib/{refinerycms-plural_name.rb → refinerycms-plural_name.rb.erb} +0 -0
- data/lib/refinery/cli.rb +73 -111
- data/lib/refinery/core.rb +8 -4
- data/lib/refinery/crud.rb +9 -5
- data/lib/refinery/extension_generation.rb +250 -214
- data/lib/refinery/version.rb +2 -2
- data/spec/helpers/refinery/custom_assets_helper_spec.rb +2 -2
- data/spec/helpers/refinery/pagination_helper_spec.rb +1 -1
- data/spec/lib/generators/refinery/cms/cms_generator_spec.rb +1 -1
- data/spec/lib/generators/refinery/core/core_generator_spec.rb +1 -1
- data/spec/lib/generators/refinery/engine/engine_generator_spec.rb +9 -4
- data/spec/lib/generators/refinery/engine/engine_generator_with_i18n_spec.rb +1 -1
- data/spec/lib/generators/refinery/engine/engine_generator_without_frontend_spec.rb +1 -1
- data/spec/lib/generators/refinery/form/form_generator_spec.rb +1 -1
- data/spec/lib/refinery/application_controller_spec.rb +8 -0
- data/spec/lib/refinery/core_spec.rb +14 -5
- data/spec/lib/refinery/crud_spec.rb +106 -0
- data/spec/lib/refinery/plugin_spec.rb +1 -1
- data/spec/lib/refinery/plugins_spec.rb +1 -1
- data/spec/requests/refinery/admin/custom_assets_spec.rb +2 -2
- data/spec/requests/refinery/admin/dialogs_spec.rb +3 -2
- data/spec/requests/refinery/search_spec.rb +2 -2
- data/spec/support/database_cleaner.rb +8 -2
- data/spec/support/refinery.rb +1 -2
- metadata +37 -32
- data/lib/generators/refinery/form/templates/app/controllers/refinery/namespace/admin/settings_controller.rb +0 -51
@@ -1,4 +1,4 @@
|
|
1
|
-
Refinery::Core::Engine.routes.
|
1
|
+
Refinery::Core::Engine.routes.draw do
|
2
2
|
# Frontend routes
|
3
3
|
namespace :<%= namespacing.underscore %> do
|
4
4
|
resources :<%= plural_name %><%= ", :path => ''" if namespacing.underscore == plural_name %>, :only => [:new, :create] do
|
@@ -19,7 +19,7 @@ Refinery::Core::Engine.routes.append do
|
|
19
19
|
get :toggle_spam
|
20
20
|
end
|
21
21
|
end<% end %>
|
22
|
-
resources :settings
|
22
|
+
resources :settings, :only => [:edit, :update]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -5,12 +5,13 @@ class Create<%= class_name.pluralize %> < ActiveRecord::Migration
|
|
5
5
|
<%
|
6
6
|
attributes.each do |attribute|
|
7
7
|
# turn image or resource into what it was supposed to be which is an integer reference to an image or resource.
|
8
|
-
|
8
|
+
case attribute.type
|
9
|
+
when :image, :resource
|
9
10
|
attribute.type = 'integer'
|
10
|
-
attribute.name = "#{attribute.name}_id"
|
11
|
-
|
11
|
+
attribute.name = "#{attribute.name}_id"
|
12
|
+
when :radio, :select
|
12
13
|
attribute.type = 'string'
|
13
|
-
|
14
|
+
when :checkbox
|
14
15
|
attribute.type = 'boolean'
|
15
16
|
end
|
16
17
|
-%>
|
File without changes
|
data/lib/generators/refinery/form/templates/lib/refinery/{plural_name.rb → plural_name.rb.erb}
RENAMED
File without changes
|
data/lib/generators/refinery/form/templates/lib/refinery/plural_name/{engine.rb → engine.rb.erb}
RENAMED
File without changes
|
File without changes
|
data/lib/refinery/cli.rb
CHANGED
@@ -4,123 +4,60 @@ module Refinery
|
|
4
4
|
class CLI < Thor
|
5
5
|
include Thor::Actions
|
6
6
|
|
7
|
+
OVERRIDES = {
|
8
|
+
:view => {
|
9
|
+
:glob => '*.{erb,builder}',
|
10
|
+
:dir => 'views',
|
11
|
+
:desc => 'view template',
|
12
|
+
},
|
13
|
+
:controller => {
|
14
|
+
:glob => '*.rb',
|
15
|
+
:dir => 'controllers',
|
16
|
+
:desc => 'controller',
|
17
|
+
},
|
18
|
+
:model => {
|
19
|
+
:glob => '*.rb',
|
20
|
+
:dir => 'models',
|
21
|
+
:desc => 'model',
|
22
|
+
},
|
23
|
+
:presenter => {
|
24
|
+
:glob => '*.rb',
|
25
|
+
:dir => 'presenters',
|
26
|
+
:desc => 'presenter',
|
27
|
+
},
|
28
|
+
:javascript => {
|
29
|
+
:glob => '*.js{,.*}',
|
30
|
+
:dir => 'assets/javascripts',
|
31
|
+
:desc => 'javascript',
|
32
|
+
},
|
33
|
+
:stylesheet => {
|
34
|
+
:glob => '*.css.scss',
|
35
|
+
:dir => 'assets/stylesheets',
|
36
|
+
:desc => 'stylesheet',
|
37
|
+
},
|
38
|
+
}
|
39
|
+
|
7
40
|
desc "override", "copies files from any Refinery extension that you are using into your application"
|
8
41
|
def override(env)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# copy in the matches
|
14
|
-
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
|
15
|
-
matches.each do |match|
|
16
|
-
dir = match.split("/app/views/").last.split('/')
|
17
|
-
file = dir.pop # get rid of the file.
|
18
|
-
dir = dir.join(File::SEPARATOR) # join directory back together
|
19
|
-
|
20
|
-
destination_dir = Rails.root.join("app", "views", dir)
|
21
|
-
FileUtils.mkdir_p(destination_dir)
|
22
|
-
FileUtils.cp match, (destination = File.join(destination_dir, file))
|
23
|
-
|
24
|
-
puts "Copied view template file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
|
25
|
-
end
|
26
|
-
else
|
27
|
-
puts "Couldn't match any view template files in any extensions like #{view}"
|
28
|
-
end
|
29
|
-
elsif (controller = env["controller"]).present?
|
30
|
-
pattern = "{refinery#{File::SEPARATOR},}#{controller.split("/").join(File::SEPARATOR)}*.rb"
|
31
|
-
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "controllers", pattern).to_s}
|
32
|
-
|
33
|
-
# copy in the matches
|
34
|
-
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
|
35
|
-
matches.each do |match|
|
36
|
-
dir = match.split("/app/controllers/").last.split('/')
|
37
|
-
file = dir.pop # get rid of the file.
|
38
|
-
dir = dir.join(File::SEPARATOR) # join directory back together
|
39
|
-
|
40
|
-
destination_dir = Rails.root.join("app", "controllers", dir)
|
41
|
-
FileUtils.mkdir_p(destination_dir)
|
42
|
-
FileUtils.cp match, (destination = File.join(destination_dir, file))
|
43
|
-
|
44
|
-
puts "Copied controller file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
|
45
|
-
end
|
46
|
-
else
|
47
|
-
puts "Couldn't match any controller files in any extensions like #{controller}"
|
48
|
-
end
|
49
|
-
elsif (model = env["model"]).present?
|
50
|
-
pattern = "{refinery#{File::SEPARATOR},}#{model.split("/").join(File::SEPARATOR)}*.rb"
|
51
|
-
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "models", pattern).to_s}
|
52
|
-
|
53
|
-
# copy in the matches
|
54
|
-
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
|
55
|
-
matches.each do |match|
|
56
|
-
dir = match.split("/app/models/").last.split('/')
|
57
|
-
file = dir.pop # get rid of the file.
|
58
|
-
dir = dir.join(File::SEPARATOR) # join directory back together
|
59
|
-
|
60
|
-
destination_dir = Rails.root.join("app", "models", dir)
|
61
|
-
FileUtils.mkdir_p(destination_dir)
|
62
|
-
FileUtils.cp match, (destination = File.join(destination_dir, file))
|
63
|
-
|
64
|
-
puts "Copied model file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
|
65
|
-
end
|
66
|
-
else
|
67
|
-
puts "Couldn't match any model files in any extensions like #{model}"
|
68
|
-
end
|
69
|
-
elsif (javascripts = env["javascript"]).present?
|
70
|
-
pattern = "#{javascripts.split("/").join(File::SEPARATOR)}*.js{,.*}"
|
71
|
-
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "assets", "javascripts", pattern).to_s}
|
72
|
-
|
73
|
-
# copy in the matches
|
74
|
-
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
|
75
|
-
matches.each do |match|
|
76
|
-
dir = match.split("/app/assets/javascripts/").last.split('/')
|
77
|
-
file = dir.pop # get rid of the file.
|
78
|
-
dir = dir.join(File::SEPARATOR) # join directory back together
|
79
|
-
|
80
|
-
destination_dir = Rails.root.join("app", "assets", "javascripts", dir)
|
81
|
-
FileUtils.mkdir_p(destination_dir)
|
82
|
-
FileUtils.cp match, (destination = File.join(destination_dir, file))
|
83
|
-
|
84
|
-
puts "Copied javascript file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
|
85
|
-
end
|
86
|
-
else
|
87
|
-
puts "Couldn't match any javascript files in any extensions like #{javascripts}"
|
42
|
+
OVERRIDES.keys.each do |kind|
|
43
|
+
if (which = env[kind.to_s]).present?
|
44
|
+
return _override(kind, which)
|
88
45
|
end
|
89
|
-
|
90
|
-
pattern = "#{stylesheets.split("/").join(File::SEPARATOR)}*.css.scss"
|
91
|
-
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "assets", "stylesheets", pattern).to_s}
|
92
|
-
|
93
|
-
# copy in the matches
|
94
|
-
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
|
95
|
-
matches.each do |match|
|
96
|
-
dir = match.split("/app/assets/stylesheets/").last.split('/')
|
97
|
-
file = dir.pop # get rid of the file.
|
98
|
-
dir = dir.join(File::SEPARATOR) # join directory back together
|
99
|
-
|
100
|
-
destination_dir = Rails.root.join("app", "assets", "stylesheets", dir)
|
101
|
-
FileUtils.mkdir_p(destination_dir)
|
102
|
-
FileUtils.cp match, (destination = File.join(destination_dir, file))
|
46
|
+
end
|
103
47
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
:controller => %w(pages),
|
116
|
-
:model => %w(page refinery/page)
|
117
|
-
}.each do |type, examples|
|
118
|
-
examples.each do |example|
|
119
|
-
puts "rake refinery:override #{type}=#{example}"
|
120
|
-
end
|
48
|
+
puts "You didn't specify anything valid to override. Here are some examples:"
|
49
|
+
{
|
50
|
+
:view => ['pages/home', 'refinery/pages/home', '**/*menu', '_menu_branch'],
|
51
|
+
:javascript => %w(admin refinery/site_bar),
|
52
|
+
:stylesheet => %w(home refinery/site_bar),
|
53
|
+
:controller => %w(pages),
|
54
|
+
:model => %w(page refinery/page),
|
55
|
+
:presenter => %w(refinery/page_presenter)
|
56
|
+
}.each do |type, examples|
|
57
|
+
examples.each do |example|
|
58
|
+
puts "rake refinery:override #{type}=#{example}"
|
121
59
|
end
|
122
60
|
end
|
123
|
-
|
124
61
|
end
|
125
62
|
|
126
63
|
desc "uncrudify", "shows you the code that your controller using crudify is running for a given action"
|
@@ -158,5 +95,30 @@ module Refinery
|
|
158
95
|
puts crud_method
|
159
96
|
end
|
160
97
|
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def _override(kind, which)
|
102
|
+
override_kind = OVERRIDES[kind]
|
103
|
+
pattern = "{refinery#{File::SEPARATOR},}#{which.split("/").join(File::SEPARATOR)}#{override_kind[:glob]}"
|
104
|
+
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", override_kind[:dir], pattern).to_s}
|
105
|
+
|
106
|
+
# copy in the matches
|
107
|
+
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
|
108
|
+
matches.each do |match|
|
109
|
+
dir = match.split("/app/#{override_kind[:dir]}/").last.split('/')
|
110
|
+
file = dir.pop # get rid of the file.
|
111
|
+
dir = dir.join(File::SEPARATOR) # join directory back together
|
112
|
+
|
113
|
+
destination_dir = Rails.root.join('app', override_kind[:dir], dir)
|
114
|
+
FileUtils.mkdir_p(destination_dir)
|
115
|
+
FileUtils.cp match, (destination = File.join(destination_dir, file))
|
116
|
+
|
117
|
+
puts "Copied #{override_kind[:desc]} file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
|
118
|
+
end
|
119
|
+
else
|
120
|
+
puts "Couldn't match any #{override_kind[:desc]} files in any extensions like #{which}"
|
121
|
+
end
|
122
|
+
end
|
161
123
|
end
|
162
124
|
end
|
data/lib/refinery/core.rb
CHANGED
@@ -128,7 +128,7 @@ module Refinery
|
|
128
128
|
# Refinery.roots(:'refinery/core') => #<Pathname:/Users/Reset/Code/refinerycms/core>
|
129
129
|
# Refinery.roots("refinery/core") => #<Pathname:/Users/Reset/Code/refinerycms/core>
|
130
130
|
def roots(extension_name = nil)
|
131
|
-
return @roots ||= self.extensions.map
|
131
|
+
return @roots ||= self.extensions.map(&:root) if extension_name.nil?
|
132
132
|
|
133
133
|
extension_name.to_s.camelize.constantize.root
|
134
134
|
end
|
@@ -157,13 +157,17 @@ module Refinery
|
|
157
157
|
options = {:plural => false, :admin => true}.merge options
|
158
158
|
|
159
159
|
klass = klass.constantize if klass.respond_to?(:constantize)
|
160
|
-
active_name = ActiveModel::Name.new
|
160
|
+
active_name = ActiveModel::Name.new klass, (Refinery if klass.parents.include?(Refinery))
|
161
161
|
|
162
162
|
if options[:admin]
|
163
163
|
# Most of the time this gets rid of 'refinery'
|
164
|
-
parts = active_name.underscore.split('/').reject{|name|
|
164
|
+
parts = active_name.underscore.split('/').reject{|name|
|
165
|
+
active_name.singular_route_key.exclude?(name)
|
166
|
+
}
|
167
|
+
|
168
|
+
# Get the singular resource_name from the url parts
|
165
169
|
resource_name = parts.pop
|
166
|
-
resource_name = options[:plural]
|
170
|
+
resource_name = resource_name.pluralize if options[:plural]
|
167
171
|
|
168
172
|
[parts.join("_"), "admin", resource_name, "path"].reject(&:blank?).join "_"
|
169
173
|
else
|
data/lib/refinery/crud.rb
CHANGED
@@ -266,8 +266,11 @@ module Refinery
|
|
266
266
|
def update_positions
|
267
267
|
previous = nil
|
268
268
|
params[:ul].each do |_, list|
|
269
|
-
|
270
|
-
|
269
|
+
# After we drop Ruby 1.8.x support the following line can be changed back to
|
270
|
+
# list.each do |index, hash|
|
271
|
+
# because there won't be an ordering issue (see https://github.com/resolve/refinerycms/issues/1585)
|
272
|
+
list.sort.map { |item| item[1] }.each_with_index do |hash, index|
|
273
|
+
moved_item_id = hash['id'].split(/#{singular_name}\_?/).reject(&:empty?).first
|
271
274
|
@current_#{singular_name} = #{class_name}.find_by_id(moved_item_id)
|
272
275
|
|
273
276
|
if @current_#{singular_name}.respond_to?(:move_to_root)
|
@@ -277,7 +280,7 @@ module Refinery
|
|
277
280
|
@current_#{singular_name}.move_to_root
|
278
281
|
end
|
279
282
|
else
|
280
|
-
@current_#{singular_name}.
|
283
|
+
@current_#{singular_name}.update_attributes :position => index
|
281
284
|
end
|
282
285
|
|
283
286
|
if hash['children'].present?
|
@@ -293,8 +296,9 @@ module Refinery
|
|
293
296
|
end
|
294
297
|
|
295
298
|
def update_child_positions(_node, #{singular_name})
|
296
|
-
_node['children']['0']
|
297
|
-
|
299
|
+
list = _node['children']['0']
|
300
|
+
list.sort.map { |item| item[1] }.each_with_index do |child, index|
|
301
|
+
child_id = child['id'].split(/#{singular_name}\_?/).reject(&:empty?).first
|
298
302
|
child_#{singular_name} = #{class_name}.where(:id => child_id).first
|
299
303
|
child_#{singular_name}.move_to_child_of(#{singular_name})
|
300
304
|
|
@@ -10,271 +10,307 @@ module Refinery
|
|
10
10
|
class_option :i18n, :type => :array, :default => [], :required => false, :banner => "field field", :desc => 'Indicates generated fields'
|
11
11
|
|
12
12
|
remove_class_option :skip_namespace
|
13
|
+
end
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def namespacing
|
17
|
+
@namespacing ||= if options[:namespace].present?
|
18
|
+
# Use exactly what the user requested, not a pluralised version.
|
19
|
+
options[:namespace].to_s.camelize
|
20
|
+
else
|
21
|
+
class_name.pluralize
|
22
|
+
end
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
options[:extension].to_s
|
27
|
-
else
|
28
|
-
singular_name
|
29
|
-
end
|
30
|
-
end
|
25
|
+
def extension_name
|
26
|
+
@extension_name ||= options[:extension].presence || singular_name
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def extension_class_name
|
30
|
+
@extension_class_name ||= extension_name.camelize
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
def extension_plural_class_name
|
34
|
+
@extension_plural_class_name ||= if options[:extension].present?
|
35
|
+
# Use exactly what the user requested, not a plural version.
|
36
|
+
extension_class_name
|
37
|
+
else
|
38
|
+
extension_class_name.pluralize
|
39
|
+
end
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
def extension_plural_name
|
43
|
+
@extension_plural_name ||= if options[:extension].present?
|
44
|
+
# Use exactly what the user requested, not a plural version.
|
45
|
+
extension_name
|
46
|
+
else
|
47
|
+
extension_name.pluralize
|
48
|
+
end
|
49
|
+
end
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def localized?
|
52
|
+
localized_attributes.any?
|
53
|
+
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
def localized_attributes
|
56
|
+
@localized_attributes ||= attributes.select{|a| options[:i18n].include?(a.name)}
|
57
|
+
end
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
def attributes_for_translation_table
|
60
|
+
localized_attributes.inject([]) {|memo, attr| memo << ":#{attr.name} => :#{attr.type}"}.join(', ')
|
61
|
+
end
|
65
62
|
|
66
|
-
|
63
|
+
def string_attributes
|
64
|
+
@string_attributes ||= attributes.select {|a| /string|text/ === a.type.to_s}.uniq
|
65
|
+
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
append_file gemfile, "\ngem '#{gem_name}', :path => '#{path}'"
|
72
|
-
end
|
73
|
-
end
|
67
|
+
def image_attributes
|
68
|
+
@image_attributes ||= attributes.select { |a| a.type == :image }.uniq
|
69
|
+
end
|
74
70
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
unless (clash_file = source_pathname.parent.join('clash_keywords.yml')).file?
|
79
|
-
clash_file = source_pathname.parent.parent.join('clash_keywords.yml')
|
80
|
-
end
|
81
|
-
clash_keywords = YAML.load_file(clash_file) if clash_file.file?
|
82
|
-
clash_keywords
|
83
|
-
end
|
84
|
-
end
|
71
|
+
def resource_attributes
|
72
|
+
@resource_attributes ||= attributes.select { |a| a.type == :resource }.uniq
|
73
|
+
end
|
85
74
|
|
86
|
-
|
87
|
-
|
75
|
+
def names_for_attr_accessible
|
76
|
+
@attributes_for_attr_accessible ||= attributes.map do |a|
|
77
|
+
case a.type
|
78
|
+
when :image, :resource
|
79
|
+
"#{a.name}_id" unless a.name[-3..-1] == "_id"
|
80
|
+
else
|
81
|
+
a.name
|
88
82
|
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
89
87
|
|
90
|
-
|
91
|
-
|
88
|
+
def append_extension_to_gemfile!
|
89
|
+
unless Rails.env.test? || (self.behavior != :revoke && extension_in_gemfile?)
|
90
|
+
path = extension_pathname.parent.relative_path_from(gemfile.parent)
|
91
|
+
append_file gemfile, "\ngem '#{gem_name}', :path => '#{path}'"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def clash_keywords
|
96
|
+
@clash_keywords ||= begin
|
97
|
+
clash_keywords = []
|
98
|
+
unless (clash_file = source_pathname.parent.join('clash_keywords.yml')).file?
|
99
|
+
clash_file = source_pathname.parent.parent.join('clash_keywords.yml')
|
92
100
|
end
|
101
|
+
clash_keywords = YAML.load_file(clash_file) if clash_file.file?
|
102
|
+
clash_keywords
|
103
|
+
end
|
104
|
+
end
|
93
105
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
path.gsub!('extension_plural_name', extension_plural_name)
|
98
|
-
path.gsub!('plural_name', plural_name)
|
99
|
-
path.gsub!('singular_name', singular_name)
|
100
|
-
path.gsub!('namespace', namespacing.underscore)
|
101
|
-
|
102
|
-
if options[:namespace].present? || options[:extension].present?
|
103
|
-
# Increment the migration file leading number
|
104
|
-
# Only relevant for nested or namespaced extensions, where a previous migration exists
|
105
|
-
if path =~ %r{/migrate/\d+\w*.rb\z}
|
106
|
-
if last_migration = Dir["#{destination_pathname.join(path.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR), '*.rb')}"].sort.last
|
107
|
-
path.gsub!(%r{\d+_}) { |m| "#{last_migration.match(%r{migrate/(\d+)_})[1].to_i + 1}_" }
|
108
|
-
end
|
109
|
-
end
|
106
|
+
def destination_pathname
|
107
|
+
@destination_pathname ||= Pathname.new(self.destination_root.to_s)
|
108
|
+
end
|
110
109
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
path = if path =~ %r{/locales/.*\.yml$} or path =~ %r{/routes.rb$} or path =~ %r{/#{gem_name}.rb$}
|
115
|
-
# put new translations into a tmp directory
|
116
|
-
path.split(File::SEPARATOR).insert(-2, "tmp").join(File::SEPARATOR)
|
117
|
-
elsif path =~ %r{/readme.md$} or path =~ %r{/#{plural_name}.rb$}
|
118
|
-
nil
|
119
|
-
else
|
120
|
-
path
|
121
|
-
end
|
122
|
-
elsif extension.present? and path =~ /lib\/#{plural_name}.rb$/
|
123
|
-
path = nil
|
124
|
-
end
|
125
|
-
end
|
110
|
+
def extension_pathname
|
111
|
+
destination_pathname.join('vendor', 'extensions', extension_plural_name)
|
112
|
+
end
|
126
113
|
|
127
|
-
|
128
|
-
|
114
|
+
def extension_path_for(path, extension, apply_tmp = true)
|
115
|
+
path = extension_pathname.join(path.to_s.gsub(%r{#{source_pathname}/?}, '')).to_s
|
129
116
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
117
|
+
path.gsub!('extension_plural_name', extension_plural_name)
|
118
|
+
path.gsub!('plural_name', plural_name)
|
119
|
+
path.gsub!('singular_name', singular_name)
|
120
|
+
path.gsub!('namespace', namespacing.underscore)
|
121
|
+
|
122
|
+
if options[:namespace].present? || options[:extension].present?
|
123
|
+
# Increment the migration file leading number
|
124
|
+
# Only relevant for nested or namespaced extensions, where a previous migration exists
|
125
|
+
if %r{/migrate/\d+\w*.rb\z} === path
|
126
|
+
if last_migration = Dir["#{destination_pathname.join(path.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR), '*.rb')}"].sort.last
|
127
|
+
path.gsub!(%r{\d+_}) { |m| "#{last_migration.match(%r{migrate/(\d+)_})[1].to_i + 1}_" }
|
134
128
|
end
|
135
129
|
end
|
136
130
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
|
131
|
+
# Detect whether this is a special file that needs to get merged not overwritten.
|
132
|
+
# This is important only when nesting extensions.
|
133
|
+
if extension.present? && File.exist?(path)
|
134
|
+
if %r{/locales/.*\.yml$} === path ||
|
135
|
+
%r{/routes.rb$} === path ||
|
136
|
+
%r{/#{gem_name}.rb$} === path
|
137
|
+
# put new translations into a tmp directory
|
138
|
+
if apply_tmp
|
139
|
+
path = path.split(File::SEPARATOR).insert(-2, "tmp").
|
140
|
+
join(File::SEPARATOR)
|
144
141
|
end
|
142
|
+
elsif %r{/readme.md$} === path || %r{/#{plural_name}.rb$} === path
|
143
|
+
path = nil
|
145
144
|
end
|
145
|
+
elsif extension.present? and path =~ /lib\/#{plural_name}.rb$/
|
146
|
+
path = nil
|
146
147
|
end
|
148
|
+
end
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
-
end
|
150
|
+
path.present? ? Pathname.new(path) : path
|
151
|
+
end
|
151
152
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
def erase_destination!
|
154
|
+
if Pathname.glob(extension_pathname.join('**', '*')).all?(&:directory?)
|
155
|
+
say_status :remove, relative_to_original_destination_root(extension_pathname.to_s), true
|
156
|
+
FileUtils.rm_rf extension_pathname unless options[:pretend]
|
157
|
+
end
|
158
|
+
end
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
160
|
+
def evaluate_templates!
|
161
|
+
Pathname.glob(source_pathname.join('**', '**')).reject{|f|
|
162
|
+
reject_template?(f)
|
163
|
+
}.sort.each do |path|
|
164
|
+
if (template_path = extension_path_for(path, extension_name)).present?
|
165
|
+
next if path.to_s =~ /seeds.rb.erb/
|
162
166
|
|
163
|
-
|
164
|
-
|
165
|
-
puts_instructions!
|
166
|
-
else
|
167
|
-
erase_destination!
|
167
|
+
unless path.to_s =~ /views/
|
168
|
+
template_path = template_path.to_s.sub(".erb", "")
|
168
169
|
end
|
169
|
-
end
|
170
170
|
|
171
|
-
|
172
|
-
"refinerycms-#{extension_plural_name}"
|
173
|
-
end
|
174
|
-
|
175
|
-
def gemfile
|
176
|
-
@gemfile ||= begin
|
177
|
-
Bundler.default_gemfile || destination_pathname.join('Gemfile')
|
178
|
-
end
|
171
|
+
template path, template_path
|
179
172
|
end
|
173
|
+
end
|
174
|
+
end
|
180
175
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
tmp_directories = []
|
185
|
-
Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb,lib/refinerycms-extension_plural_name.rb}"), File::FNM_DOTMATCH).sort.each do |path|
|
186
|
-
# get the path to the current tmp file.
|
187
|
-
new_file_path = destination_pathname.join(extension_path_for(path, extension_name))
|
188
|
-
tmp_directories << Pathname.new(new_file_path.to_s.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)) # save for later
|
189
|
-
# get the path to the existing file and perform a deep hash merge.
|
190
|
-
current_path = Pathname.new(new_file_path.to_s.split(File::SEPARATOR).reject{|f| f == 'tmp'}.join(File::SEPARATOR))
|
191
|
-
new_contents = nil
|
192
|
-
if new_file_path.to_s =~ %r{.yml$}
|
193
|
-
# merge translation files together.
|
194
|
-
new_contents = YAML::load(new_file_path.read).deep_merge(YAML::load(current_path.read)).to_yaml.gsub(%r{^---\n}, '')
|
195
|
-
elsif new_file_path.to_s =~ %r{/routes.rb$}
|
196
|
-
# append any routes from the new file to the current one.
|
197
|
-
routes_file = [(file_parts = current_path.read.to_s.split("\n")).first]
|
198
|
-
routes_file += file_parts[1..-2]
|
199
|
-
routes_file += new_file_path.read.to_s.split("\n")[1..-2]
|
200
|
-
routes_file << file_parts.last
|
201
|
-
new_contents = routes_file.join("\n")
|
202
|
-
elsif new_file_path.to_s =~ %r{/#{gem_name}.rb$}
|
203
|
-
new_contents = current_path.read + new_file_path.read
|
204
|
-
end
|
205
|
-
# write to current file the merged results.
|
206
|
-
current_path.open('w+') { |file| file.puts new_contents } if new_contents
|
207
|
-
end
|
176
|
+
def existing_extension?
|
177
|
+
options[:extension].present? && extension_pathname.directory?
|
178
|
+
end
|
208
179
|
|
209
|
-
|
210
|
-
|
211
|
-
|
180
|
+
def exit_with_message!(message)
|
181
|
+
puts ""
|
182
|
+
puts message
|
183
|
+
puts ""
|
184
|
+
exit 1
|
185
|
+
end
|
212
186
|
|
213
|
-
|
214
|
-
|
215
|
-
|
187
|
+
def finalize_extension!
|
188
|
+
if self.behavior != :revoke and !self.options['pretend']
|
189
|
+
puts_instructions!
|
190
|
+
else
|
191
|
+
erase_destination!
|
192
|
+
end
|
193
|
+
end
|
216
194
|
|
217
|
-
|
218
|
-
|
219
|
-
|
195
|
+
def gem_name
|
196
|
+
"refinerycms-#{extension_plural_name}"
|
197
|
+
end
|
220
198
|
|
221
|
-
|
222
|
-
|
199
|
+
def gemfile
|
200
|
+
@gemfile ||= begin
|
201
|
+
Bundler.default_gemfile || destination_pathname.join('Gemfile')
|
202
|
+
end
|
203
|
+
end
|
223
204
|
|
224
|
-
|
225
|
-
|
205
|
+
def extension_in_gemfile?
|
206
|
+
gemfile.read.scan(%r{#{gem_name}}).any?
|
207
|
+
end
|
226
208
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
209
|
+
def merge_locales!
|
210
|
+
if existing_extension?
|
211
|
+
# go through all of the temporary files and merge what we need into the current files.
|
212
|
+
tmp_directories = []
|
213
|
+
Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb,lib/refinerycms-extension_plural_name.rb}"), File::FNM_DOTMATCH).sort.each do |path|
|
214
|
+
# get the path to the current tmp file.
|
215
|
+
new_file_path = extension_path_for(path, extension_name)
|
216
|
+
tmp_directories << Pathname.new(new_file_path.to_s.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)) # save for later
|
217
|
+
# get the path to the existing file and perform a deep hash merge.
|
218
|
+
current_path = extension_path_for(path, extension_name, false)
|
219
|
+
new_contents = nil
|
220
|
+
if File.exist?(new_file_path) && %r{.yml$} === new_file_path.to_s
|
221
|
+
# merge translation files together.
|
222
|
+
new_contents = YAML::load(new_file_path.read).deep_merge(
|
223
|
+
YAML::load(current_path.read)
|
224
|
+
).to_yaml.gsub(%r{^---\n}, '')
|
225
|
+
elsif %r{/routes.rb$} === new_file_path.to_s
|
226
|
+
# append any routes from the new file to the current one.
|
227
|
+
routes_file = [(file_parts = current_path.read.to_s.split("\n")).first]
|
228
|
+
routes_file += file_parts[1..-2]
|
229
|
+
routes_file += new_file_path.read.to_s.split("\n")[1..-2]
|
230
|
+
routes_file << file_parts.last
|
231
|
+
new_contents = routes_file.join("\n")
|
232
|
+
elsif %r{/#{gem_name}.rb$} === new_file_path.to_s
|
233
|
+
new_contents = current_path.read + new_file_path.read
|
231
234
|
end
|
235
|
+
# write to current file the merged results.
|
236
|
+
current_path.open('w+') { |file| file.puts new_contents } if new_contents
|
232
237
|
end
|
233
238
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
puts "Now run:"
|
238
|
-
puts "bundle install"
|
239
|
-
puts "rails generate refinery:#{extension_plural_name}"
|
240
|
-
puts "rake db:migrate"
|
241
|
-
puts "rake db:seed"
|
242
|
-
puts "------------------------"
|
243
|
-
end
|
244
|
-
end
|
239
|
+
tmp_directories.uniq.each{|dir| remove_dir(dir) if dir && dir.exist?}
|
240
|
+
end
|
241
|
+
end
|
245
242
|
|
246
|
-
|
247
|
-
|
248
|
-
|
243
|
+
def copy_or_merge_seeds!
|
244
|
+
source_seed_file = source_pathname.join("db/seeds.rb.erb")
|
245
|
+
destination_seed_file = destination_pathname.join(
|
246
|
+
extension_path_for(
|
247
|
+
source_seed_file.to_s.sub(".erb", ""), extension_name
|
248
|
+
)
|
249
|
+
)
|
250
|
+
|
251
|
+
if existing_extension?
|
252
|
+
# create temp seeds file
|
253
|
+
temp_seed_file = destination_pathname.join(
|
254
|
+
extension_path_for("tmp/seeds.rb", extension_name)
|
255
|
+
)
|
256
|
+
|
257
|
+
# copy/evaluate seeds template to temp file
|
258
|
+
template source_seed_file, temp_seed_file, :verbose => false
|
259
|
+
|
260
|
+
# append temp seeds file content to extension seeds file
|
261
|
+
destination_seed_file.open('a+') { |file|
|
262
|
+
file.puts temp_seed_file.read.to_s
|
263
|
+
}
|
264
|
+
|
265
|
+
# remove temp file
|
266
|
+
FileUtils.rm_rf temp_seed_file
|
267
|
+
else
|
268
|
+
template source_seed_file, destination_seed_file
|
269
|
+
end
|
270
|
+
end
|
249
271
|
|
250
|
-
|
251
|
-
|
252
|
-
|
272
|
+
def puts_instructions!
|
273
|
+
unless Rails.env.test?
|
274
|
+
puts "------------------------"
|
275
|
+
puts "Now run:"
|
276
|
+
puts "bundle install"
|
277
|
+
puts "rails generate refinery:#{extension_plural_name}"
|
278
|
+
puts "rake db:migrate"
|
279
|
+
puts "rake db:seed"
|
280
|
+
puts "------------------------"
|
281
|
+
end
|
282
|
+
end
|
253
283
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
end
|
284
|
+
def reject_file?(file)
|
285
|
+
!localized? && file.to_s.include?('locale_picker')
|
286
|
+
end
|
258
287
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
else
|
263
|
-
"Please specify the singular name '#{singular_name.singularize}' instead of '#{plural_name}'."
|
264
|
-
end
|
265
|
-
exit_with_message!(message)
|
266
|
-
end
|
288
|
+
def reject_template?(file)
|
289
|
+
file.directory? || reject_file?(file)
|
290
|
+
end
|
267
291
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
292
|
+
def sanity_check!
|
293
|
+
if clash_keywords.member?(singular_name.downcase)
|
294
|
+
exit_with_message!("Please choose a different name. The generated code would fail for class '#{singular_name}' as it conflicts with a reserved keyword.")
|
295
|
+
end
|
272
296
|
|
273
|
-
|
274
|
-
|
297
|
+
if singular_name == plural_name
|
298
|
+
message = if singular_name.singularize == singular_name
|
299
|
+
"The extension name you specified will not work as the singular name is equal to the plural name."
|
300
|
+
else
|
301
|
+
"Please specify the singular name '#{singular_name.singularize}' instead of '#{plural_name}'."
|
275
302
|
end
|
303
|
+
exit_with_message!(message)
|
304
|
+
end
|
305
|
+
|
306
|
+
if attributes.empty? && self.behavior != :revoke
|
307
|
+
exit_with_message!("You must specify a name and at least one field. For help: #{generator_command}")
|
276
308
|
end
|
277
309
|
end
|
278
310
|
|
311
|
+
def source_pathname
|
312
|
+
@source_pathname ||= Pathname.new(self.class.source_root.to_s)
|
313
|
+
end
|
314
|
+
|
279
315
|
end
|
280
316
|
end
|