caboose-cms 0.9.228 → 0.9.229

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/caboose/admin.js +1 -1
  3. data/app/assets/javascripts/caboose/admin_main.js +1 -13
  4. data/app/assets/javascripts/caboose/admin_media_index.js +161 -158
  5. data/app/assets/javascripts/caboose/application.js +8 -7
  6. data/app/assets/javascripts/caboose/block_content_controller_dragdrop.js +60 -4
  7. data/app/assets/javascripts/caboose/block_modal_controllers/block_dd_modal_controller.js +3 -2
  8. data/app/assets/javascripts/caboose/block_modal_controllers/media_modal_controller.js +17 -6
  9. data/app/assets/javascripts/caboose/model/all.js +5 -1
  10. data/app/assets/stylesheets/caboose/admin_block_edit_image.css.scss +2 -1
  11. data/app/assets/stylesheets/caboose/admin_edit_page_content_dragdrop.scss +71 -15
  12. data/app/assets/stylesheets/caboose/admin_main.css.scss +25 -29
  13. data/app/assets/stylesheets/caboose/admin_media_index.css.scss +26 -5
  14. data/app/assets/stylesheets/caboose/application.css +11 -5
  15. data/app/assets/stylesheets/caboose/login.scss +1 -0
  16. data/app/assets/stylesheets/caboose/model_binder.css +13 -4
  17. data/app/assets/stylesheets/caboose/page_bar_generator.css +2 -1
  18. data/app/controllers/caboose/admin_controller.rb +3 -4
  19. data/app/controllers/caboose/application_controller.rb +16 -19
  20. data/app/controllers/caboose/block_types_controller.rb +8 -6
  21. data/app/controllers/caboose/cart_controller.rb +2 -2
  22. data/app/controllers/caboose/change_logs_controller.rb +13 -0
  23. data/app/controllers/caboose/fonts_controller.rb +139 -2
  24. data/app/controllers/caboose/invoices_controller.rb +5 -4
  25. data/app/controllers/caboose/login_logs_controller.rb +5 -7
  26. data/app/controllers/caboose/media_categories_controller.rb +16 -2
  27. data/app/controllers/caboose/media_controller.rb +14 -11
  28. data/app/controllers/caboose/pages_controller.rb +104 -42
  29. data/app/controllers/caboose/posts_controller.rb +53 -7
  30. data/app/controllers/caboose/products_controller.rb +1 -1
  31. data/app/controllers/caboose/sites_controller.rb +25 -6
  32. data/app/controllers/caboose/sns_controller.rb +3 -3
  33. data/app/controllers/caboose/themes_controller.rb +30 -0
  34. data/app/controllers/caboose/users_controller.rb +17 -10
  35. data/app/controllers/caboose/variants_controller.rb +9 -9
  36. data/app/models/caboose/block.rb +98 -22
  37. data/app/models/caboose/block_type.rb +2 -1
  38. data/app/models/caboose/block_type_parser.rb +1 -1
  39. data/app/models/caboose/calendar_event_group.rb +2 -2
  40. data/app/models/caboose/change_log.rb +97 -0
  41. data/app/models/caboose/core_plugin.rb +4 -3
  42. data/app/models/caboose/font.rb +7 -2
  43. data/app/models/caboose/font_variant.rb +12 -0
  44. data/app/models/caboose/media.rb +15 -4
  45. data/app/models/caboose/media_category.rb +2 -4
  46. data/app/models/caboose/page.rb +316 -45
  47. data/app/models/caboose/page_bar_generator.rb +20 -10
  48. data/app/models/caboose/post.rb +108 -8
  49. data/app/models/caboose/product.rb +1 -1
  50. data/app/models/caboose/role.rb +2 -2
  51. data/app/models/caboose/schema.rb +73 -72
  52. data/app/models/caboose/site.rb +203 -1
  53. data/app/models/caboose/theme.rb +70 -5
  54. data/app/views/caboose/block_types/admin_edit.html.erb +6 -8
  55. data/app/views/caboose/blocks/_cached_block.html.erb +28 -0
  56. data/app/views/caboose/blocks/_file.html.erb +2 -2
  57. data/app/views/caboose/blocks/_ga.html.erb +1 -2
  58. data/app/views/caboose/blocks/_image.html.erb +4 -0
  59. data/app/views/caboose/blocks/_render_function.html.erb +9 -4
  60. data/app/views/caboose/change_logs/admin_index.html.erb +65 -0
  61. data/app/views/caboose/fonts/admin_family_edit.html.erb +63 -0
  62. data/app/views/caboose/fonts/admin_family_index.html.erb +42 -0
  63. data/app/views/caboose/fonts/admin_index.html.erb +55 -10
  64. data/app/views/caboose/fonts/admin_variant_edit.html.erb +84 -0
  65. data/app/views/caboose/invoices_mailer/customer_status_updated.html.erb +5 -14
  66. data/app/views/caboose/login_logs/admin_index_for_user.html.erb +1 -1
  67. data/app/views/caboose/media/admin_index.html.erb +14 -24
  68. data/app/views/caboose/my_account/index.html.erb +1 -0
  69. data/app/views/caboose/pages/_admin_header.html.erb +5 -0
  70. data/app/views/caboose/pages/admin_change_logs.html.erb +56 -0
  71. data/app/views/caboose/pages/admin_edit_content.html.erb +6 -2
  72. data/app/views/caboose/pages/admin_edit_general.html.erb +32 -4
  73. data/app/views/caboose/pages/compiled_asset.css.erb +0 -0
  74. data/app/views/caboose/pages/compiled_asset.js.erb +0 -0
  75. data/app/views/caboose/posts/_admin_header.html.erb +5 -0
  76. data/app/views/caboose/posts/admin_change_logs.html.erb +56 -0
  77. data/app/views/caboose/posts/admin_delete_form.html.erb +1 -1
  78. data/app/views/caboose/posts/admin_edit_content.html.erb +6 -2
  79. data/app/views/caboose/products/admin_group_variants.html.erb +1 -1
  80. data/app/views/caboose/products/admin_sort.html copy.erb +1 -1
  81. data/app/views/caboose/sites/admin_edit.html.erb +21 -0
  82. data/app/views/caboose/sites/compiled_asset.css.erb +0 -0
  83. data/app/views/caboose/sites/compiled_asset.js.erb +0 -0
  84. data/app/views/caboose/themes/admin_edit.html.erb +7 -3
  85. data/app/views/caboose/themes/admin_error_log.html.erb +9 -0
  86. data/app/views/caboose/themes/admin_js.html.erb +131 -0
  87. data/app/views/caboose/users/_admin_header.html.erb +4 -0
  88. data/app/views/caboose/users/admin_change_logs.html.erb +63 -0
  89. data/app/views/caboose/users/admin_edit_roles.html.erb +1 -0
  90. data/app/views/caboose/variants/admin_group.html.erb +1 -1
  91. data/app/views/layouts/caboose/admin.html.erb +9 -2
  92. data/app/views/layouts/caboose/application.html.erb +62 -92
  93. data/app/views/layouts/caboose/css.css.erb +44 -0
  94. data/app/views/layouts/caboose/footer_css.css.erb +41 -0
  95. data/app/views/layouts/caboose/footer_js.js.erb +31 -0
  96. data/app/views/layouts/caboose/js.js.erb +34 -0
  97. data/lib/caboose/version.rb +1 -1
  98. data/lib/tasks/caboose.rake +3 -14
  99. metadata +23 -27
  100. data/app/controllers/caboose/assets_controller.rb +0 -65
  101. data/app/models/caboose/asset.rb +0 -23
  102. data/app/models/caboose/asset_manifest.rb +0 -91
  103. data/app/models/caboose/block_cache.rb +0 -105
  104. data/app/models/caboose/block_cache_file.rb +0 -22
  105. data/app/models/caboose/block_cache_image.rb +0 -53
  106. data/app/models/caboose/page_cache.rb +0 -12
  107. data/app/models/caboose/page_cacher.rb +0 -137
  108. data/app/views/caboose/pages/admin_new_old.html.erb +0 -46
  109. data/app/views/caboose/pages/test.html.erb +0 -64
