active_scaffold 3.0.5 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.document +5 -0
  2. data/Gemfile +11 -2
  3. data/Gemfile.lock +20 -0
  4. data/Rakefile +33 -4
  5. data/active_scaffold.gemspec +378 -17
  6. data/frontends/default/images/config.png +0 -0
  7. data/frontends/default/images/gears.png +0 -0
  8. data/frontends/default/javascripts/jquery/active_scaffold.js +34 -33
  9. data/frontends/default/javascripts/jquery/jquery.editinplace.js +21 -4
  10. data/frontends/default/javascripts/prototype/active_scaffold.js +43 -38
  11. data/frontends/default/stylesheets/stylesheet.css +110 -35
  12. data/frontends/default/views/_action_group.html.erb +20 -0
  13. data/frontends/default/views/_base_form.html.erb +7 -3
  14. data/frontends/default/views/_create_form.html.erb +5 -3
  15. data/frontends/default/views/_create_form_on_list.html.erb +2 -1
  16. data/frontends/default/views/_field_search.html.erb +2 -2
  17. data/frontends/default/views/_form.html.erb +2 -2
  18. data/frontends/default/views/_form_messages.html.erb +1 -1
  19. data/frontends/default/views/_horizontal_subform.html.erb +1 -1
  20. data/frontends/default/views/_list_actions.html.erb +6 -14
  21. data/frontends/default/views/_list_header.html.erb +4 -6
  22. data/frontends/default/views/_list_with_header.html.erb +2 -2
  23. data/frontends/default/views/_messages.html.erb +2 -2
  24. data/frontends/default/views/_search.html.erb +2 -2
  25. data/frontends/default/views/_show.html.erb +1 -1
  26. data/frontends/default/views/_update_form.html.erb +2 -1
  27. data/frontends/default/views/_vertical_subform.html.erb +1 -1
  28. data/frontends/default/views/action_confirmation.html.erb +13 -0
  29. data/frontends/default/views/add_existing.js.rjs +1 -1
  30. data/frontends/default/views/destroy.js.rjs +21 -3
  31. data/frontends/default/views/on_action_update.js.rjs +1 -1
  32. data/frontends/default/views/on_create.js.rjs +30 -13
  33. data/frontends/default/views/on_update.js.rjs +19 -6
  34. data/init.rb +6 -0
  35. data/lib/active_scaffold/actions/core.rb +32 -12
  36. data/lib/active_scaffold/actions/create.rb +4 -11
  37. data/lib/active_scaffold/actions/delete.rb +16 -13
  38. data/lib/active_scaffold/actions/list.rb +58 -2
  39. data/lib/active_scaffold/actions/mark.rb +1 -1
  40. data/lib/active_scaffold/actions/nested.rb +24 -15
  41. data/lib/active_scaffold/actions/show.rb +10 -3
  42. data/lib/active_scaffold/actions/update.rb +10 -3
  43. data/lib/{active_record_permissions.rb → active_scaffold/active_record_permissions.rb} +0 -0
  44. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +9 -8
  45. data/lib/active_scaffold/bridges/bridge.rb +1 -1
  46. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +8 -4
  47. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +1 -1
  48. data/lib/active_scaffold/bridges/paperclip/bridge.rb +1 -1
  49. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +1 -1
  50. data/lib/active_scaffold/config/base.rb +8 -0
  51. data/lib/active_scaffold/config/core.rb +2 -15
  52. data/lib/active_scaffold/config/create.rb +8 -0
  53. data/lib/active_scaffold/config/delete.rb +10 -1
  54. data/lib/active_scaffold/config/field_search.rb +1 -0
  55. data/lib/active_scaffold/config/form.rb +2 -1
  56. data/lib/active_scaffold/config/nested.rb +3 -2
  57. data/lib/active_scaffold/config/search.rb +1 -0
  58. data/lib/active_scaffold/config/show.rb +1 -0
  59. data/lib/active_scaffold/config/update.rb +8 -0
  60. data/lib/active_scaffold/constraints.rb +9 -4
  61. data/lib/active_scaffold/data_structures/action_columns.rb +1 -1
  62. data/lib/active_scaffold/data_structures/action_link.rb +10 -1
  63. data/lib/active_scaffold/data_structures/action_links.rb +62 -22
  64. data/lib/active_scaffold/data_structures/column.rb +17 -13
  65. data/lib/active_scaffold/data_structures/nested_info.rb +21 -6
  66. data/lib/active_scaffold/finder.rb +2 -1
  67. data/lib/active_scaffold/helpers/association_helpers.rb +2 -2
  68. data/lib/active_scaffold/helpers/controller_helpers.rb +57 -10
  69. data/lib/active_scaffold/helpers/form_column_helpers.rb +12 -8
  70. data/lib/active_scaffold/helpers/id_helpers.rb +5 -9
  71. data/lib/active_scaffold/helpers/list_column_helpers.rb +26 -28
  72. data/lib/active_scaffold/helpers/search_column_helpers.rb +8 -3
  73. data/lib/active_scaffold/helpers/view_helpers.rb +60 -19
  74. data/lib/active_scaffold/locale/de.rb +13 -6
  75. data/lib/active_scaffold/locale/en.rb +2 -1
  76. data/lib/active_scaffold/locale/es.yml +3 -0
  77. data/lib/active_scaffold/locale/fr.rb +5 -2
  78. data/lib/active_scaffold/locale/ru.yml +77 -20
  79. data/lib/active_scaffold/marked_model.rb +5 -5
  80. data/lib/{paginator.rb → active_scaffold/paginator.rb} +0 -0
  81. data/lib/{responds_to_parent.rb → active_scaffold/responds_to_parent.rb} +0 -0
  82. data/lib/active_scaffold/version.rb +9 -0
  83. data/lib/active_scaffold.rb +60 -84
  84. data/lib/active_scaffold_assets.rb +45 -0
  85. data/lib/active_scaffold_env.rb +14 -0
  86. data/lib/active_scaffold_vho.rb +2 -0
  87. data/lib/extensions/active_association_reflection.rb +13 -0
  88. data/lib/extensions/paginator_extensions.rb +1 -1
  89. data/lib/extensions/routing_mapper.rb +1 -1
  90. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +12 -4
  91. metadata +85 -68
  92. data/lib/dhtml_confirm.rb +0 -54
