refinerycms 0.9.8 → 0.9.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/Gemfile +6 -6
  2. data/app/controllers/application_controller.rb +2 -1
  3. data/bin/refinerycms +36 -32
  4. data/changelog.md +471 -0
  5. data/config/environments/production.rb +1 -1
  6. data/db/migrate/20100606135207_change_thumbnail_sizes_for_dragonfly.rb +4 -4
  7. data/db/migrate/20100826232810_move_inquiry_settings_to_refinery_settings.rb +2 -2
  8. data/db/migrate/20100831122919_move_page_to_nested_set.rb +28 -0
  9. data/db/schema.rb +7 -1
  10. data/db/seeds/refinery_settings.rb +2 -4
  11. data/license.md +21 -0
  12. data/readme.md +97 -0
  13. data/todo.md +61 -0
  14. data/vendor/refinerycms/authentication/app/views/admin/users/index.html.erb +5 -13
  15. data/vendor/refinerycms/authentication/app/views/layouts/login.html.erb +1 -1
  16. data/vendor/refinerycms/authentication/config/locales/de.yml +53 -56
  17. data/vendor/refinerycms/authentication/config/locales/en.yml +1 -2
  18. data/vendor/refinerycms/authentication/config/locales/lv.yml +38 -38
  19. data/vendor/refinerycms/authentication/config/locales/pt-BR.yml +21 -48
  20. data/vendor/refinerycms/authentication/features/lost_password.feature +40 -0
  21. data/vendor/refinerycms/authentication/features/manage_users.feature +57 -0
  22. data/vendor/refinerycms/authentication/features/step_definitions/lost_password.rb +8 -0
  23. data/vendor/refinerycms/authentication/features/step_definitions/user_steps.rb +32 -0
  24. data/vendor/refinerycms/authentication/features/support/factories.rb +17 -0
  25. data/vendor/refinerycms/authentication/features/support/paths.rb +24 -0
  26. data/vendor/refinerycms/authentication/lib/authenticated_system.rb +1 -1
  27. data/vendor/refinerycms/authentication/lib/authentication.rb +1 -1
  28. data/vendor/refinerycms/core/app/views/admin/_head.html.erb +4 -4
  29. data/vendor/refinerycms/core/app/views/admin/_menu_tab.html.erb +2 -2
  30. data/vendor/refinerycms/core/app/views/layouts/admin.html.erb +1 -1
  31. data/vendor/refinerycms/core/app/views/layouts/admin_dialog.html.erb +1 -1
  32. data/vendor/refinerycms/core/app/views/shared/_footer.html.erb +1 -1
  33. data/vendor/refinerycms/core/app/views/shared/_google_analytics.html.erb +1 -1
  34. data/vendor/refinerycms/core/app/views/shared/_header.html.erb +1 -1
  35. data/vendor/refinerycms/core/app/views/shared/_menu.html.erb +5 -2
  36. data/vendor/refinerycms/core/app/views/shared/_menu_branch.html.erb +6 -3
  37. data/vendor/refinerycms/core/app/views/shared/_site_bar.html.erb +11 -15
  38. data/vendor/refinerycms/core/app/views/shared/admin/_form_actions.html.erb +1 -0
  39. data/vendor/refinerycms/core/app/views/shared/admin/_image_picker.html.erb +3 -3
  40. data/vendor/refinerycms/core/app/views/shared/admin/_make_sortable.html.erb +2 -1
  41. data/vendor/refinerycms/core/app/views/shared/admin/_resource_picker.html.erb +24 -17
  42. data/vendor/refinerycms/core/app/views/wymiframe.html.erb +1 -1
  43. data/vendor/refinerycms/core/config/locales/de.yml +50 -51
  44. data/vendor/refinerycms/core/config/locales/en.yml +5 -2
  45. data/vendor/refinerycms/core/config/locales/lv.yml +6 -3
  46. data/vendor/refinerycms/core/config/locales/pt-BR.yml +34 -38
  47. data/vendor/refinerycms/core/crud.md +12 -12
  48. data/vendor/refinerycms/core/features/engine_generator.feature +27 -0
  49. data/vendor/refinerycms/core/features/search.feature +56 -0
  50. data/vendor/refinerycms/core/features/site_bar.feature +24 -0
  51. data/vendor/refinerycms/core/features/step_definitions/core_steps.rb +61 -0
  52. data/vendor/refinerycms/core/features/step_definitions/engine_generator_steps.rb +19 -0
  53. data/vendor/refinerycms/core/features/step_definitions/generator_steps.rb +11 -0
  54. data/vendor/refinerycms/core/features/support/paths.rb +14 -0
  55. data/vendor/refinerycms/core/features/uploads/beach.jpeg +0 -0
  56. data/vendor/refinerycms/core/features/uploads/refinery_is_awesome.txt +1 -0
  57. data/vendor/refinerycms/core/lib/core.rb +52 -53
  58. data/vendor/refinerycms/core/lib/generators/refinery_engine/refinery_engine_generator.rb +14 -3
  59. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/controllers/admin/plural_name_controller.rb +3 -1
  60. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/models/singular_name.rb +4 -3
  61. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/views/admin/plural_name/_form.html.erb +2 -1
  62. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/views/admin/plural_name/_singular_name.html.erb +6 -2
  63. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/views/plural_name/index.html.erb +3 -1
  64. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/views/plural_name/show.html.erb +7 -3
  65. data/vendor/refinerycms/core/lib/refinery/application_controller.rb +85 -75
  66. data/vendor/refinerycms/core/lib/refinery/application_helper.rb +10 -190
  67. data/vendor/refinerycms/core/lib/refinery/crud.rb +283 -0
  68. data/vendor/refinerycms/core/lib/refinery/{form_helpers.rb → helpers/form_helper.rb} +0 -0
  69. data/vendor/refinerycms/core/lib/refinery/helpers/html_truncation_helper.rb +26 -0
  70. data/vendor/refinerycms/core/lib/refinery/helpers/image_helper.rb +37 -0
  71. data/vendor/refinerycms/core/lib/refinery/helpers/menu_helper.rb +38 -0
  72. data/vendor/refinerycms/core/lib/refinery/helpers/meta_helper.rb +67 -0
  73. data/vendor/refinerycms/core/lib/refinery/helpers/script_helper.rb +36 -0
  74. data/vendor/refinerycms/core/lib/refinery/helpers/site_bar_helper.rb +26 -0
  75. data/vendor/refinerycms/core/lib/refinery/helpers/tag_helper.rb +19 -0
  76. data/vendor/refinerycms/core/lib/refinery/helpers/translation_helper.rb +17 -0
  77. data/vendor/refinerycms/core/lib/refinery/plugin.rb +3 -3
  78. data/vendor/refinerycms/core/lib/tasks/refinery.rake +4 -3
  79. data/vendor/refinerycms/core/public/javascripts/refinery/admin.js +93 -101
  80. data/vendor/refinerycms/core/public/javascripts/refinery/core.js +3 -0
  81. data/vendor/refinerycms/core/public/javascripts/refinery/nestedsortables.js +164 -0
  82. data/vendor/refinerycms/core/public/javascripts/refinery/serializelist.js +66 -0
  83. data/vendor/refinerycms/core/public/stylesheets/refinery/refinery.css +11 -73
  84. data/vendor/refinerycms/dashboard/config/locales/de.yml +6 -6
  85. data/vendor/refinerycms/dashboard/config/locales/pt-BR.yml +3 -5
  86. data/vendor/refinerycms/dashboard/features/dashboard.feature +54 -0
  87. data/vendor/refinerycms/dashboard/features/support/paths.rb +14 -0
  88. data/vendor/refinerycms/images/app/controllers/admin/images_controller.rb +6 -6
  89. data/vendor/refinerycms/images/app/helpers/admin/images_helper.rb +1 -1
  90. data/vendor/refinerycms/images/app/views/admin/images/_existing_image.html.erb +15 -13
  91. data/vendor/refinerycms/images/app/views/admin/images/_grid_view.html.erb +1 -1
  92. data/vendor/refinerycms/images/app/views/admin/images/_list_view_image.html.erb +1 -1
  93. data/vendor/refinerycms/images/config/locales/de.yml +21 -25
  94. data/vendor/refinerycms/images/config/locales/pt-BR.yml +13 -23
  95. data/vendor/refinerycms/images/features/manage_images.feature +48 -0
  96. data/vendor/refinerycms/images/features/step_definitions/image_steps.rb +37 -0
  97. data/vendor/refinerycms/images/features/support/paths.rb +17 -0
  98. data/vendor/refinerycms/images/features/uploads/beach.jpeg +0 -0
  99. data/vendor/refinerycms/images/features/uploads/id-rather-be-here.jpg +0 -0
  100. data/vendor/refinerycms/images/features/uploads/refinery_is_awesome.txt +1 -0
  101. data/vendor/refinerycms/images/lib/images.rb +6 -0
  102. data/vendor/refinerycms/images/readme.md +12 -36
  103. data/vendor/refinerycms/pages/app/controllers/admin/pages_controller.rb +4 -42
  104. data/vendor/refinerycms/pages/app/controllers/pages_controller.rb +1 -1
  105. data/vendor/refinerycms/pages/app/models/page.rb +3 -4
  106. data/vendor/refinerycms/pages/app/sweepers/page_sweeper.rb +18 -0
  107. data/vendor/refinerycms/pages/app/views/admin/pages/_form_advanced_options.html.erb +1 -1
  108. data/vendor/refinerycms/pages/app/views/admin/pages/_page.html.erb +6 -5
  109. data/vendor/refinerycms/pages/config/locales/de.yml +66 -36
  110. data/vendor/refinerycms/pages/config/locales/pt-BR.yml +29 -57
  111. data/vendor/refinerycms/pages/features/manage_pages.feature +45 -0
  112. data/vendor/refinerycms/pages/features/step_definitions/page_steps.rb +29 -0
  113. data/vendor/refinerycms/pages/features/support/paths.rb +18 -0
  114. data/vendor/refinerycms/pages/lib/pages.rb +5 -0
  115. data/vendor/refinerycms/pages/spec/models/page_spec.rb +13 -0
  116. data/vendor/refinerycms/refinery.rb +1 -1
  117. data/vendor/refinerycms/resources/app/views/admin/resources/_existing_resource.html.erb +2 -2
  118. data/vendor/refinerycms/resources/config/locales/de.yml +16 -17
  119. data/vendor/refinerycms/resources/config/locales/pt-BR.yml +15 -17
  120. data/vendor/refinerycms/resources/features/manage_files.feature +39 -0
  121. data/vendor/refinerycms/resources/features/step_definitions/file_steps.rb +21 -0
  122. data/vendor/refinerycms/resources/features/support/paths.rb +17 -0
  123. data/vendor/refinerycms/resources/features/uploads/beach.jpeg +0 -0
  124. data/vendor/refinerycms/resources/features/uploads/refinery_is_awesome.txt +1 -0
  125. data/vendor/refinerycms/resources/lib/resources.rb +17 -1
  126. data/vendor/refinerycms/settings/app/models/refinery_setting.rb +82 -64
  127. data/vendor/refinerycms/settings/config/locales/de.yml +36 -16
  128. data/vendor/refinerycms/settings/config/locales/pt-BR.yml +32 -34
  129. data/vendor/refinerycms/settings/features/manage_refinery_settings.feature +5 -0
  130. data/vendor/refinerycms/settings/lib/settings.rb +1 -1
  131. metadata +86 -53
  132. data/vendor/refinerycms/core/lib/crud.rb +0 -265
  133. data/vendor/refinerycms/core/lib/refinery/html_truncation_helper.rb +0 -22
  134. data/vendor/refinerycms/core/public/javascripts/jquery/jquery.nestedsortables.js +0 -186