@@ -323,7 +323,7 @@ module Caboose
323
323
  :params => params.to_json,
324
324
  :status => 'pending'
325
325
  )
326
- e.delay(:queue => 'caboose_general', :priority => 8).product_process if Rails.env.production?
326
+ e.delay(:queue => 'general', :priority => 8).product_process if Rails.env.production?
327
327
  e.product_process if Rails.env.development?
328
328
  resp.new_id = e.id
329
329
  resp.success = true
@@ -89,8 +89,8 @@ module Caboose
89
89
 
90
90
  # @route GET /admin/sites/:id/block-types
91
91
  def admin_edit_block_types
92
- return if !user_is_allowed('sites', 'edit')
93
- if (!logged_in_user.is_super_admin?)
92
+ return unless user_is_allowed('site_settings', 'edit') || user_is_allowed('sites', 'edit')
93
+ if (@site.id.to_s != params[:id] && !@site.is_master)
94
94
  @error = "You are not allowed to edit this site."
95
95
  render :file => 'caboose/extras/error' and return
96
96
  end
@@ -139,8 +139,8 @@ module Caboose
139
139
 
140
140
  # @route GET /admin/sites/:id
141
141
  def admin_edit
142
- return if !user_is_allowed('sites', 'edit')
143
- if (!logged_in_user.is_super_admin?)
142
+ return unless user_is_allowed('site_settings', 'edit') || user_is_allowed('sites', 'edit')
143
+ if (@site.id.to_s != params[:id] && !@site.is_master)
144
144
  @error = "You are not allowed to edit this site."