@@ -2,61 +2,118 @@ ru:
2
2
  active_scaffold:
3
3
  add: 'Добавить запись'
4
4
  add_existing: 'Добавить существующую запись'
5
- add_existing_model: 'Добавить существующую запись %{model}'
6
- are_you_sure_to_delete: 'Вы уверены?'
5
+ add_existing_model: '%{model}: добавить существующую запись'
6
+ are_you_sure_to_delete: 'Удалить %{label}?'
7
7
  cancel: 'Отмена'
8
8
  click_to_edit: 'Нажмите для редактирования'
9
+ click_to_reset: 'Нажмите для сброса'
9
10
  close: 'Закрыть'
10
- create: 'Создать запись'
11
- create_model: 'Создать запись %{model}'
11
+ config_list: 'Настройки списка'
12
+ config_list_model: '%{model}: настройки списка'
13
+ create: 'Создать'
14
+ create_model: '%{model}: создать запись'
12
15
  create_another: 'Создать другую запись'
13
- created_model: 'Создана запись %{model}'
16
+ created_model: '%{model}: запись создана'
14
17
  create_new: 'Создать новую запись'
15
18
  customize: 'Настроить'
16
19
  delete: 'Удалить'
17
- deleted_model: 'Удалена запись %{model}'
20
+ deleted_model: '%{model}: запись удалена'
18
21
  delimiter: 'Разделитель'
19
22
  download: 'Загрузить'
20
23
  edit: 'Изменить'
21
24
  export: 'Экспорт'
22
25
  nested_for_model: '%{parent_model} / %{nested_model}'
23
- nested_of_model: '%{nested_model} of %{parent_model}'
26
+ nested_of_model: '%{nested_model} @ %{parent_model}'
27
+ false: 'Нет'
24
28
  filtered: '(Найденное)'
