refinerycms-page-menus 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +2 -0
  2. data/app/controllers/refinery/admin/page_menus_controller.rb +9 -0
  3. data/app/controllers/refinery/admin/page_positions_controller.rb +51 -0
  4. data/app/models/refinery/page_menu.rb +31 -0
  5. data/app/models/refinery/page_position.rb +37 -0
  6. data/app/views/refinery/admin/page_menus/_form.html.erb +41 -0
  7. data/app/views/refinery/admin/page_menus/edit.html.erb +1 -0
  8. data/app/views/refinery/admin/page_positions/_actions.html.erb +45 -0
  9. data/app/views/refinery/admin/page_positions/_page_position.html.erb +49 -0
  10. data/app/views/refinery/admin/page_positions/_records.html.erb +14 -0
  11. data/app/views/refinery/admin/page_positions/_sortable_list.html.erb +4 -0
  12. data/app/views/refinery/admin/page_positions/index.html.erb +11 -0
  13. data/app/views/refinery/admin/pages/_actions.html.erb +40 -0
  14. data/app/views/refinery/admin/pages/_list_actions.html.erb +28 -0
  15. data/app/views/refinery/admin/pages/_list_page.html.erb +46 -0
  16. data/app/views/refinery/admin/pages/_list_records.html.erb +16 -0
  17. data/app/views/refinery/admin/pages/list.html.erb +8 -0
  18. data/app/views/refinery/admin/pages_shared/_submenu.html.erb +65 -0
  19. data/config/locales/da.yml +32 -0
  20. data/config/locales/en.yml +93 -0
  21. data/config/routes.rb +14 -0
  22. data/db/migrate/20120406121839_create_page_menus.rb +31 -0
  23. data/db/migrate/20120411133453_add_permatitle_to_page_menus.rb +9 -0
  24. data/db/migrate/20120411134419_add_menu_match_to_page_positions.rb +6 -0
  25. data/lib/generators/refinery/page_menus/page_menus_generator.rb +14 -0
  26. data/lib/generators/refinery/page_menus/templates/config/initializers/refinery/page_menus.rb.erb +3 -0
  27. data/lib/refinery/page_menus.rb +31 -0
  28. data/lib/refinery/page_menus/configuration.rb +10 -0
  29. data/lib/refinery/page_menus/controller_extension.rb +44 -0
  30. data/lib/refinery/page_menus/engine.rb +35 -0
  31. data/lib/refinery/page_menus/instance_methods.rb +16 -0
  32. data/lib/refinery/page_menus/model_extension.rb +14 -0
  33. data/lib/refinerycms-page-menus.rb +1 -0
  34. data/license.md +21 -0
  35. data/readme.md +1 -0
  36. data/refinerycms-page-menus.gemspec +25 -0
  37. data/spec/factories/pages.rb +5 -0
  38. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +44 -0
  39. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +29 -0
  40. data/spec/lib/pages/content_page_presenter_spec.rb +43 -0
  41. data/spec/lib/pages/content_presenter_spec.rb +111 -0
  42. data/spec/lib/pages/page_part_section_presenter_spec.rb +35 -0
  43. data/spec/lib/pages/section_presenter_spec.rb +86 -0
  44. data/spec/lib/pages/title_section_presenter_spec.rb +21 -0
  45. data/spec/lib/pages_spec.rb +26 -0
  46. data/spec/models/refinery/page_spec.rb +415 -0
  47. data/spec/requests/refinery/admin/pages_spec.rb +613 -0
  48. data/spec/requests/refinery/pages_spec.rb +302 -0
  49. metadata +127 -0
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ spec/dummy/
@@ -0,0 +1,9 @@
1
+ module Refinery
2
+ module Admin
3
+ class PageMenusController < ::Refinery::AdminController
4
+
5
+ crudify :'refinery/page_menu', :xhr_paging => true, :sortable => false, :redirect_to_url => "refinery.admin_page_menu_page_positions_path(@page_menu)"
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ module Refinery
2
+ module Admin
3
+ class PagePositionsController < Refinery::AdminController
4
+
5
+ crudify :'refinery/page_position',
6
+ :order => "lft ASC",
7
+ :include => [:children],
8
+ :paging => false
9
+
10
+ before_filter :find_all_menus, :find_menu, :only => [:index, :update_positions]
11
+
12
+ # after_filter lambda{::Refinery::Page.expire_page_caching}, :only => [:update_positions]
13
+
14
+ # before_filter :restrict_access, :only => [:create, :update, :update_positions, :destroy],
15
+ # :if => proc { Refinery.i18n_enabled? }
16
+
17
+
18
+ def children
19
+ @page_position = find_page_position
20
+ render :layout => false
21
+ end
22
+
23
+ protected
24
+
25
+ def find_all_page_positions(conditions = '')
26
+ @page_positions = @page_menu.positions.where(conditions).order('lft ASC')
27
+ end
28
+
29
+ def find_menu
30
+ if params[:page_menu_id]
31
+ @page_menu = Refinery::PageMenu.find(params[:page_menu_id])
32
+ end
33
+ end
34
+
35
+ def find_all_menus
36
+ @page_menus = Refinery::PageMenu.order('title ASC')
37
+ end
38
+
39
+ # def restrict_access
40
+ # if current_refinery_user.has_role?(:translator) && !current_refinery_user.has_role?(:superuser) &&
41
+ # (params[:switch_locale].blank? || params[:switch_locale] == Refinery::I18n.default_frontend_locale.to_s)
42
+ # flash[:error] = t('translator_access', :scope => 'refinery.admin.pages')
43
+ # redirect_to refinery.admin_pages_path
44
+ # end
45
+ #
46
+ # return true
47
+ # end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ module Refinery
2
+ class PageMenu < Refinery::Core::BaseModel
3
+
4
+ has_many :positions, :class_name => "::Refinery::PagePosition", :foreign_key => :refinery_menu_id, :dependent => :destroy, :order => "lft ASC"
5
+ has_many :pages, :class_name => "::Refinery::Page", :through => :positions, :foreign_key => :refinery_page_id
6
+
7
+ validates :title, :presence => true, :uniqueness => true
8
+ validates :permatitle, :presence => true, :uniqueness => true
9
+ validates_associated :positions
10
+
11
+ def pages=(new_ids)
12
+ old_ids = positions.map(&:refinery_page_id)
13
+ (new_ids - old_ids).each do |id|
14
+ positions.build(:refinery_page_id => id) if !id.empty?
15
+ end
16
+ (old_ids - new_ids).each do |id|
17
+ positions.where(:refinery_page_id => id).destroy_all
18
+ end
19
+ self.save
20
+ end
21
+
22
+ # def fast_menu(columns = [])
23
+ # live.in_menu.order('lft ASC').includes(:translations)
24
+ # end
25
+
26
+ def roots
27
+ @roots ||= positions.select {|pos| pos.parent_id.nil?}
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ module Refinery
2
+ class PagePosition < Refinery::Core::BaseModel
3
+
4
+ attr_accessible :parent_id, :refinery_page_id, :refinery_menu_id
5
+
6
+ belongs_to :menu, :class_name => '::Refinery::PageMenu', :foreign_key => :refinery_menu_id
7
+ belongs_to :page, :class_name => '::Refinery::Page', :foreign_key => :refinery_page_id
8
+
9
+ # Docs for acts_as_nested_set https://github.com/collectiveidea/awesome_nested_set
10
+ # rather than :delete_all we want :destroy
11
+ acts_as_nested_set :dependent => :destroy
12
+
13
+ validates :page, :presence => true
14
+ validates :menu, :presence => true
15
+
16
+ def title
17
+ page.title
18
+ end
19
+
20
+ def url
21
+ page.url
22
+ end
23
+
24
+ def url=(value)
25
+ page.url = value
26
+ end
27
+
28
+ def original_id
29
+ page.id
30
+ end
31
+
32
+ def original_type
33
+ page.type
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ <%= form_for [refinery, :admin, @page_menu], :html => {:onsubmit => "selectAll('.select_to')" } do |f| -%>
2
+ <%= render '/refinery/admin/error_messages',
3
+ :object => @page_menu,
4
+ :include_object_name => true %>
5
+
6
+ <div class='field'>
7
+ <%= f.label :title %>
8
+ <%= f.text_field :title, class: "larger widest" %>
9
+ </div>
10
+
11
+
12
+ <div class='select'>
13
+
14
+ <div class="hemisquare">
15
+ <span class='label_with_help'>
16
+ <%= label_tag :all_pages, t('.all_pages') %>
17
+ <%= refinery_help_tag t('.all_pages_help') %>
18
+ </span>
19
+ <%= collection_select :all, :pages, Refinery::Page.all - @page_menu.pages, :id, :title, {}, { :allow_blank => true, :size => 20, :multiple => true, :class => "select_from" } %>
20
+ </div>
21
+
22
+ <div class='select_buttons'>
23
+ <%= button_tag ">", :type => 'button', :onclick => "moveSelectedPage('.select_from','.select_to')", :class => 'select_add' %>
24
+ <%= button_tag "<", :type => 'button', :onclick => "moveSelectedPage('.select_to','.select_from')", :class => 'select_remove' %>
25
+ </div>
26
+
27
+ <div class="hemisquare right_side">
28
+ <span class='label_with_help'>
29
+ <%= f.label :pages, t('.menu_pages') %>
30
+ <%= refinery_help_tag t('.pages_help') %>
31
+ </span>
32
+ <%= f.collection_select :pages, @page_menu.pages, :id, :title, {}, { :allow_blank => true, :size => 20, :multiple => true, :class => "select_to" } %>
33
+ </div>
34
+
35
+ </div>
36
+
37
+ <%= render '/refinery/admin/form_actions', :f => f,
38
+ :continue_editing => false,
39
+ :delete_title => t('delete', :scope => 'refinery.travels.admin.travels.category'),
40
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete') %>
41
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,45 @@
1
+ <ul>
2
+ <li>
3
+ <%= render '/refinery/admin/search', :url => refinery.admin_pages_path %>
4
+ </li>
5
+
6
+ <li>
7
+ <%= link_to t('menus.edit', :scope => 'refinery.admin.pages.actions'), refinery.edit_admin_page_menu_path(@page_menu),
8
+ :class => "add_icon" %>
9
+ </li>
10
+
11
+ <li>
12
+ <%= link_to t('reorder_pages', :scope => 'refinery.admin.pages.actions'), refinery.admin_pages_path,
13
+ :id => "reorder_action",
14
+ :class => "reorder_icon" %>
15
+
16
+ <%= link_to t('reorder_pages_done', :scope => 'refinery.admin.pages.actions'), refinery.admin_pages_path,
17
+ :id => "reorder_action_done",
18
+ :style => "display: none;",
19
+ :class => "reorder_icon" %>
20
+ </li>
21
+
22
+ <li>
23
+ <%= link_to t('pages.manage', :scope => 'refinery.admin.pages.actions'), refinery.admin_pages_path,
24
+ :class => "folder_icon" %>
25
+ </li>
26
+
27
+ <ul class='collapsible_menu'>
28
+ <li class='not_a_link'>
29
+ <%= link_to t('menus.title', :scope => 'refinery.admin.pages.actions'), "#",
30
+ :class => "folder_icon" %>
31
+ </li>
32
+
33
+ <li>
34
+ <%= link_to t('menus.main', :scope => 'refinery.admin.pages.actions'), refinery.admin_pages_main_menu_path,
35
+ :class => "folder_icon" %>
36
+ </li>
37
+
38
+ <% (@page_menus - [@page_menu]).each do |menu| %>
39
+ <li>
40
+ <%= link_to menu.title, refinery.admin_page_menu_page_positions_path(menu),
41
+ :class => "folder_icon" %>
42
+ </li>
43
+ <% end %>
44
+ </ul>
45
+ </ul>
@@ -0,0 +1,49 @@
1
+ <% page = page_position.page %>
2
+ <li class='clearfix record icons' id="<%= dom_id(page_position) -%>">
3
+ <div class='clearfix'>
4
+ <% if page_position.children.present? %>
5
+ <span class="icon toggle <%= 'expanded' if Refinery::Pages.auto_expand_admin_tree %>" title="<%= t('expand_collapse', :scope => 'refinery.admin.pages') %>"></span>
6
+ <% else %>
7
+ <span class="icon"></span>
8
+ <% end %>
9
+
10
+ <span class='title <%= 'toggle' if page_position.children.present? %>'>
11
+ <%= page.title_with_meta.html_safe %>
12
+ <% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
13
+ <span class='preview'>
14
+ <% page.translations.each do |translation| %>
15
+ <% if translation.title.present? %>
16
+ <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
17
+ refinery.edit_admin_page_path(page, :switch_locale => translation.locale),
18
+ :class => 'locale' %>
19
+ <% end %>
20
+ <% end %>
21
+ </span>
22
+ <% end %>
23
+ </span>
24
+
25
+ <span class='actions'>
26
+ <%= link_to refinery_icon_tag('application_go.png'),
27
+ refinery.page_path(page),
28
+ :target => "_blank",
29
+ :title => t('.view_live_html') %>
30
+ <%= link_to refinery_icon_tag('page_add.png'),
31
+ refinery.new_admin_page_path(:parent_id => page.id),
32
+ :title => t('new', :scope => 'refinery.admin.pages') %>
33
+
34
+ <%= link_to refinery_icon_tag('application_edit.png'),
35
+ refinery.edit_admin_page_path(page.uncached_nested_url),
36
+ :title => t('edit', :scope => 'refinery.admin.pages') %>
37
+
38
+ <%= link_to refinery_icon_tag('delete.png'),
39
+ refinery.admin_page_path(page.uncached_nested_url),
40
+ :class => "cancel confirm-delete",
41
+ :title => t('delete', :scope => 'refinery.admin.pages'),
42
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => page.title_with_meta.gsub(/\ ?<em>.*<\/em>/, "")),
43
+ :method => :delete if page.deletable? %>
44
+ </span>
45
+ </div>
46
+ <ul class='nested' data-ajax-content="<%= refinery.admin_children_pages_path(page.uncached_nested_url) %>">
47
+ <%= render(:partial => 'page_position', :collection => page_position.children) if Refinery::Pages.auto_expand_admin_tree %>
48
+ </ul>
49
+ </li>
@@ -0,0 +1,14 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <% if @page_positions.any? %>
5
+ <%= render 'sortable_list' %>
6
+ <% else %>
7
+ <p>
8
+ <% unless searching? %>
9
+ <strong><%=t('.no_pages_yet')%></strong>
10
+ <% else %>
11
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
12
+ <% end %>
13
+ </p>
14
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'page_position', :collection => @page_positions.select{|p| p.parent_id.nil?} %>
3
+ </ul>
4
+ <%= render '/refinery/admin/sortable_list', :continue_reordering => !!local_assigns[:continue_reordering] %>
@@ -0,0 +1,11 @@
1
+ <h2><%= @page_menu.title %></h2>
2
+
3
+ <section id='records' class='tree'>
4
+ <% cache_if(Refinery::Pages.cache_pages_backend, [Refinery::Core.base_cache_key, "pages_backend", Globalize.locale].join('_')) do %>
5
+ <%= render 'records' %>
6
+ <% end %>
7
+ </section>
8
+ <section id='actions'>
9
+ <%= render 'actions' %>
10
+ </section>
11
+ <%= render '/refinery/admin/make_sortable', :tree => true if @page_positions.many? -%>
@@ -0,0 +1,40 @@
1
+ <ul>
2
+ <li>
3
+ <%= render '/refinery/admin/search', :url => refinery.admin_pages_path %>
4
+ </li>
5
+ <li>
6
+ <%= link_to t('.create_new_page'), refinery.new_admin_page_path,
7
+ :class => "add_icon" %>
8
+ </li>
9
+ <% if @pages.many? and !searching? %>
10
+ <li>
11
+ <%= link_to t('.reorder_pages'), refinery.admin_pages_path,
12
+ :id => "reorder_action",
13
+ :class => "reorder_icon" %>
14
+
15
+ <%= link_to t('.reorder_pages_done'), refinery.admin_pages_path,
16
+ :id => "reorder_action_done",
17
+ :style => "display: none;",
18
+ :class => "reorder_icon" %>
19
+ </li>
20
+ <% end %>
21
+
22
+ <li>
23
+ <%= link_to t('.pages.manage'), refinery.admin_pages_path,
24
+ :class => "folder_icon" %>
25
+ </li>
26
+
27
+ <ul class='collapsible_menu'>
28
+ <li class='not_a_link'>
29
+ <%= link_to t('.menus.title'), "#",
30
+ :class => "folder_icon" %>
31
+ </li>
32
+
33
+ <% @page_menus.each do |menu| %>
34
+ <li>
35
+ <%= link_to menu.title, refinery.admin_page_menu_page_positions_path(menu),
36
+ :class => "folder_icon" %>
37
+ </li>
38
+ <% end %>
39
+ </ul>
40
+ </ul>
@@ -0,0 +1,28 @@
1
+ <ul>
2
+ <li>
3
+ <%= render '/refinery/admin/search', :url => refinery.admin_pages_path %>
4
+ </li>
5
+ <li>
6
+ <%= link_to t('create_new_page', :scope => "refinery.admin.pages.actions"), refinery.new_admin_page_path,
7
+ :class => "add_icon" %>
8
+ </li>
9
+
10
+ <ul class='collapsible_menu'>
11
+ <li class='not_a_link'>
12
+ <%= link_to t('menus.title', :scope => "refinery.admin.pages.actions"), "#",
13
+ :class => "folder_icon" %>
14
+ </li>
15
+
16
+ <li>
17
+ <%= link_to t('menus.main', :scope => "refinery.admin.pages.actions"), refinery.admin_pages_main_menu_path,
18
+ :class => "folder_icon" %>
19
+ </li>
20
+
21
+ <% @page_menus.each do |menu| %>
22
+ <li>
23
+ <%= link_to menu.title, refinery.admin_page_menu_page_positions_path(menu),
24
+ :class => "folder_icon" %>
25
+ </li>
26
+ <% end %>
27
+ </ul>
28
+ </ul>
@@ -0,0 +1,46 @@
1
+ <% page = list_page %>
2
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(page) -%>">
3
+ <div class='clearfix'>
4
+ <% if page.children.present? %>
5
+ <span class="icon toggle <%= 'expanded' if Refinery::Pages.auto_expand_admin_tree %>" title="<%= t('expand_collapse', :scope => 'refinery.admin.pages') %>"></span>
6
+ <% else %>
7
+ <span class="icon"></span>
8
+ <% end %>
9
+
10
+ <span class='title <%= 'toggle' if page.children.present? %>'>
11
+ <%= page.title_with_meta.html_safe %>
12
+ <% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
13
+ <span class='preview'>
14
+ <% page.translations.each do |translation| %>
15
+ <% if translation.title.present? %>
16
+ <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
17
+ refinery.edit_admin_page_path(page, :switch_locale => translation.locale),
18
+ :class => 'locale' %>
19
+ <% end %>
20
+ <% end %>
21
+ </span>
22
+ <% end %>
23
+ </span>
24
+
25
+ <span class='actions'>
26
+ <%= link_to refinery_icon_tag('application_go.png'),
27
+ refinery.page_path(page),
28
+ :target => "_blank",
29
+ :title => t('.view_live_html') %>
30
+ <%= link_to refinery_icon_tag('page_add.png'),
31
+ refinery.new_admin_page_path(:parent_id => page.id),
32
+ :title => t('new', :scope => 'refinery.admin.pages') %>
33
+
34
+ <%= link_to refinery_icon_tag('application_edit.png'),
35
+ refinery.edit_admin_page_path(page.uncached_nested_url),
36
+ :title => t('edit', :scope => 'refinery.admin.pages') %>
37
+
38
+ <%= link_to refinery_icon_tag('delete.png'),
39
+ refinery.admin_page_path(page.uncached_nested_url),
40
+ :class => "cancel confirm-delete",
41
+ :title => t('delete', :scope => 'refinery.admin.pages'),
42
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => page.title_with_meta.gsub(/\ ?<em>.*<\/em>/, "")),
43
+ :method => :delete if page.deletable? %>
44
+ </span>
45
+ </div>
46
+ </li>
@@ -0,0 +1,16 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <% if @pages.any? %>
5
+ <ul id='sortable_list'>
6
+ <%= render :partial => 'list_page', :collection => @pages %>
7
+ </ul>
8
+ <% else %>
9
+ <p>
10
+ <% unless searching? %>
11
+ <strong><%=t('.no_pages_yet')%></strong>
12
+ <% else %>
13
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
14
+ <% end %>
15
+ </p>
16
+ <% end %>