145
145
  render :file => 'caboose/extras/error' and return
146
146
  end
@@ -168,6 +168,7 @@ module Caboose
168
168
  site.description = site_name
169
169
  site.use_fonts = true
170
170
  site.use_dragdrop = true
171
+ site.use_caching = true
171
172
  site.theme_color = '#141414'
172
173
  site.allow_self_registration = false
173
174
  site.use_store = false
@@ -214,8 +215,11 @@ module Caboose
214
215
  when 'state' then site.state = value
215
216
  when 'zip' then site.zip = value
216
217
  when 'fax' then site.fax = value
218
+ when 'use_change_logs' then site.use_change_logs = value
219
+ when 'google_api_key' then site.google_api_key = value
217
220
  when 'contact_email' then site.contact_email = value
218
221
  when 'recaptcha_threshold' then site.recaptcha_threshold = value
222
+ when 'use_caching' then site.use_caching = value
219
223
  when 'head_code' then site.head_code = (value.blank? ? nil : value.gsub('<end/script>','</script>'))
220
224
  when 'body_open_code' then site.body_open_code = (value.blank? ? nil : value.gsub('<end/script>','</script>'))
221
225
  when 'body_close_code' then site.body_close_code = (value.blank? ? nil : value.gsub('<end/script>','</script>'))
@@ -299,8 +303,8 @@ module Caboose
299
303
  # @route GET /admin/sites/:field-options
300
304
  # @route GET /admin/sites/:id/:field-options
301
305
  def options
302
- return if !user_is_allowed('sites', 'view')
303
- render :json => { :error => "You are not allowed to manage sites." } and return if !@site.is_master
306
+ return if !user_is_allowed('sites', 'edit')
307
+ render :json => { :error => "You are not allowed to manage sites." } and return if !logged_in_user.is_super_admin?
304
308
  case params[:field]
305
309
  when nil
306
310
  options = logged_in_user.is_super_admin? ? Site.reorder('name').all.collect { |s| { 'value' => s.id, 'text' => s.name }} : []
@@ -315,6 +319,21 @@ module Caboose
315
319
  end
316
320
 
317
321
 
322
+ # @route PUT /admin/sites/:id/refresh-cache
323
+ def admin_refresh_cache
324
+ return if !user_is_allowed('sites', 'edit')
325
+ @site.delay(:queue => 'caching', :priority => 5).refresh_all_page_caches
326
+ render :json => true
327
+ end
328
+
329
+ # @route GET /api/generate-asset/site_:id
330
+ def compiled_asset
331
+ respond_to do |format|
332
+ format.css { render :layout => 'caboose/footer_css', :content_type => "text/css" }
333
+ format.js { render :layout => 'caboose/footer_js', :content_type => "text/javascript" }
334
+ end
335
+ end
336
+
318
337
  private