25
- found: 'Найдено'
29
+ found:
30
+ one: 'запись'
31
+ few: 'записи'
32
+ many: 'записей'
33
+ other: 'записи'
26
34
  hide: 'Скрыть'
27
35
  live_search: 'Поиск'
28
- loading: 'Загрузка...'
36
+ loading: 'Загрузка…'
29
37
  next: 'Следующее'
30
38
  no_entries: 'Нет записей'
31
- omit_header: 'Omit Header'
39
+ no_options: 'Нет вариантов'
40
+ omit_header: 'Пропустить заголовок'
32
41
  options: 'Настройки'
33
42
  pdf: 'PDF'
34
43
  previous: 'Предыдущее'
35
- print: 'Распечатать'
44
+ print: 'Печать'
36
45
  refresh: 'Обновить'
37
46
  remove: 'Удалить'
38
47
  remove_file: 'Удалить или заменить файл'
39
48
  replace_with_new: 'Заменить новым'
40
- revisions_for_model: 'Редакции %{model}'
41
- reset: 'Сбросить'
42
- saving: 'Сохранение...'
49
+ revisions_for_model: '%{model}: редакции'
50
+ reset: 'Сброс'
51
+ saving: 'Сохранение…'
43
52
  search: 'Поиск'
44
53
  search_terms: 'Ключевые слова'
45
54
  _select_: '- выбрать -'
46
55
  show: 'Показать'
47
- show_model: 'Показать запись %{model}'
56
+ show_model: '%{model}: показать запись'
48
57
  _to_ : ' to '
58
+ true: 'Да'
49
59
  update: 'Обновить запись'
50
- update_model: 'Обновить запись %{model}'
51
- updated_model: 'Обновлена запись %{model}'
60
+ update_model: '%{model}: обновить запись'
61
+ updated_model: '%{model}: запись обновлена'
52
62
  '=': '='
53
63
  '>=': '>='
54
64
  '<=': '<='
55
65
  '>': '>'
56
66
  '<': '<'
57
67
  '!=': '!='
58
- between: 'Между'
68
+ between: 'В интервале'
69
+ contains: 'Содержит'
70
+ begins_with: 'Начинается с'
71
+ ends_with: 'Оканчивается на'
72
+ today: 'Сегодня'
73
+ yesterday: 'Вчера'
74
+ tomorrow: 'Завтра'
75
+ this_week: 'На этой неделе'
76
+ prev_week: 'На прошлой неделе'
77
+ next_week: 'На следующей неделе'
78
+ this_month: 'В этом месяце'
79
+ prev_month: 'В прошлом месяце'
80
+ next_month: 'В следующем месяце'
81
+ this_year: 'В этом году'
82
+ prev_year: 'В прошлом году'
83
+ next_year: 'В следующем году'
84
+ past: 'Прошлое'
85
+ future: 'Будущее'
86
+ range: 'Интервал'
87
+ seconds: 'секунд'
88
+ minutes: 'минут'
89
+ hours: 'часов'
90
+ days: 'дней'
91
+ weeks: 'недель'
92
+ months: 'месяцев'
93
+ years: 'лет'
94
+ optional_attributes: 'Дополнительные настройки'
95
+ null: 'Пусто'
96
+ not_null: 'Не пусто'
97
+ date_picker_options:
98
+ weekHeader: 'Нед.'
99
+ firstDay: 1
100
+ isRTL: false
101
+ showMonthAfterYear: false
102
+ datetime_picker_options:
103
+ timeText: 'Время'
104
+ currentText: 'Сегодня'
105
+ closeText: 'Закрыть'
106
+ errors:
107
+ template:
108
+ header:
109
+ one: '%{model}: сохранение не удалось из-за %{count} ошибки'
110
+ few: '%{model}: сохранение не удалось из-за %{count} ошибок'
111
+ many: '%{model}: сохранение не удалось из-за %{count} ошибок'
112
+ other: '%{model}: сохранение не удалось из-за %{count} ошибки'
113
+ body: 'Проблемы возникли со следующими полями:'
59
114
 
60
115
  # error_messages