@@ -1,5 +1,7 @@
1
1
  class Admin::<%= class_name.pluralize %>Controller < Admin::BaseController
2
2
 
3
- crudify :<%= singular_name %>, :title_attribute => :<%= attributes.first.name %>
3
+ crudify :<%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? and title.name != 'title' %>
4
+ , :title_attribute => '<%= title.name %>'
5
+ <% end %>
4
6
 
5
7
  end
@@ -1,9 +1,10 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
2
 
3
3
  acts_as_indexed :fields => [:<%= attributes.collect{ |attribute| attribute.name if attribute.type.to_s =~ /string|text/ }.compact.uniq.join(", :") %>]
4
-
5
- validates_presence_of :<%= attributes.first.name %>
6
- validates_uniqueness_of :<%= attributes.first.name %>
4
+ <% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
5
+ validates_presence_of :<%= title.name %>
6
+ validates_uniqueness_of :<%= title.name %>
7
+ <% end -%>
7
8
 
8
9
  <% attributes.collect{|a| a if a.type.to_s == 'image'}.compact.uniq.each do |a| -%>
9
10
  belongs_to :<%= a.name.gsub("_id", "") %><%= ", :class_name => 'Image'" unless a.name =~ /^image(_id)?$/ %>
@@ -30,6 +30,7 @@
30
30
  :locals => {
31
31
  :f => f,
32
32
  :continue_editing => false,
33
- :delete_title => t('admin.<%= plural_name %>.<%= singular_name %>.delete')
33
+ :delete_title => t('admin.<%= plural_name %>.<%= singular_name %>.delete'),
34
+ :delete_confirmation => t('shared.admin.delete.message'<% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>, :title => @<%= singular_name %>.<%= title.name %><% end %>)
34
35
  } %>