319
338
 
320
339
  def get_edit_site(s_id, site_id)
@@ -22,9 +22,9 @@ module Caboose
22
22
  media_category_id = arr.shift
23
23
  original_name = arr.join('_')
24
24
  name = Caboose::Media.upload_name(original_name)
25
- m = Media.where(:media_category_id => media_category_id, :original_name => original_name, :name => name).first
26
- m = Media.create(:media_category_id => media_category_id, :original_name => original_name, :name => name, :processed => false) if m.nil?
27
- m.delay(:queue => 'caboose_media', :priority => 3).process
25
+ m = Media.where(:media_category_id => media_category_id, :original_name => original_name, :name => name, :processed => false, :deleted => false).order('id desc').first
26
+ m = Media.create(:media_category_id => media_category_id, :original_name => original_name, :name => name, :processed => false, :deleted => false) if m.nil?
27
+ m.delay(:queue => 'general', :priority => 3).process
28
28
  end
29
29
  end
30
30
  end
@@ -134,6 +134,18 @@ module Caboose
134
134
  @theme = @site.theme
135
135
  end
136
136
 
137
+ # @route GET /admin/theme/js
138
+ def admin_js
139
+ return if !user_is_allowed('theme', 'edit')
140
+ @theme = @site.theme
141
+ end
142
+
143
+ # @route GET /admin/theme/errors
144
+ def admin_error_log
145
+ return if !user_is_allowed('theme', 'edit')
146
+ @theme = @site.theme
147
+ end
148
+
137
149
  # @route PUT /admin/theme/sass
138
150
  def admin_update_sass
139
151
  return if !user_is_allowed('theme', 'edit')
@@ -146,6 +158,19 @@ module Caboose
146
158
  render :json => resp
147
159
  end
148
160
 
161
+ # @route PUT /admin/theme/js
162
+ def admin_update_js
163
+ return if !user_is_allowed('theme', 'edit')
164
+ resp = StdClass.new
165
+ @theme = @site.theme
166
+ @theme.main_js = params['code']
167
+ @theme.save
168
+ @theme.upload_js(@site.id)
169
+ resp.success = true
170
+ resp.message = "Code has been saved!"
171
+ render :json => resp
172
+ end
173
+
149
174
  # @route POST /admin/themes/:id/default-banner-image
150
175
  def admin_update_default_banner_image
151
176
  return if !user_is_allowed('theme', 'edit')
@@ -166,6 +191,7 @@ module Caboose
166
191
  resp = Caboose::StdClass.new
167
192
  checked = params[:checked]
168
193
  theme_id = params[:id]
194
+ theme = Caboose::Theme.find(theme_id)
169
195
  file_id = params[:file_id]
170
196
  if checked && checked != false && checked != 'false'
171
197
  am = Caboose::ThemeFileMembership.where(:theme_id => theme_id, :theme_file_id => file_id).first
@@ -176,6 +202,10 @@ module Caboose
176
202
  else
177
203
  Caboose::ThemeFileMembership.delete_all(:theme_id => theme_id, :theme_file_id => file_id)
178
204
  end
205
+ file = Caboose::ThemeFile.find(file_id)
206
+ if file && file.filename.include?('.js')
207
+ Rails.env.production? ? theme.delay(:queue => 'general', :priority => 12).upload_js(@site.id) : theme.upload_js(@site.id)
208
+ end
179
209
  resp.success = "Success"
180
210
  render :json => resp
181
211
  end
@@ -26,6 +26,7 @@ module Caboose
26
26
  # @route GET /admin/users/json
27
27
  def admin_json
28
28
  return if !user_is_allowed('users', 'view')