61
- internal_error: 'Внутренняя ошибка сервера.'
62
- version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать.'
116
+ cant_destroy_record: 'Запись %{record} не может быть удалена'
117
+ failed_to_save_record: 'Запись не может быть сохранена из-за неизвестной ошибки'
118
+ internal_error: '500 Внутренняя ошибка сервера'
119
+ version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать'
@@ -21,12 +21,12 @@ module ActiveScaffold
21
21
  end
22
22
 
23
23
  module ClassMethods
24
- # The proc to call that retrieves the marked_records from the ApplicationController.
25
- attr_accessor :marked_records_proc
26
-
27
- # Class-level access to the marked_records
28
24
  def marked_records
29
- (marked_records_proc.call || Set.new) if marked_records_proc
25
+ Thread.current[:marked_records] ||= Set.new
26
+ end
27
+
28
+ def marked_records=(marked)
29
+ Thread.current[:marked_records] = marked
30
30
  end
31
31
  end
32
32
 
File without changes
@@ -0,0 +1,9 @@
1
+ module ActiveScaffold
2
+ module Version
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ PATCH = 11
6
+
7
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
@@ -2,13 +2,21 @@ unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 0
2
2
  raise "This version of ActiveScaffold requires Rails 3.0 or higher. Please use an earlier version."
3
3
  end
4
4
 
5
- require 'render_component' rescue nil
6
- require 'verification'
5
+ begin
6
+ require 'render_component'
7
+ rescue LoadError
8
+ end
9
+ begin
10
+ require 'verification'
11
+ rescue LoadError
12
+ end
13
+
14
+ require 'active_scaffold_assets'
15
+ require 'active_scaffold/active_record_permissions'
16
+ require 'active_scaffold/paginator'
17
+ require 'active_scaffold/responds_to_parent'
7
18
 
8
- require 'active_record_permissions'
9
- require 'dhtml_confirm'
10
- require 'paginator'
11
- require 'responds_to_parent'
19
+ require 'active_scaffold/version'
12
20
 
13
21
  module ActiveScaffold
14
22
  autoload :AttributeParams, 'active_scaffold/attribute_params'
@@ -17,8 +25,8 @@ module ActiveScaffold
17
25
  autoload :Finder, 'active_scaffold/finder'
18
26
  autoload :MarkedModel, 'active_scaffold/marked_model'
19
27
 
20
- def self.active_scaffold_autoload_subdir(dir, mod=self)
21
- Dir["#{File.dirname(__FILE__)}/active_scaffold/#{dir}/*.rb"].each { |file|
28
+ def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
29
+ Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file|
22
30
  basename = File.basename(file, ".rb")
23
31
  mod.module_eval {
24
32
  autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
@@ -27,7 +35,7 @@ module ActiveScaffold
27
35
  end
28
36
 
29
37
  module Actions
30
- ActiveScaffold.active_scaffold_autoload_subdir('actions', self)
38
+ ActiveScaffold.autoload_subdir('actions', self)
31
39
  end
32
40
 
33
41
  module Bridges
@@ -35,15 +43,15 @@ module ActiveScaffold
35
43
  end
36
44
 
37
45
  module Config
38
- ActiveScaffold.active_scaffold_autoload_subdir('config', self)
46
+ ActiveScaffold.autoload_subdir('config', self)
39
47
  end
40
48
 
41
49
  module DataStructures
42
- ActiveScaffold.active_scaffold_autoload_subdir('data_structures', self)
50
+ ActiveScaffold.autoload_subdir('data_structures', self)
43
51
  end
44
52
 
45
53
  module Helpers
46
- ActiveScaffold.active_scaffold_autoload_subdir('helpers', self)
54
+ ActiveScaffold.autoload_subdir('helpers', self)
47
55
  end
48
56
 
49
57
  class ControllerNotFound < RuntimeError; end
@@ -100,58 +108,10 @@ module ActiveScaffold
100
108
  @@js_framework ||= :prototype
101
109
  end
102
110
 
103
- ##
104
- ## Copy over asset files (javascript/css/images) from directory to public/
105
- ##
106
- def self.install_assets_from(directory)
107
- copy_files("/public", "/public", directory)
108
-
109
- available_frontends = Dir[File.join(directory, 'frontends', '*')].map { |d| File.basename d }
110
- [:stylesheets, :javascripts, :images].each do |asset_type|
111
- path = "/public/#{asset_type}/active_scaffold"
112
- copy_files(path, path, directory)
113
-
114
- File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f|
115
- f.puts "Any changes made to files in sub-folders will be lost."
116
- f.puts "See http://activescaffold.com/tutorials/faq#custom-css."
117
- end
118
-
119
- available_frontends.each do |frontend|
120
- if asset_type == :javascripts
121
- file_mask = '*.js'
122
- source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}"
123
- else
124
- file_mask = '*.*'
125
- source = "/frontends/#{frontend}/#{asset_type}"
126
- end
127
- destination = "/public/#{asset_type}/active_scaffold/#{frontend}"
128
- copy_files(source, destination, directory, file_mask)
129
- end
130
- end
131
- end
132
-
133
111
  def self.root
134
112
  File.dirname(__FILE__) + "/.."
135
113
  end
136
114
 
137
- def self.delete_stale_assets
138
- available_frontends = Dir[File.join(root, 'frontends', '*')].map { |d| File.basename d }
139
- [:stylesheets, :javascripts, :images].each do |asset_type|
140
- available_frontends.each do |frontend|
141
- destination = File.join(Rails.root, "/public/#{asset_type}/active_scaffold/#{frontend}")
142
- FileUtils.rm Dir.glob("#{destination}/*")
143
- end
144
- end
145
- end
146
-
147
- private
148
- def self.copy_files(source_path, destination_path, directory, file_mask = '*.*')
149
- source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path)
150
- FileUtils.mkdir_p(destination) unless File.exist?(destination)
151
-
152
- FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination)
153
- end
154
-
155
115
  module ClassMethods