35
36
  <%% end -%>
@@ -1,6 +1,6 @@
1
1
  <li class='clearfix record <%%= cycle("on", "on-hover") %>' id="<%%= dom_id(<%= singular_name %>) -%>">
2
2
  <span class='title'>
3
- <%%= <%= singular_name %>.<%= attributes.first.name %> %>
3
+ <%%= <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? -%>.<%= title.name %><% end %> %>
4
4
  <span class="preview">&nbsp;</span>
5
5
  </span>
6
6
  <span class='actions'>
@@ -11,6 +11,10 @@
11
11
  :title => t('.edit') %>
12
12
  <%%= link_to refinery_icon_tag("delete.png"), admin_<%= singular_name %>_path(<%= singular_name %>),
13
13
  :class => "cancel confirm-delete",
14
- :title => t('.delete') %>
14
+ :title => t('.delete'),
15
+ :'data-confirm' => t('shared.admin.delete.message'<% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>,
16
+ :title => <%= singular_name %>.<%= title.name %>
17
+ <% end %>),
18
+ :'data-method' => :delete %>
15
19
  </span>
16
20
  </li>
@@ -2,7 +2,9 @@
2
2
  <ul id="<%= plural_name %>">
3
3
  <%% @<%= plural_name %>.each do |<%= singular_name %>| %>