29
+ where2 = @logged_in_user && @logged_in_user.is_allowed('all', 'all') ? "id is not null" : "username is null or (username != 'admin' and username != 'eli' and username != 'elo')"
29
30
  pager = PageBarGenerator.new(params, {
30
31
  'site_id' => @site.id,
31
32
  'first_name_like' => '',
@@ -38,7 +39,7 @@ module Caboose
38
39
  'desc' => false,
39
40
  'base_url' => '/admin/users',
40
41
  'use_url_params' => false,
41
- 'additional_where' => [ "(site_id = #{@site.id})" ]
42
+ 'additional_where' => [ "(site_id = #{@site.id}) AND (#{where2})" ]
42
43
  })
43
44
  render :json => {
44
45
  :pager => pager,
@@ -114,7 +115,7 @@ module Caboose
114
115
  :params => params.to_json,
115
116
  :status => 'pending'
116
117
  )
117
- e.delay(:queue => 'caboose_general', :priority => 8).user_process if Rails.env.production?
118
+ e.delay(:queue => 'general', :priority => 8).user_process if Rails.env.production?
118
119
  e.user_process if Rails.env.development?
119
120
  resp.new_id = e.id
120
121
  resp.success = true
@@ -126,6 +127,14 @@ module Caboose
126
127
  return if !user_is_allowed('users', 'edit')
127
128
  @edituser = get_edit_user(params[:id], @site.id)
128
129
  end
130
+
131
+ # @route GET /admin/users/:id/logs
132
+ def admin_change_logs
133
+ return unless user_is_allowed('logs', 'view')
134
+ @edituser = get_edit_user(params[:id], @site.id)
135
+ mc = "Media Category"
136
+ @logs = ChangeLog.where(:user_id => @edituser.id, :site_id => @site.id).where('(is_field = false and (action = ? OR action = ?)) OR (action != ? and action != ?) OR (is_field = true AND description ILIKE (?))','added','deleted','added','deleted',"%#{mc}%").order('timestamp desc, id desc').limit(500)
137
+ end
129
138
 
130
139
  # @route GET /admin/users/:id/password
131
140
  def admin_edit_password
@@ -212,13 +221,11 @@ module Caboose
212
221
 
213
222
  # @route POST /admin/users
214
223
  def admin_add
215
- return if !user_is_allowed('users', 'add')
216
-
217
- resp = StdClass.new({
218
- 'error' => nil,
219
- 'redirect' => nil
220
- })
221
-
224
+ resp = StdClass.new({'error' => nil,'redirect' => nil})
225
+ if !user_is_allowed_to('add', 'users', true)
226
+ return
227
+ end
228
+
222
229
  user = User.new()
223
230
  user.email = params[:email] ? params[:email].strip.downcase : nil
224
231
  user.site_id = @site.id
@@ -396,7 +403,7 @@ module Caboose
396
403
  token = params[:token]
397
404
  if user.token == params[:token]
398
405
  if logged_in? || logged_in_user.id == User::LOGGED_OUT_USER_ID
399
- Caboose.log(logged_in_user.id)
406
+ # Caboose.log(logged_in_user.id)
400
407
  redirect_to "/logout?return_url=/admin/users/#{params[:id]}/su/#{user.token}"
401
408
  return
402
409
  end
@@ -316,38 +316,38 @@ module Caboose
316
316
  when 'sale_price'
317
317
  variants.each_with_index do |v, i|
318
318
  v.sale_price = value
319
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale if i == 0
319
+ v.product.delay(:run_at => 3.seconds.from_now, :queue => 'general', :priority => 15).update_on_sale if i == 0
320
320
  end
321
321
  when 'date_sale_starts'
322
322
  variants.each_with_index do |v, i|
323
323
  v.date_sale_starts = ModelBinder.update_date(v.date_sale_starts, value, @logged_in_user.timezone)
324
324
  if i == 0
325
- v.product.delay(:run_at => v.date_sale_starts, :queue => 'caboose_store').update_on_sale
326
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
325
+ v.product.delay(:run_at => v.date_sale_starts, :queue => 'general', :priority => 15).update_on_sale
326
+ v.product.delay(:run_at => 3.seconds.from_now, :queue => 'general', :priority => 15).update_on_sale
327
327
  end