156
116
  def active_scaffold(model_id = nil, &block)
157
117
  # initialize bridges here
@@ -181,6 +141,7 @@ module ActiveScaffold
181
141
  @active_scaffold_custom_paths = []
182
142
 
183
143
  self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock}
144
+ self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
184
145
  self.active_scaffold_config.configure &block if block_given?
185
146
  self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil?
186
147
  self.active_scaffold_config._load_action_columns
@@ -200,14 +161,33 @@ module ActiveScaffold
200
161
 
201
162
  # sneak the action links from the actions into the main set
202
163
  if link = active_scaffold_config.send(mod).link rescue nil
203
- active_scaffold_config.action_links << link
164
+ if link.is_a? Array
165
+ link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)}
166
+ elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
167
+ active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
168
+ end
204
169
  end
205
170
  end
206
171
  end
207
172
  active_scaffold_paths.each do |path|
208
173
  self.append_view_path(ActionView::ActiveScaffoldResolver.new(path))
209
174
  end
210
- self.active_scaffold_config._add_sti_create_links if self.active_scaffold_config.add_sti_create_links?
175
+ self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links?
176
+ end
177
+
178
+ # To be called after include action modules
179
+ def _add_sti_create_links
180
+ new_action_link = active_scaffold_config.action_links.collection['new']
181
+ unless new_action_link.nil? || active_scaffold_config.sti_children.empty?
182
+ active_scaffold_config.action_links.collection.delete('new')
183
+ active_scaffold_config.sti_children.each do |child|
184
+ new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
185
+ new_sti_link.label = child.to_s.camelize.constantize.model_name.human
186
+ new_sti_link.parameters = {:parent_sti => controller_path}
187
+ new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path }
188
+ active_scaffold_config.action_links.collection.create.add(new_sti_link)
189
+ end
190
+ end
211
191
  end
212
192
 
213
193
  # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
@@ -215,14 +195,22 @@ module ActiveScaffold
215
195
  return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested
216
196
  active_scaffold_config.columns.each do |column|
217
197
  next unless column.link.nil? and column.autolink?
218
- action_link = link_for_association(column)
219
- column.set_link(action_link) unless action_link.nil?
198
+ #lazy load of action_link, cause it was really slowing down app in dev mode
199
+ #and might lead to trouble cause of cyclic constantization of controllers
200
+ #and might be unnecessary cause it is done before columns are configured
201
+ column.set_link(Proc.new {|col| link_for_association(col)})
220
202
  end