4
4
  <li>
5
- <%%= link_to <%= singular_name %>.<%= attributes.first.name %>, <%= singular_name %>_url(<%= singular_name %>) %>
5
+ <%%= link_to <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
6
+ .<%= title.name %>
7
+ <% end %>, <%= singular_name %>_url(<%= singular_name %>) %>
6
8
  </li>
7
9
  <%% end %>
8
10
  </ul>
@@ -1,5 +1,7 @@
1
1
  <%% content_for :body_content_title do %>
2
- <%%= @<%= singular_name %>.<%= attributes.first.name %> %>
2
+ <%%= @<%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
3
+ .<%= title.name %>
4
+ <% end %> %>
3
5
  <%% end %>
4
6
 
5
7
  <%% content_for :body_content_left do %>
@@ -11,7 +13,7 @@
11
13
  <% elsif attribute.type.to_s == 'resource' -%>
12
14
  <%%= link_to <%= "'#{attribute.name}'" %>, @<%= singular_name %>.<%= attribute.name %>.url %>
13
15
  <% else -%>
14
- <%%= @<%= singular_name %>.<%= attribute.name %> %>
16
+ <%%=raw @<%= singular_name %>.<%= attribute.name %> %>
15
17
  <% end -%>
16
18
  </div>
17
19
  <% end %>
@@ -22,7 +24,9 @@
22
24
  <ul id="<%= plural_name %>">
23
25
  <%% @<%= plural_name %>.each do |<%= singular_name %>| %>
24
26
  <li>