328
328
  end
329
329
  when 'time_sale_starts'
330
330
  variants.each_with_index do |v, i|
331
331
  v.date_sale_starts = ModelBinder.update_time(v.date_sale_starts, value, @logged_in_user.timezone)
332
332
  if i == 0
333
- v.product.delay(:run_at => v.date_sale_starts, :queue => 'caboose_store').update_on_sale
334
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
333
+ v.product.delay(:run_at => v.date_sale_starts, :queue => 'general', :priority => 15).update_on_sale
334
+ v.product.delay(:run_at => 3.seconds.from_now, :queue => 'general', :priority => 15).update_on_sale
335
335
  end
336
336
  end
337
337
  when 'date_sale_ends'
338
338
  variants.each_with_index do |v, i|
339
339
  v.date_sale_ends = ModelBinder.update_date(v.date_sale_ends, value, @logged_in_user.timezone)
340
340
  if i == 0
341
- v.product.delay(:run_at => v.date_sale_ends , :queue => 'caboose_store').update_on_sale
342
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
341
+ v.product.delay(:run_at => v.date_sale_ends , :queue => 'general', :priority => 15).update_on_sale
342
+ v.product.delay(:run_at => 3.seconds.from_now, :queue => 'general', :priority => 15).update_on_sale
343
343
  end
344
344
  end
345
345
  when 'time_sale_ends'
346
346
  variants.each_with_index do |v, i|
347
347
  v.date_sale_ends = ModelBinder.update_time(v.date_sale_ends, value, @logged_in_user.timezone)
348
348
  if i == 0
349
- v.product.delay(:run_at => v.date_sale_ends , :queue => 'caboose_store').update_on_sale
350
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
349
+ v.product.delay(:run_at => v.date_sale_ends , :queue => 'general', :priority => 15).update_on_sale
350
+ v.product.delay(:run_at => 3.seconds.from_now, :queue => 'general', :priority => 15).update_on_sale
351
351
  end
352
352
  end
353
353
 
@@ -39,7 +39,11 @@ class Caboose::Block < ActiveRecord::Base
39
39
  :new_parent_id,
40
40
  :new_sort_order,
41
41
  :new_value,
42
- :new_media_id
42
+ :new_media_id,
43
+ :cached_value,
44
+ :cached_css,
45
+ :cached_js,
46
+ :use_cache
43
47
 
44
48
  after_initialize :caste_value
45
49
  before_save :caste_value
@@ -58,6 +62,82 @@ class Caboose::Block < ActiveRecord::Base
58
62
  return self.name if parent_id.nil?
59
63
  return "#{parent.full_name}_#{self.name}"
60
64
  end