221
203
  end
222
204
 
223
205
  def link_for_association(column, options = {})
224
206
  begin
225
- controller = column.polymorphic_association? ? :polymorph : active_scaffold_controller_for(column.association.klass)
207
+ controller = if column.polymorphic_association?
208
+ :polymorph
209
+ elsif options.include?(:controller)
210
+ "#{options[:controller].to_s.camelize}Controller".constantize
211
+ else
212
+ active_scaffold_controller_for(column.association.klass)
213
+ end
226
214
  rescue ActiveScaffold::ControllerNotFound
227
215
  controller = nil
228
216
  end
@@ -230,7 +218,7 @@ module ActiveScaffold
230
218
  unless controller.nil?
231
219
  options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column
232
220
  options[:parameters] ||= {}
233
- options[:parameters].reverse_merge! :parent_model => column.active_record_class.to_s.underscore, :association => column.association.name
221
+ options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name
234
222
  if column.plural_association?
235
223
  # note: we can't create nested scaffolds on :through associations because there's no reverse association.
236
224
 
@@ -249,7 +237,7 @@ module ActiveScaffold
249
237
  def link_for_association_as_scope(scope, options = {})
250
238
  options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
251
239
  options[:parameters] ||= {}
252
- options[:parameters].reverse_merge! :parent_model => active_scaffold_config.model.to_s.underscore, :named_scope => scope
240
+ options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope
253
241
  ActiveScaffold::DataStructures::ActionLink.new('index', options)
254
242
  end
255
243
 
@@ -343,30 +331,18 @@ module ActiveScaffold
343
331
  end
344
332
  end
345
333
 
346
- # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
347
- Dir["#{File.dirname __FILE__}/extensions/*.rb"].each { |file| require file }
348
-
349
- ActionController::Base.send(:include, ActiveScaffold)
350
- ActionController::Base.send(:include, RespondsToParent)
351
- ActionController::Base.send(:include, ActiveScaffold::Helpers::ControllerHelpers)
352
- ActionView::Base.send(:include, ActiveScaffold::Helpers::ViewHelpers)
353
-
354
- ActionController::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Controller}
355
- ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model}
356
- ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions}
357
-
358
- I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'active_scaffold', 'locale', '*.{rb,yml}')]
359
- #ActiveScaffold.js_framework = :jquery
334
+ require 'active_scaffold_env'
360
335
 
361
336
  ##
362
337
  ## Run the install assets script, too, just to make sure
363
338
  ## But at least rescue the action in production
364
339
  ##
340
+
365
341
  Rails::Application.initializer("active_scaffold.install_assets") do
366
342
  begin
367
- ActiveScaffold.delete_stale_assets
368
- ActiveScaffold.install_assets_from(ActiveScaffold.root)
343
+ ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true})
369
344
  rescue
370
345
  raise $! unless Rails.env == 'production'
371
346
  end
