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
@@ -0,0 +1,283 @@
1
+ # Base methods for CRUD actions
2
+ # Simply override any methods in your action controller you want to be customised
3
+ # Don't forget to add:
4
+ # resources :plural_model_name_here
5
+ # to your routes.rb file.
6
+ # Full documentation about CRUD and resources go here:
7
+ # -> http://caboo.se/doc/classes/ActionController/Resources.html#M003716
8
+ # Example (add to your controller):
9
+ # crudify :foo, {:title_attribute => 'name'}
10
+
11
+ module Refinery
12
+ module Crud
13
+
14
+ def self.append_features(base)
15
+ super
16
+ base.extend(ClassMethods)
17
+ end
18
+
19
+ module ClassMethods
20
+
21
+ def crudify(model_name, new_options = {})
22
+ singular_name = model_name.to_s
23
+ class_name = singular_name.camelize
24
+ plural_name = singular_name.pluralize
25
+
26
+ options = {
27
+ :title_attribute => "title",
28
+ :order => 'position ASC',
29
+ :conditions => '',
30
+ :sortable => true,
31
+ :searchable => true,
32
+ :include => [],
33
+ :paging => true,
34
+ :search_conditions => '',
35
+ :redirect_to_url => "admin_#{plural_name}_url"
36
+ }.merge!(new_options)
37
+
38
+ module_eval %(
39
+ prepend_before_filter :find_#{singular_name},
40
+ :only => [:update, :destroy, :edit, :show]
41
+
42
+ def new
43
+ @#{singular_name} = #{class_name}.new
44
+ end
45
+
46
+ def create
47
+ # if the position field exists, set this object as last object, given the conditions of this class.
48
+ if #{class_name}.column_names.include?("position")
49
+ params[:#{singular_name}].merge!({
50
+ :position => ((#{class_name}.maximum(:position, :conditions => "#{options[:conditions]}")||-1) + 1)
51
+ })
52
+ end
53
+
54
+ if (@#{singular_name} = #{class_name}.create(params[:#{singular_name}])).valid?
55
+ unless request.xhr?
56
+ flash[:notice] = t('refinery.crudify.created',
57
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
58
+ else
59
+ flash.now[:notice] = t('refinery.crudify.created',
60
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
61
+ end
62
+ unless from_dialog?
63
+ unless params[:continue_editing] =~ /true|on|1/
64
+ redirect_back_or_default(#{options[:redirect_to_url]})
65
+ else
66
+ unless request.xhr?
67
+ redirect_to :back
68
+ else
69
+ render :partial => "/shared/message"
70
+ end
71
+ end
72
+ else
73
+ render :text => "<script type='text/javascript'>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
74
+ end
75
+ else
76
+ unless request.xhr?
77
+ render :action => 'new'
78
+ else
79
+ render :partial => "/shared/admin/error_messages",
80
+ :locals => {
81
+ :object => @#{singular_name},
82
+ :include_object_name => true
83
+ }
84
+ end
85
+ end
86
+ end
87
+
88
+ def edit
89
+ # object gets found by find_#{singular_name} function
90
+ end
91
+
92
+ def update
93
+ if @#{singular_name}.update_attributes(params[:#{singular_name}])
94
+ unless request.xhr?
95
+ flash[:notice] = t('refinery.crudify.updated',
96
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
97
+ else
98
+ flash.now[:notice] = t('refinery.crudify.updated',
99
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
100
+ end
101
+ unless from_dialog?
102
+ unless params[:continue_editing] =~ /true|on|1/
103
+ redirect_back_or_default(#{options[:redirect_to_url]})
104
+ else
105
+ unless request.xhr?
106
+ redirect_to :back
107
+ else
108
+ render :partial => "/shared/message"
109
+ end
110
+ end
111
+ else
112
+ render :text => "<script type='text/javascript'>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
113
+ end
114
+ else
115
+ unless request.xhr?
116
+ render :action => 'edit'
117
+ else
118
+ render :partial => "/shared/admin/error_messages",
119
+ :locals => {
120
+ :object => @#{singular_name},
121
+ :include_object_name => true
122
+ }
123
+ end
124
+ end
125
+ end
126
+
127
+ def destroy
128
+ if @#{singular_name}.destroy
129
+ flash[:notice] = t('refinery.crudify.destroyed',
130
+ :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
131
+ end
132
+ redirect_to #{options[:redirect_to_url]}
133
+ end
134
+
135
+ def find_#{singular_name}
136
+ @#{singular_name} = #{class_name}.find(params[:id],
137
+ :include => %w(#{options[:include].join(' ')}))
138
+ end
139
+
140
+ def find_all_#{plural_name}
141
+ @#{plural_name} = #{class_name}.find(
142
+ :all,
143
+ :order => "#{options[:order]}",
144
+ :conditions => "#{options[:conditions]}",
145
+ :include => %w(#{options[:include].join(' ')})
146
+ )
147
+ end
148
+
149
+ def paginate_all_#{plural_name}
150
+ @#{plural_name} = #{class_name}.paginate(
151
+ :page => params[:page],
152
+ :order => "#{options[:order]}",
153
+ :conditions => "#{options[:conditions]}",
154
+ :include => %w(#{options[:include].join(' ')})
155
+ )
156
+ end
157
+
158
+ def search_all_#{plural_name}
159
+ @#{plural_name} = #{class_name}.with_query(params[:search]).find(
160
+ :all,
161
+ :order => "#{options[:order]}",
162
+ :conditions => "#{options[:search_conditions]}",
163
+ :include => %w(#{options[:include].join(' ')})
164
+ )
165
+ end
166
+
167
+ def search_and_paginate_all_#{plural_name}
168
+ @#{plural_name} = #{class_name}.with_query(params[:search]).paginate(
169
+ :page => params[:page],
170
+ :order => "#{options[:order]}",
171
+ :conditions => "#{options[:search_conditions]}",
172
+ :include => %w(#{options[:include].join(' ')})
173
+ )
174
+ end
175
+
176
+ protected :find_#{singular_name},
177
+ :find_all_#{plural_name},
178
+ :paginate_all_#{plural_name},
179
+ :search_all_#{plural_name},
180
+ :search_and_paginate_all_#{plural_name}
181
+
182
+ )
183
+
184
+ if options[:searchable]
185
+ if options[:paging]
186
+ module_eval %(
187
+ def index
188
+ if searching?
189
+ search_and_paginate_all_#{plural_name}
190
+ else
191
+ paginate_all_#{plural_name}
192
+ end
193
+ end
194
+ )
195
+ else
196
+ module_eval %(
197
+ def index
198
+ if searching?
199
+ search_all_#{plural_name}
200
+ else
201
+ find_all_#{plural_name}
202
+ end
203
+ end
204
+ )
205
+ end
206
+
207
+ else
208
+ if options[:paging]
209
+ module_eval %(
210
+ def index
211
+ paginate_all_#{plural_name}
212
+ end
213
+ )
214
+ else
215
+ module_eval %(
216
+ def index
217
+ find_all_#{plural_name}
218
+ end
219
+ )
220
+ end
221
+
222
+ end
223
+
224
+ if options[:sortable]
225
+ module_eval %(
226
+ def reorder
227
+ find_all_#{plural_name}
228
+ end
229
+
230
+ # Based upon http://github.com/matenia/jQuery-Awesome-Nested-Set-Drag-and-Drop
231
+ def update_positions
232
+ newlist = params[:ul]
233
+ previous = nil
234
+ # The list doesn't come to us in the correct order. Frustration.
235
+ index = 0
236
+ while index < newlist.length do
237
+ hash = newlist[index.to_s]
238
+ moved_item_id = hash['id'].split(/#{singular_name}/)
239
+ @current_#{singular_name} = #{class_name}.find_by_id(moved_item_id)
240
+
241
+ if previous.present?
242
+ @previous_item = #{class_name}.find_by_id(previous)
243
+ @current_#{singular_name}.move_to_right_of(@previous_item)
244
+ else
245
+ @current_#{singular_name}.move_to_root
246
+ end
247
+
248
+ if hash['children'].present?
249
+ update_child_positions(hash, @current_#{singular_name})
250
+ end
251
+
252
+ previous = moved_item_id
253
+ index += 1
254
+ end
255
+ #{class_name}.rebuild!
256
+ render :nothing => true
257
+ end
258
+
259
+ def update_child_positions(node, #{singular_name})
260
+ child_index = 0
261
+ while child_index < node['children'].length do
262
+ child = node['children'][child_index.to_s]
263
+ child_id = child['id'].split(/#{singular_name}/)
264
+ child_#{singular_name} = #{class_name}.find_by_id(child_id)
265
+ child_#{singular_name}.move_to_child_of(#{singular_name})
266
+
267
+ if child['children'].present?
268
+ update_child_positions(child, child_#{singular_name})
269
+ end
270
+
271
+ child_index += 1
272
+ end
273
+ end
274
+
275
+ )
276
+ end
277
+
278
+ end
279
+
280
+ end
281
+
282
+ end
283
+ end
@@ -0,0 +1,26 @@
1
+ require_dependency 'truncate_html'
2
+
3
+ module Refinery
4
+ module Helpers
5
+ module HtmlTruncationHelper
6
+
7
+ # Like the Rails _truncate_ helper but doesn't break HTML tags, entities, and words.
8
+ # <script> tags pass through and are not counted in the total.
9
+ # the omission specified _does_ count toward the total length count.
10
+ # use :link => link_to('more', post_path), or something to that effect
11
+ def truncate(text, *args)
12
+ return unless text.present?
13
+ return super unless ((arguments = args.dup).extract_options![:preserve_html_tags] == true) # don't ruin the current args object
14
+
15
+ options = args.extract_options!
16
+ max_length = options[:length] || 30
17
+ omission = options[:omission] || "..."
18
+
19
+ return truncate_html(text,
20
+ :length => max_length,
21
+ :word_boundary => true,
22
+ :omission => omission)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ module Refinery
2
+ module Helpers
3
+ module ImageHelper
4
+
5
+ # replace all system images with a thumbnail version of them (handy for all images inside a page part)
6
+ # for example, <%= content_fu(@page[:body], '96x96#c') %> converts all /system/images to a 96x96 cropped thumbnail
7
+ def content_fu(content, thumbnail)
8
+ raise NotImplementedError # todo: implement for new syntax.
9
+
10
+ content.scan(/\/system\/images([^\"\ ]*)/).flatten.each do |match|
11
+ parts = match.split(".")
12
+ extension = parts.pop
13
+ content.gsub!(match, "#{parts.join(".")}_#{thumbnail}.#{extension}")
14
+ end unless content.blank?
15
+
16
+ return content
17
+ end
18
+
19
+ # image_fu is a helper for inserting an image that has been uploaded into a template.
20
+ # Say for example that we had a @model.image (@model having a belongs_to :image relationship)
21
+ # and we wanted to display a thumbnail cropped to 200x200 then we can use image_fu like this:
22
+ # <%= image_fu @model.image, '200x200' %> or with no thumbnail: <%= image_fu @model.image %>
23
+ def image_fu(image, geometry = nil, options={})
24
+ if image.present?
25
+ # call rails' image tag function with default alt, width and height options.
26
+ # if any other options were supplied these are merged in and can replace the defaults.
27
+ image_tag((thumbnail = image.thumbnail(geometry)).url, {
28
+ :alt => image.respond_to?(:title) ? image.title : image.image_name,
29
+ :width => thumbnail.width,
30
+ :height => thumbnail.height
31
+ }.merge(options))
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ module Refinery
2
+ module Helpers
3
+ module MenuHelper
4
+
5
+ # This was extracted from REFINERY_ROOT/vendor/plugins/refinery/app/views/shared/_menu_branch.html.erb
6
+ # to remove the complexity of that template by reducing logic in the view.
7
+ def css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count = nil)
8
+ css = []
9
+ css << "selected" if selected_page?(menu_branch) or descendant_page_selected?(menu_branch)
10
+ css << "first" if menu_branch_counter == 0
11
+ css << "last" if menu_branch_counter == (sibling_count ||= menu_branch.shown_siblings.size)
12
+ css
13
+ end
14
+
15
+ # Determines whether any page underneath the supplied page is the current page according to rails.
16
+ # Just calls selected_page? for each descendant of the supplied page.
17
+ def descendant_page_selected?(page)
18
+ page.has_descendants? and page.descendants.any? {|descendant| selected_page?(descendant) }
19
+ end
20
+
21
+ # Determine whether the supplied page is the currently open page according to Refinery.
22
+ # Also checks whether Rails thinks it is selected after that using current_page?
23
+ def selected_page?(page)
24
+ # ensure we match the path without the locale.
25
+ path = request.path
26
+ if defined?(::Refinery::I18n) and ::Refinery::I18n.enabled?
27
+ path = path.split("/#{::I18n.locale}").last
28
+ end
29
+
30
+ (path =~ Regexp.new(page.menu_match) if page.menu_match.present?) or
31
+ (path == page.link_url) or
32
+ (path == page.nested_path) or
33
+ current_page?(page)
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,67 @@
1
+ module Refinery
2
+ module Helpers
3
+ module MetaHelper
4
+
5
+ # This is used to display the title of the current object (normally a page) in the browser's titlebar.
6
+ #
7
+ def browser_title(yield_title=nil)
8
+ [
9
+ yield_title.present? ? yield_title : nil,
10
+ @meta.browser_title.present? ? @meta.browser_title : @meta.path,
11
+ RefinerySetting.find_or_set(:site_name, "Company Name")
12
+ ].compact.join(" - ")
13
+ end
14
+
15
+ # you can override the object used for the title by supplying options[:object]
16
+ # this object must support custom_title_type if you want custom titles.
17
+ def page_title(options = {})
18
+ object = options.fetch(:object, @meta)
19
+ options.delete(:object)
20
+ options = RefinerySetting.find_or_set(:page_title, {
21
+ :chain_page_title => false,
22
+ :ancestors => {
23
+ :separator => " | ",
24
+ :class => 'ancestors',
25
+ :tag => 'span'
26
+ },
27
+ :page_title => {
28
+ :class => nil,
29
+ :tag => nil,
30
+ :wrap_if_not_chained => false
31
+ }
32
+ }).merge(options)
33
+
34
+ title = []
35
+ objects = (options[:chain_page_title] and object.respond_to?(:ancestors)) ? [object.ancestors, object] : [object]
36
+
37
+ objects.flatten.compact.each do |obj|
38
+ if obj.respond_to?(:custom_title_type)
39
+ title << case obj.custom_title_type
40
+ when "text"
41
+ obj.custom_title
42
+ when "image"
43
+ image_fu(obj.custom_title_image, nil, {:alt => obj.title}) rescue obj.title
44
+ else
45
+ obj.title
46
+ end
47
+ else
48
+ title << obj.title
49
+ end
50
+ end
51
+
52
+ final_title = title.pop
53
+ if (options[:page_title][:wrap_if_not_chained] and title.empty?) and options[:page_title][:tag].present?
54
+ css = options[:page_title][:class].present? ? " class='#{options[:page_title][:class]}'" : nil
55
+ final_title = "<#{options[:page_title][:tag]}#{css}>#{final_title}</#{options[:page_title][:tag]}>"
56
+ end
57
+
58
+ if title.empty?
59
+ return final_title.to_s.html_safe
60
+ else
61
+ return "<#{options[:ancestors][:tag]} class='#{options[:ancestors][:class]}'>#{title.join options[:ancestors][:separator]}#{options[:ancestors][:separator]}</#{options[:ancestors][:tag]}>#{final_title}".html_safe
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end