65
+
66
+ def cached_ancestor
67
+ begin
68
+ page_or_post = self.page ? self.page : self.post
69
+ content = page_or_post.block.child('content')
70
+ index_page = Caboose::Page.index_page(page_or_post.site_id)
71
+ footer = index_page.block.child('footer')
72
+ return Caboose::Block.cached_ancestor_helper(self, content.id, footer.id)
73
+ rescue
74
+ return nil
75
+ end
76
+ end
77
+
78
+ def self.cached_ancestor_helper(b, content_id, footer_id)
79
+ if b.block_type && b.name.nil? && !b.block_type.is_dynamic && (b.parent_id == content_id || b.parent_id == footer_id)
80
+ return b.id
81
+ elsif b.parent
82
+ return cached_ancestor_helper(b.parent, content_id, footer_id)
83
+ else
84
+ return nil
85
+ end
86
+ end
87
+
88
+ def has_dynamic_descendant
89
+ return Caboose::Block.descendant_helper(self)
90
+ end
91
+
92
+ def self.descendant_helper(block)
93
+ return true if block.block_type.nil? || block.block_type.is_dynamic
94
+ is_dynamic = false
95
+ block.children.where("name is null OR name ILIKE ?","%_column").each do |b|
96
+ is_dynamic = Caboose::Block.descendant_helper(b)
97
+ return true if is_dynamic == true
98
+ end
99
+ return is_dynamic
100
+ end
101
+
102
+ def update_cache
103
+ par = self.parent
104
+ hdd = self.has_dynamic_descendant
105
+ if par && self.block_type && self.name.blank? && !self.block_type.is_dynamic && !hdd
106
+ opts = {
107
+ :view => nil,
108
+ :controller_view_content => nil,
109
+ :modal => false,
110
+ :empty_text => '',
111
+ :editing => false,
112
+ :css => nil,
113
+ :js => nil,
114
+ :csrf_meta_tags => nil,
115
+ :csrf_meta_tags2 => nil,
116
+ :logged_in_user => nil,
117
+ :page => self.page,
118
+ :post => self.post,
119
+ :site => self.page ? self.page.site : self.post.site,
120
+ :is_cache => true,
121
+ :protocol => "https://"
122
+ }
123
+ str = par.render(self, opts)
124
+ host = Rails.env.production? ? "https://#{ActionController::Base.asset_host}" : ""
125
+ self.cached_value = str.blank? ? '' : str.gsub('"/assets/',"\"#{host}/assets/")
126
+ self.use_cache = true
127
+ elsif self.block_type && !self.block_type.is_dynamic && self.children && self.children.count > 0 && hdd # Try caching the children
128
+ self.cached_value = nil
129
+ self.cached_css = nil
130
+ self.cached_js = nil
131
+ self.children.where(:name => nil).each do |child|
132
+ child.delay(:queue => 'caching', :priority => 6).update_cache
133
+ end
134
+ elsif hdd
135
+ self.cached_value = nil
136
+ self.cached_css = nil
137
+ self.cached_js = nil
138
+ end
139
+ self.save
140
+ end
61
141
 
62
142
  def child_value(name)
63
143
  b = self.child(name)
@@ -70,8 +150,6 @@ class Caboose::Block < ActiveRecord::Base
70
150
  return b.media.file if b.media
71
151
  return b.file
72
152
  end
73
- #return b.image if b.block_type.field_type == 'image'
74
- #return b.file if b.block_type.field_type == 'file'
75
153
  return b.value
76
154
  end
77
155
 
@@ -153,11 +231,8 @@ class Caboose::Block < ActiveRecord::Base
153
231
  end
154
232
  end
155
233
 
156
- def render(block, options)
157
- #Caboose.log("block.full_name = #{block.full_name}")
158
- #Caboose.log("block.render\nself.id = #{self.id}\nblock = #{block}\nblock.full_name = #{block.full_name}\noptions.class = #{options.class}\noptions = #{options}")
234
+ def render(block, options)
159
235
  if block && block.is_a?(String)
160
- #Caboose.log("Block #{block} is a string, finding block object... self.id = #{self.id}")
161
236
  b = self.child(block)
162
237
  if b.nil?
163
238
  self.create_children
@@ -181,14 +256,14 @@ class Caboose::Block < ActiveRecord::Base
181
256
  :js => nil,
182
257
  :csrf_meta_tags => nil,
183
258
  :csrf_meta_tags2 => nil,
184
- :logged_in_user => nil
259
+ :logged_in_user => nil,
260
+ :is_cache => false
185
261
  }
186
- #defaults = { :modal => false, :empty_text => '', :editing => false, :css => nil, :js => nil, :block => block }
262
+
187
263
  options2 = nil
188
264
  if options.is_a?(Hash)
189
265
  options2 = defaults.merge(options)
190
266
  else
191
- #options2 = { :modal => options.modal, :empty_text => options.empty_text, :editing => options.editing, :css => options.css, :js => options.js }
192
267
  options2 = {
193
268
  :view => options.view ? options.view : nil,
194
269
  :controller_view_content => options.controller_view_content ? options.controller_view_content : nil,
@@ -199,11 +274,15 @@ class Caboose::Block < ActiveRecord::Base
199
274
  :js => options.js ? options.js : nil,
200
275
  :csrf_meta_tags => options.csrf_meta_tags ? options.csrf_meta_tags : nil,
201
276
  :csrf_meta_tags2 => options.csrf_meta_tags2 ? options.csrf_meta_tags2 : nil,
202
- :logged_in_user => options.logged_in_user ? options.logged_in_user : nil
277
+ :logged_in_user => options.logged_in_user ? options.logged_in_user : nil,
278
+ :is_cache => options.is_cache ? options.is_cache : nil
203
279
  }