372
- end
347
+ end if defined?(ACTIVE_SCAFFOLD_GEM)
348
+
@@ -0,0 +1,45 @@
1
+ class ActiveScaffoldAssets
2
+
3
+ def self.copy_to_public(from, options = {})
4
+ unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false
5
+ copy_files("/public", "/public", from)
6
+ available_frontends = Dir[File.join(from, 'frontends', '*')].collect { |d| File.basename d }
7
+ [:stylesheets, :javascripts, :images].each do |asset_type|
8
+ copy_asset_type(from, available_frontends, asset_type, options)
9
+ end
10
+ end
11
+ end
12
+
13
+ protected
14
+
15
+ def self.copy_asset_type(from, available_frontends, asset_type, options = {})
16
+ path = "/public/#{asset_type}/active_scaffold"
17
+ copy_files(path, path, from)
18
+
19
+ File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f|
20
+ f.puts "Any changes made to files in sub-folders will be lost."
21
+ f.puts "See http://activescaffold.com/tutorials/faq#custom-css."
22
+ end
23
+
24
+ available_frontends.each do |frontend|
25
+ if asset_type == :javascripts
26
+ file_mask = '*.js'
27
+ source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}"
28
+ else
29
+ file_mask = '*.*'
30
+ source = "/frontends/#{frontend}/#{asset_type}"
31
+ end
32
+ destination = "/public/#{asset_type}/active_scaffold/#{frontend}"
33
+ copy_files(source, destination, from, file_mask, options)
34
+ end
35
+ end
36
+
37
+ def self.copy_files(source_path, destination_path, directory, file_mask = '*.*', options = {})
38
+ source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path)
39
+ FileUtils.mkdir_p(destination) unless File.exist?(destination)
40
+ Dir.glob('*.so')
41
+
42
+ FileUtils.rm Dir.glob("#{destination}/*") if options[:clean_up_destination]
43
+ FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination)
44
+ end
45
+ end
@@ -0,0 +1,14 @@
1
+ # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
2
+ Dir["#{File.dirname __FILE__}/extensions/*.rb"].each { |file| require file }
3
+
4
+ ActionController::Base.send(:include, ActiveScaffold)
5
+ ActionController::Base.send(:include, RespondsToParent)
6
+ ActionController::Base.send(:include, ActiveScaffold::Helpers::ControllerHelpers)
7
+ ActionView::Base.send(:include, ActiveScaffold::Helpers::ViewHelpers)
8
+
9
+ ActionController::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Controller}
10
+ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model}
11
+ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions}
12
+
13
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'active_scaffold', 'locale', '*.{rb,yml}')]
14
+ #ActiveScaffold.js_framework = :jquery
@@ -0,0 +1,2 @@
1
+ ACTIVE_SCAFFOLD_GEM = true
2
+ require 'active_scaffold'
@@ -0,0 +1,13 @@
1
+ # Bugfix: building an sti model from an association fails
2
+ # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti
3
+ ActiveRecord::Reflection::AssociationReflection.class_eval do
4
+ def build_association(*opts)
5
+ col = klass.inheritance_column.to_sym
6
+ if !col.nil? && opts.first.is_a?(Hash) && (opts.first.symbolize_keys[col])
7
+ sti_model = opts.first.delete(col)
8
+ sti_model.to_s.camelize.constantize.new(*opts)
9
+ else
10
+ klass.new(*opts)
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- require 'paginator'
1
+ require 'active_scaffold/paginator'
2
2
 
3
3
  class Paginator
4
4
 
@@ -2,7 +2,7 @@ module ActionDispatch
2
2
  module Routing
3
3
  ACTIVE_SCAFFOLD_CORE_ROUTING = {
4
4
  :collection => {:show_search => :get, :render_field => :get},
5
- :member => {:row => :get, :update_column => :post, :render_field => :get, :delete => :get}
5
+ :member => {:row => :get, :update_column => :post, :render_field => :get}
6
6
  }
7
7
  ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = {
8
8
  :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
@@ -8,8 +8,10 @@ module Rails
8
8
  end
9
9
 
10
10
  def install_plugins
11
- plugin 'verification', :git => 'git://github.com/rails/verification.git'
12
- plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git'
11
+ unless defined?(ACTIVE_SCAFFOLD_GEM)
12
+ plugin 'verification', :git => 'git://github.com/rails/verification.git'
13
+ plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git'
14
+ end
13
15
  if js_lib == 'prototype'
14
16
  get "https://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
15
17
  elsif js_lib == 'jquery'
@@ -19,8 +21,14 @@ module Rails
19
21
  end
20
22
 
21
23
  def configure_active_scaffold
22
- if js_lib == 'jquery'
23
- gsub_file 'vendor/plugins/active_scaffold/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery'
24
+ unless defined?(ACTIVE_SCAFFOLD_GEM)
25
+ if js_lib == 'jquery'
26
+ gsub_file 'vendor/plugins/active_scaffold/lib/active_scaffold_env.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery'
27
+ end
28
+ else
29
+ if js_lib == 'jquery'
30
+ create_file "config/initializers/active_scaffold.rb", "ActiveScaffold.js_framework = :jquery"
31
+ end
24
32
  end
25
33
  end
26
34