25
- <%%= link_to <%= singular_name %>.<%= attributes.first.name %>, <%= singular_name %>_url(<%= singular_name %>) %>
27
+ <%%= link_to <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
28
+ .<%= title.name %>
29
+ <% end %>, <%= singular_name %>_url(<%= singular_name %>) %>
26
30
  </li>
27
31
  <%% end %>
28
32
  </ul>
@@ -1,101 +1,111 @@
1
1
  require 'action_controller'
2
2
 
3
- class Refinery::ApplicationController < ActionController::Base
3
+ module Refinery::ApplicationController
4
4
 
5
- helper_method :home_page?,
6
- :local_request?,
7
- :just_installed?,
8
- :from_dialog?,
9
- :admin?,
10
- :login?
5
+ def self.included(controller)
6
+ controller.send :include, InstanceMethods
7
+ controller.send :include, ClassMethods
8
+ end
11
9
 
12
- protect_from_forgery # See ActionController::RequestForgeryProtection
10
+ module ClassMethods
11
+ def self.included(c) # Extend controller
12
+ c.helper_method :home_page?,
13
+ :local_request?,
14
+ :just_installed?,
15
+ :from_dialog?,
16
+ :admin?,
17
+ :login?
13
18
 
14
- include Crud # basic create, read, update and delete methods
15
- include AuthenticatedSystem
19
+ c.protect_from_forgery # See ActionController::RequestForgeryProtection
16
20
 
17
- before_filter :find_pages_for_menu,
18
- :show_welcome_page?
21
+ c.send :include, Crud # basic create, read, update and delete methods
22
+ c.send :include, AuthenticatedSystem
19
23
 
20
- after_filter :store_current_location!,
21
- :if => Proc.new {|c| c.send(:refinery_user?) rescue false }
24
+ c.send :before_filter, :find_pages_for_menu,
25
+ :show_welcome_page?
22
26
 
23
- rescue_from ActiveRecord::RecordNotFound,
24
- ActionController::UnknownAction,
25
- ActionView::MissingTemplate,
26
- :with => :error_404
27
+ c.send :after_filter, :store_current_location!,
28
+ :if => Proc.new {|c| c.send(:refinery_user?) rescue false }
27
29
 
28
- def admin?
29
- controller_name =~ %r{^admin/}
30
+ c.send :rescue_from, ActiveRecord::RecordNotFound,
31
+ ActionController::UnknownAction,
32
+ ActionView::MissingTemplate,
33
+ :with => :error_404
34
+ end
30
35
  end
31
36
 