204
280
  end
205
281
  options2[:block] = block
206
282
 
283
+ pop = block.page ? block.page : block.post
284
+ return block.cached_value if block && pop && pop.site && pop.site.use_caching && block.use_cache && !block.cached_value.blank? && block.block_type && !block.block_type.is_dynamic && !options2[:is_cache] && (options2[:editing] == false || (pop && pop.is_published))
285
+
207
286
  view = options2[:view]
208
287
  view = ActionView::Base.new(ActionController::Base.view_paths) if view.nil?
209
288
 
@@ -227,7 +306,7 @@ class Caboose::Block < ActiveRecord::Base
227
306
  block.block_type.latest_error = "#{msg}#{ex.message}\n#{ex.backtrace.join("\n")}"
228
307
  block.block_type.save
229
308
  end
230
- end
309
+ end
231
310
  else
232
311
 
233
312
  full_name = block.block_type.full_name
@@ -277,12 +356,9 @@ class Caboose::Block < ActiveRecord::Base
277
356
  return "<p class='note error'>Could not find block view anywhere.</p>" if i > arr.count
278
357
  begin
279
358
  str = view.render(:partial => arr[i], :locals => options)
280
- # Caboose.log("Level #{i+1} for #{full_name}: Found partial #{arr[i]}")
281
- rescue ActionView::MissingTemplate => ex
282
- # Caboose.log("Level #{i+1} for #{full_name}: #{ex.message}")
359
+ rescue ActionView::MissingTemplate => ex
283
360
  str = render_helper(view, options, block, full_name, arr, i+1)
284
- rescue Exception => ex
285
- # Caboose.log("Level #{i+1} for #{full_name}: #{ex.message}")
361
+ rescue Exception => ex
286
362
  str = "<p class='note error'>#{self.block_message(block, ex)}</p>"
287
363
  end
288
364
  return str
@@ -299,8 +375,7 @@ class Caboose::Block < ActiveRecord::Base
299
375
  end
300
376
 
301
377
  def render_from_function(options)
302
- self.create_children
303
- #locals = OpenStruct.new(:block => self, :empty_text => empty_text, :editing => editing)
378
+ self.create_children
304
379
  locals = OpenStruct.new(options)
305
380
  erb = ERB.new(block_type.render_function)
306
381
  return erb.result(locals.instance_eval { binding })
@@ -317,13 +392,13 @@ class Caboose::Block < ActiveRecord::Base
317
392
  :js => nil,
318
393
  :csrf_meta_tags => nil,
319
394
  :csrf_meta_tags2 => nil,
320
- :logged_in_user => nil
395
+ :logged_in_user => nil,
396
+ :is_cache => false
321
397
  }
322
398
  options2 = nil
323
399
  if options.is_a?(Hash)
324
400
  options2 = defaults.merge(options)
325
401
  else
326
- #options2 = { :modal => options.modal, :empty_text => options.empty_text, :editing => options.editing, :css => options.css, :js => options.js }
327
402
  options2 = {
328
403
  :view => options.view ? options.view : nil,
329
404
  :controller_view_content => options.controller_view_content ? options.controller_view_content : nil,
@@ -334,7 +409,8 @@ class Caboose::Block < ActiveRecord::Base
334
409
  :js => options.js ? options.js : nil,
335
410
  :csrf_meta_tags => options.csrf_meta_tags ? options.csrf_meta_tags : nil,
336
411
  :csrf_meta_tags2 => options.csrf_meta_tags2 ? options.csrf_meta_tags2 : nil,
337
- :logged_in_user => options.logged_in_user ? options.logged_in_user : nil
412
+ :logged_in_user => options.logged_in_user ? options.logged_in_user : nil,
413
+ :is_cache => options.is_cache ? options.is_cache : nil
338
414
  }
339
415
  end
340
416
  options2[:block] = self