32
- def error_404(exception=nil)
33
- if (@page = Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
34
- # render the application's custom 404 page with layout and meta.
35
- render :template => "/pages/show",
36
- :format => 'html',
37
- :status => 404
38
- else
39
- # fallback to the default 404.html page.
40
- file = Rails.root.join('public', '404.html')
41
- file = Refinery.root.join('vendor', 'refinerycms', 'core', 'public', '404.html') unless file.exist?
42
- render :file => file.cleanpath.to_s,
43
- :layout => false,
44
- :status => 404
37
+ module InstanceMethods
38
+ def admin?
39
+ controller_name =~ %r{^admin/}
45
40
  end
46
- end
47
41
 
48
- def from_dialog?
49
- params[:dialog] == "true" or params[:modal] == "true"
50
- end
42
+ def error_404(exception=nil)
43
+ if (@page = Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
44
+ # render the application's custom 404 page with layout and meta.
45
+ render :template => "/pages/show",
46
+ :format => 'html',
47
+ :status => 404
48
+ else
49
+ # fallback to the default 404.html page.
50
+ file = Rails.root.join('public', '404.html')
51
+ file = Refinery.root.join('vendor', 'refinerycms', 'core', 'public', '404.html') unless file.exist?
52
+ render :file => file.cleanpath.to_s,
53
+ :layout => false,
54
+ :status => 404
55
+ end
56
+ end
51
57
 
52
- def home_page?
53
- root_url(:only_path => true) == request.path
54
- end
58
+ def from_dialog?
59
+ params[:dialog] == "true" or params[:modal] == "true"
60
+ end
55
61
 
56
- def just_installed?
57
- Role[:refinery].users.empty?
58
- end
62
+ def home_page?
63
+ root_url(:only_path => true) == request.path
64
+ end
59
65
 
60
- def local_request?
61
- Rails.env.development? or request.remote_ip =~ /(::1)|(127.0.0.1)|((192.168).*)/
62
- end
66
+ def just_installed?
67
+ Role[:refinery].users.empty?
68
+ end
63
69
 
64
- def login?
65
- (controller_name =~ /^(user|session)(|s)/ and not admin?) or just_installed?
66
- end
70
+ def local_request?
71
+ Rails.env.development? or request.remote_ip =~ /(::1)|(127.0.0.1)|((192.168).*)/
72
+ end
67
73
 
68
- protected
74
+ def login?
75
+ (controller_name =~ /^(user|session)(|s)/ and not admin?) or just_installed?
76
+ end
69
77
 
70
- # get all the pages to be displayed in the site menu.
71
- def find_pages_for_menu
72
- @menu_pages = Page.top_level
73
- end
78
+ protected
74
79
 
75
- # use a different model for the meta information.
76
- def present(model)
77
- presenter = (Object.const_get("#{model.class}Presenter") rescue ::Refinery::BasePresenter)
78
- @meta = presenter.new(model)
79
- end
80
+ # get all the pages to be displayed in the site menu.
81
+ def find_pages_for_menu
82
+ @menu_pages = Page.top_level
83
+ end
80
84
 
81
- # this hooks into the Rails render method.
82
- def render(action = nil, options = {}, &blk)
83
- present(@page) unless admin? or @meta.present?
84
- super
85
- end
85
+ # use a different model for the meta information.
86
+ def present(model)
87
+ presenter = (Object.const_get("#{model.class}Presenter") rescue ::Refinery::BasePresenter)
88
+ @meta = presenter.new(model)
89
+ end
86
90
 
87
- def show_welcome_page?
88
- render :template => "/welcome", :layout => "login" if just_installed? and controller_name != "users"
89
- end
91
+ # this hooks into the Rails render method.
92
+ def render(action = nil, options = {}, &blk)
93
+ present(@page) unless admin? or @meta.present?
94
+ super
95
+ end
90
96
 
91
- private
92
- def store_current_location!
93
- if admin?
94
- # ensure that we don't redirect to AJAX or POST/PUT/DELETE urls
95
- session[:refinery_return_to] = request.path if request.get? and !request.xhr? and !from_dialog?
96
- elsif defined?(@page) and @page.present?
97
- session[:website_return_to] = @page.url
97
+ def show_welcome_page?
98
+ render :template => "/welcome", :layout => "login" if just_installed? and controller_name != "users"
98
99
  end
99
- end
100
100
 
101
+ private
102
+ def store_current_location!
103
+ if admin?
104
+ # ensure that we don't redirect to AJAX or POST/PUT/DELETE urls
105
+ session[:refinery_return_to] = request.path if request.get? and !request.xhr? and !from_dialog?
106
+ elsif defined?(@page) and @page.present?
107
+ session[:website_return_to] = @page.url
108
+ end
109
+ end
110
+ end
101
111
  end
@@ -1,195 +1,15 @@
1
1
  # Methods added to this helper will be available to all templates in the application.
2
+ Dir[File.expand_path('../helpers/*.rb', __FILE__).to_s].each {|helper| require helper}
3
+
2
4
  module Refinery
3
5
  module ApplicationHelper
4
- include Refinery::HtmlTruncationHelper
5
-
6
- def t(key, options = {})
7
- if (val = super) =~ /class.+?translation_missing/
8
- val = val.to_s.gsub(/<span[^>]*>/, 'i18n: ').gsub('</span>', '').gsub(', ', '.')
9
- end
10
-
11
- val
12
- end
13
-
14
- # This is used to display the title of the current object (normally a page) in the browser's titlebar.
15
- #
16
- def browser_title(yield_title=nil)
17
- [
18
- yield_title.present? ? yield_title : nil,
19
- @meta.browser_title.present? ? @meta.browser_title : @meta.path,
20
- RefinerySetting.find_or_set(:site_name, "Company Name")
21
- ].compact.join(" - ")
22
- end
23
-
24
- # replace all system images with a thumbnail version of them (handy for all images inside a page part)
25
- # for example, <%= content_fu(@page[:body], :preview) %> converts all /system/images to their 'preview' thumbnail
26
- def content_fu(content, thumbnail)
27
- raise NotImplementedError # todo: implement for new syntax.
28
-
29
- content.scan(/\/system\/images([^\"\ ]*)/).flatten.each do |match|
30
- parts = match.split(".")
31
- extension = parts.pop
32
- content.gsub!(match, "#{parts.join(".")}_#{thumbnail}.#{extension}")
33
- end unless content.blank?
34
-
35
- return content
36
- end
37
-
38
- # This was extracted from REFINERY_ROOT/vendor/plugins/refinery/app/views/shared/_menu_branch.html.erb
39
- # to remove the complexity of that template by reducing logic in the view.
40
- def css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count = nil)
41
- css = []
42
- css << "selected" if selected_page?(menu_branch) or descendant_page_selected?(menu_branch)
43
- css << "first" if menu_branch_counter == 0
44
- css << "last" if menu_branch_counter == (sibling_count ||= menu_branch.shown_siblings.size)
45
- css
46
- end
47
-
48
- # Determines whether any page underneath the supplied page is the current page according to rails.
49
- # Just calls selected_page? for each descendant of the supplied page.
50
- def descendant_page_selected?(page)
51
- page.descendants.any? {|descendant| selected_page?(descendant) }
52
- end
53
-
54
- # image_fu is a helper for inserting an image that has been uploaded into a template.
55
- # Say for example that we had a @model.image (@model having a belongs_to :image relationship)
56
- # and we wanted to display a thumbnail cropped to 200x200 then we can use image_fu like this:
57
- # <%= image_fu @model.image, '200x200' %> or with no thumbnail: <%= image_fu @model.image %>
58
- def image_fu(image, geometry = nil, options={})
59
- if image.present?
60
- # call rails' image tag function with default alt, width and height options.
61
- # if any other options were supplied these are merged in and can replace the defaults.
62
- image_tag((thumbnail = image.thumbnail(geometry)).url, {
63
- :alt => image.respond_to?(:title) ? image.title : image.image_name,
64
- :width => thumbnail.width,
65
- :height => thumbnail.height
66
- }.merge(options))
67
- end
68
- end
69
-
70
- # This function helps when including both the jquery and jqueryui libraries.
71
- # If you use this function then whenever we update or relocate the version of jquery or jquery ui in use
72
- # we will update the reference here and your existing application starts to use it.
73
- # Use <%= jquery_include_tags %> to include it in your <head> section.
74
- def jquery_include_tags(options={})
75
- # Merge in options
76
- options = {
77
- :caching => RefinerySetting.find_or_set(:use_resource_caching, Rails.root.writable?),
78
- :google => RefinerySetting.find_or_set(:use_google_ajax_libraries, false),
79
- :jquery_ui => true
80
- }.merge(options)
81
-
82
- # render the tags normally unless
83
- unless options[:google] and !local_request?
84
- if options[:jquery_ui]
85
- javascript_include_tag "jquery#{"-min" if Rails.env.production?}", "jquery-ui-custom-min",
86
- :cache => (options[:caching] ? "cache/jquery" : nil)
87
- else
88
- javascript_include_tag "jquery#{"-min" if Rails.env.production?}"
89
- end
90
- else
91
- "#{javascript_include_tag("http://www.google.com/jsapi").gsub(".js", "")}
92
- <script type='text/javascript'>
93
- google.load('jquery', '1.4');
94
- #{"google.load('jqueryui', '1.8');" if options[:jquery_ui]}
95
- </script>".html_safe
96
- end
97
- end
98
-
99
- # you can override the object used for the title by supplying options[:object]
100
- # this object must support custom_title_type if you want custom titles.
101
- def page_title(options = {})
102
- object = options.fetch(:object, @meta)
103
- options.delete(:object)
104
- options = RefinerySetting.find_or_set(:page_title, {
105
- :chain_page_title => false,
106
- :ancestors => {
107
- :separator => " | ",
108
- :class => 'ancestors',
109
- :tag => 'span'
110
- },
111
- :page_title => {
112
- :class => nil,
113
- :tag => nil,
114
- :wrap_if_not_chained => false
115
- }
116
- }).merge(options)
117
-
118
- title = []
119
- objects = (options[:chain_page_title] and object.respond_to?(:ancestors)) ? [object.ancestors, object] : [object]
120
-
121
- objects.flatten.compact.each do |obj|
122
- if obj.respond_to?(:custom_title_type)
123
- title << case obj.custom_title_type
124
- when "text"
125
- obj.custom_title
126
- when "image"
127
- image_fu(obj.custom_title_image, nil, {:alt => obj.title}) rescue obj.title
128
- else
129
- obj.title
130
- end
131
- else
132
- title << obj.title
133
- end
134
- end
135
-
136
- final_title = title.pop
137
- if (options[:page_title][:wrap_if_not_chained] and title.empty?) and options[:page_title][:tag].present?
138
- css = options[:page_title][:class].present? ? " class='#{options[:page_title][:class]}'" : nil
139
- final_title = "<#{options[:page_title][:tag]}#{css}>#{final_title}</#{options[:page_title][:tag]}>"
140
- end
141
-
142
- if title.empty?
143
- return final_title.to_s.html_safe
144
- else
145
- return "<#{options[:ancestors][:tag]} class='#{options[:ancestors][:class]}'>#{title.join options[:ancestors][:separator]}#{options[:ancestors][:separator]}</#{options[:ancestors][:tag]}>#{final_title}".html_safe
146
- end
147
- end
148
-
149
- # Returns <span class='help' title='Your Input'>(help)</span>
150
- # Remember to wrap your block with <span class='label_with_help'></span> if you're using a label next to the help tag.
151
- def refinery_help_tag(title='')
152
- "<span class='help' title='#{title}'>(#{t('shared.admin.help')})</span>".html_safe
153
- end
154
-
155
- # This is just a quick wrapper to render an image tag that lives inside refinery/icons.
156
- # They are all 16x16 so this is the default but is able to be overriden with supplied options.
157
- def refinery_icon_tag(filename, options = {})
158
- image_tag "refinery/icons/#{filename}", {:width => 16, :height => 16}.merge(options)
159
- end
160
-
161
- # Determine whether the supplied page is the currently open page according to Rails.
162
- def selected_page?(page)
163
- # ensure we match the path without the locale.
164
- path = request.path
165
- if defined?(::Refinery::I18n) and ::Refinery::I18n.enabled?
166
- path = path.split("/#{::I18n.locale}").last
167
- end
168
-
169
- current_page?(page) or
170
- (path =~ Regexp.new(page.menu_match) if page.menu_match.present?) or
171
- (path == page.link_url) or
172
- (path == page.nested_path)
173
- end
174
-
175
- # Generates the link to determine where the site bar switch button returns to.
176
- def site_bar_switch_link
177
- link_to_if(admin?, t('.switch_to_your_website'),
178
- (if session.keys.include?(:website_return_to) and session[:website_return_to].present?
179
- session[:website_return_to]
180
- else
181
- root_url(:only_path => true)
182
- end)) do
183
- link_to t('.switch_to_your_website_editor'),
184
- (if session.keys.include?(:refinery_return_to) and session[:refinery_return_to].present?
185
- session[:refinery_return_to]
186
- elsif defined?(@page) and @page.present? and !@page.home?
187
- edit_admin_page_url(@page, :only_path => true)
188
- else
189
- (request.fullpath.to_s == '/') ? admin_root_url(:only_path => true) : "/admin#{request.request_uri}/edit"
190
- end rescue admin_root_url(:only_path => true))
191
- end
192
- end
193
-
6
+ include Refinery::Helpers::HtmlTruncationHelper
7
+ include Refinery::Helpers::ImageHelper
8
+ include Refinery::Helpers::MenuHelper
9
+ include Refinery::Helpers::MetaHelper
10
+ include Refinery::Helpers::ScriptHelper
11
+ include Refinery::Helpers::SiteBarHelper
12
+ include Refinery::Helpers::TagHelper
13
+ include Refinery::Helpers::TranslationHelper
194
14
  end
195
15
  end