refinerycms-page-menus 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/app/assets/javascripts/refinery/backend.js.coffee +16 -1
  2. data/app/controllers/refinery/admin/{page_positions_controller.rb → menu_links_controller.rb} +6 -6
  3. data/app/controllers/refinery/admin/page_menus_controller.rb +20 -19
  4. data/app/models/refinery/{page_position.rb → menu_link.rb} +28 -11
  5. data/app/models/refinery/page_menu.rb +5 -5
  6. data/app/views/refinery/admin/{page_positions → menu_links}/_custom_link.html.erb +1 -1
  7. data/app/views/refinery/admin/menu_links/_menu_link.html.erb +29 -0
  8. data/app/views/refinery/admin/{page_positions → menu_links}/_resource_link.html.erb +1 -1
  9. data/app/views/refinery/admin/{page_positions → menu_links}/_resource_link_editor_box.html.erb +4 -4
  10. data/app/views/refinery/admin/menu_links/create.js.erb +6 -0
  11. data/app/views/refinery/admin/menu_links/destroy.js.erb +3 -0
  12. data/app/views/refinery/admin/page_menus/_form.html.erb +6 -8
  13. data/app/views/refinery/admin/page_menus/_form_actions.html.erb +4 -4
  14. data/app/views/refinery/admin/page_menus/_page_menu.html.erb +1 -1
  15. data/app/views/refinery/admin/page_menus/_page_menus.html.erb +3 -2
  16. data/app/views/refinery/admin/page_menus/edit.html.erb +0 -2
  17. data/config/locales/da.yml +21 -23
  18. data/config/locales/en.yml +20 -22
  19. data/config/locales/fr.yml +1 -25
  20. data/config/routes.rb +2 -2
  21. data/db/migrate/06_rename_page_positions_to_menu_links.rb +5 -0
  22. data/db/seeds.rb +1 -1
  23. data/lib/refinery/page_menus.rb +0 -2
  24. data/lib/refinery/page_menus/configuration.rb +1 -1
  25. data/lib/refinery/page_menus/engine.rb +2 -8
  26. data/lib/refinery/page_menus/instance_methods.rb +1 -1
  27. data/lib/refinery/page_menus/version.rb +1 -1
  28. data/lib/tasks/refinery/page_menus.rake +65 -0
  29. data/readme.md +21 -12
  30. metadata +17 -28
  31. data/app/helpers/refinery/page_positions_helper.rb +0 -66
  32. data/app/views/refinery/admin/page_menus/_sortable_list.html.erb +0 -5
  33. data/app/views/refinery/admin/page_positions/_page_position.html.erb +0 -26
  34. data/app/views/refinery/admin/page_positions/create.js.erb +0 -5
  35. data/app/views/refinery/admin/page_positions/destroy.js.erb +0 -3
  36. data/lib/refinery/page_menus/controller_extension.rb +0 -48
@@ -10,6 +10,19 @@ jQuery =>
10
10
  $('#page_menu_form').submit (e) ->
11
11
  save_structure($(this))
12
12
 
13
+ reset_custom_link_form()
14
+
15
+ reset_link_forms = () ->
16
+ reset_custom_link_form()
17
+ reset_resource_link_forms()
18
+
19
+ reset_custom_link_form = () ->
20
+ $('#menu_link_custom_url').val('http://')
21
+ $('#menu_link_label').val('')
22
+
23
+ reset_resource_link_forms = () ->
24
+ $('.resource-pp-add-box').find('input[type="checkbox"]').attr('checked', false)
25
+
13
26
  save_structure = (form) ->
14
27
  list_reorder.sortable_list.nestedSortable("disable")
15
28
 
@@ -21,4 +34,6 @@ save_structure = (form) ->
21
34
  for elem in serialized_lists.split('&')
22
35
  if elem.length
23
36
  input = $("<input>").attr("type", "hidden").attr("name", elem.split('=')[0]).val(elem.split('=')[1])
24
- form.append(input)
37
+ form.append(input)
38
+
39
+ window.reset_link_forms = reset_link_forms
@@ -1,17 +1,17 @@
1
1
  module Refinery
2
2
  module Admin
3
- class PagePositionsController < Refinery::AdminController
3
+ class MenuLinksController < Refinery::AdminController
4
4
 
5
5
  def create
6
6
  respond_to do |format|
7
7
  format.js do
8
- @page_positions = []
8
+ @menu_links = []
9
9
  if params[:refinery_resource_ids]
10
10
  params[:refinery_resource_ids].each do |id|
11
- @page_positions << PagePosition.create({refinery_resource_id: id}.merge(params[:page_position]))
11
+ @menu_links << MenuLink.create({refinery_resource_id: id}.merge(params[:menu_link]))
12
12
  end
13
13
  else
14
- @page_positions << PagePosition.create(params[:page_position])
14
+ @menu_links << MenuLink.create(params[:menu_link])
15
15
  end
16
16
  end
17
17
  end
@@ -20,8 +20,8 @@ module Refinery
20
20
  def destroy
21
21
  respond_to do |format|
22
22
  format.js do
23
- @page_position = PagePosition.find(params[:id])
24
- @page_position.destroy
23
+ @menu_link = MenuLink.find(params[:id])
24
+ @menu_link.destroy
25
25
  end
26
26
  end
27
27
  end
@@ -4,35 +4,36 @@ module Refinery
4
4
 
5
5
  crudify :'refinery/page_menu',
6
6
  :xhr_paging => true,
7
- :sortable => false
7
+ :sortable => false,
8
+ :include => [:links]
8
9
 
9
- before_filter :find_page_positions, only: [:edit, :update]
10
- before_filter :set_page_positions, only: [:create, :update]
10
+ before_filter :find_menu_links, only: [:edit, :update]
11
+ before_filter :set_links_positions, only: [:create, :update]
11
12
 
12
13
  private
13
14
 
14
15
  # Based upon http://github.com/matenia/jQuery-Awesome-Nested-Set-Drag-and-Drop
15
- def set_page_positions
16
+ def set_links_positions
16
17
  previous = nil
17
18
  params[:ul].each do |_, list|
18
19
  list.each do |index, hash|
19
- moved_item_id = hash['id'].split(/page_position\_?/).reject(&:empty?).first
20
+ moved_item_id = hash['id'].split(/menu_link\_?/).reject(&:empty?).first
20
21
 
21
22
  if moved_item_id
22
- current_position = @page_menu.positions.find(moved_item_id) # Scope?
23
+ current_link = @page_menu.links.find(moved_item_id) # Scope?
23
24
 
24
- if current_position.respond_to?(:move_to_root)
25
+ if current_link.respond_to?(:move_to_root)
25
26
  if previous.present?
26
- current_position.move_to_right_of(@page_menu.positions.find(previous)) #SCOPE?
27
+ current_link.move_to_right_of(@page_menu.links.find(previous)) #SCOPE?
27
28
  else
28
- current_position.move_to_root
29
+ current_link.move_to_root
29
30
  end
30
31
  else
31
- current_position.update_attributes :position => index
32
+ current_link.update_attributes :position => index
32
33
  end
33
34
 
34
35
  if hash['children'].present?
35
- update_child_page_positions(hash, current_position)
36
+ update_child_links_positions(hash, current_link)
36
37
  end
37
38
 
38
39
  previous = moved_item_id
@@ -40,24 +41,24 @@ module Refinery
40
41
  end
41
42
  end if params[:ul].present?
42
43
 
43
- PagePosition.rebuild!
44
+ MenuLink.rebuild!
44
45
  end
45
46
 
46
- def update_child_page_positions(_node, position)
47
+ def update_child_links_positions(_node, link)
47
48
  list = _node['children']['0']
48
49
  list.each do |index, child|
49
- child_id = child['id'].split(/page_position\_?/).reject(&:empty?).first
50
- child_position = @page_menu.positions.find(child_id) # Scoped?
51
- child_position.move_to_child_of(position)
50
+ child_id = child['id'].split(/menu_link\_?/).reject(&:empty?).first
51
+ child_link = @page_menu.links.find(child_id) # Scoped?
52
+ child_link.move_to_child_of(link)
52
53
 
53
54
  if child['children'].present?
54
- update_child_page_positions(child, child_position)
55
+ update_child_links_positions(child, child_link)
55
56
  end
56
57
  end
57
58
  end
58
59
 
59
- def find_page_positions
60
- @page_positions = @page_menu.roots
60
+ def find_menu_links
61
+ @menu_links = @page_menu.roots
61
62
  end
62
63
 
63
64
  end
@@ -1,5 +1,5 @@
1
1
  module Refinery
2
- class PagePosition < Refinery::Core::BaseModel
2
+ class MenuLink < Refinery::Core::BaseModel
3
3
 
4
4
  attr_accessible :parent_id, :refinery_page_id, :refinery_menu_id, :refinery_resource_id, :refinery_resource_type,
5
5
  :title_attribute, :custom_url, :label
@@ -12,6 +12,9 @@ module Refinery
12
12
  acts_as_nested_set :dependent => :destroy
13
13
 
14
14
  validates :menu, :presence => true
15
+ validates :label, :presence => true
16
+
17
+ before_validation :set_label
15
18
 
16
19
  def self.find_all_of_type(type)
17
20
  # find all resources of the given type, determined by the configuration
@@ -31,20 +34,34 @@ module Refinery
31
34
  Refinery::PageMenus.menu_resources[type.to_sym]
32
35
  end
33
36
 
37
+ def set_label
38
+ if label.blank?
39
+ if custom_link?
40
+ begin
41
+ self.label = custom_url.match(/(\w+)\.\w+$/).captures.join.titleize
42
+ rescue
43
+ self.label = custom_url
44
+ end
45
+ else
46
+ self.label = resource.send(resource_config[:title_attr])
47
+ end
48
+ end
49
+ end
50
+
34
51
  def resource_klass
35
- Refinery::PagePosition.resource_klass(resource_type)
52
+ Refinery::MenuLink.resource_klass(resource_type)
36
53
  end
37
54
 
38
55
  def resource_config
39
- Refinery::PagePosition.resource_config(resource_type)
56
+ Refinery::MenuLink.resource_config(resource_type)
40
57
  end
41
58
 
42
59
  def resource_type
43
- refinery_resource_type || 'refinery_page'
60
+ refinery_resource_type || "Custom link"
44
61
  end
45
62
 
46
63
  def type_name
47
- custom_link? ? "Custom link" : refinery_resource_type.titleize()
64
+ resource_type.titleize
48
65
  end
49
66
 
50
67
  def custom_link?
@@ -60,16 +77,16 @@ module Refinery
60
77
  resource_klass.find(refinery_resource_id)
61
78
  end
62
79
 
63
- def resource_url
64
- resource.present? ? resource.url : '/'
65
- end
66
-
67
80
  def resource_title
68
81
  resource[resource_config[:title_attr]]
69
82
  end
70
83
 
71
84
  def title
72
- title_attribute.present? ? title_attribute : label.present? ? label : resource.title
85
+ title_attribute.present? ? title_attribute : label
86
+ end
87
+
88
+ def resource_url
89
+ resource.present? ? resource.url : '/'
73
90
  end
74
91
 
75
92
  def url
@@ -99,7 +116,7 @@ module Refinery
99
116
  :menu_match => menu_match,
100
117
  :parent_id => parent_id,
101
118
  :rgt => rgt,
102
- :title => title,
119
+ :title => label, # title attributes has not yet been implemented in RefineryCMS
103
120
  :type => self.class.name,
104
121
  :url => url
105
122
  }
@@ -1,18 +1,18 @@
1
1
  module Refinery
2
2
  class PageMenu < Refinery::Core::BaseModel
3
3
 
4
- has_many :positions, :class_name => "::Refinery::PagePosition", :foreign_key => :refinery_menu_id, :dependent => :destroy, :order => "lft ASC"
4
+ has_many :links, :class_name => "::Refinery::MenuLink", :foreign_key => :refinery_menu_id, :dependent => :destroy, :order => "lft ASC"
5
5
 
6
6
  validates :title, :presence => true, :uniqueness => true
7
7
  validates :permatitle, :presence => true, :uniqueness => true
8
- validates_associated :positions
8
+ validates_associated :links
9
9
 
10
- attr_accessible :title, :permatitle, :positions, :positions_attributes
10
+ attr_accessible :title, :permatitle, :links, :links_attributes
11
11
 
12
- accepts_nested_attributes_for :positions, :allow_destroy => true
12
+ accepts_nested_attributes_for :links, :allow_destroy => true
13
13
 
14
14
  def roots
15
- @roots ||= positions.select {|pos| pos.parent_id.nil?}
15
+ @roots ||= links.select {|pos| pos.parent_id.nil?}
16
16
  end
17
17
 
18
18
  end
@@ -1,5 +1,5 @@
1
1
  <div class="field">
2
- <%= f.label :custom_url, "Url" %>
2
+ <%= f.label :custom_url, t('.custom_url') %>
3
3
  <%= f.text_field :custom_url %>
4
4
  </div>
5
5
 
@@ -0,0 +1,29 @@
1
+ <%= fields_for 'page_menu[links_attributes]', menu_link do |f| %>
2
+ <li class='pp-link clearfix record' id="<%= dom_id(menu_link)%>">
3
+ <div class='header'>
4
+ <div class='name'><%= menu_link.label %></div>
5
+ <div class='type'><%= menu_link.type_name %></div>
6
+ <span class='arrow'>&nbsp;</span>
7
+ </div>
8
+ <div class='body'>
9
+ <%= f.hidden_field :id %>
10
+ <% if f.object.custom_link? %>
11
+ <%= render partial: "refinery/admin/menu_links/custom_link", object: menu_link, locals: {f: f} %>
12
+ <% else %>
13
+ <%= render partial: "refinery/admin/menu_links/resource_link", object: menu_link, locals: {f: f} %>
14
+ <% end %>
15
+ <%= link_to t('remove', :scope => 'refinery.admin.menu_links'), admin_menu_link_path(menu_link),
16
+ method: :delete,
17
+ remote: true,
18
+ class: 'remove' %>
19
+ </div>
20
+
21
+ <% if menu_link.children.any? %>
22
+ <ul class='nested'>
23
+ <% menu_link.children.each do |child| %>
24
+ <%= render partial: 'refinery/admin/menu_links/menu_link', object: child %>
25
+ <% end %>
26
+ </ul>
27
+ <% end %>
28
+ </li>
29
+ <% end %>
@@ -10,5 +10,5 @@
10
10
 
11
11
  <div class="field">
12
12
  <%= f.label :original %>
13
- <div class='original-resource'><%= resource_link.resource.title %></div>
13
+ <div class='original-resource'><%= resource_link.resource_title %></div>
14
14
  </div>
@@ -1,21 +1,21 @@
1
1
  <%= content_tag :div, class: "pp-add-box resource-pp-add-box" do %>
2
- <%= form_for [refinery, :admin, @page_menu.positions.build(refinery_resource_type: resource_type)], remote: true do |f| %>
2
+ <%= form_for [refinery, :admin, @page_menu.links.build(refinery_resource_type: resource_type)], remote: true do |f| %>
3
3
  <h3><%= resource_type.to_s.titleize %></h3>
4
4
  <div class='pp-selection-box'>
5
5
  <ul class='checkboxes'>
6
6
  <%= f.hidden_field :refinery_menu_id %>
7
7
  <%= f.hidden_field :refinery_resource_type %>
8
8
 
9
- <% resources = Refinery::PagePosition.find_all_of_type(resource_type) %>
9
+ <% resources = Refinery::MenuLink.find_all_of_type(resource_type) %>
10
10
  <% resources.each_with_index do |object, index| %>
11
11
  <li>
12
12
  <%= check_box_tag "refinery_resource_ids[]", object.id %>
13
- <%= label_tag "refinery_resource_ids[]", object.title %>
13
+ <%= label_tag "refinery_resource_ids[]", object.send(Refinery::MenuLink.resource_config(resource_type)[:title_attr]) %>
14
14
  </li>
15
15
  <% end %>
16
16
  </ul>
17
17
  </div>
18
18
  <% # add resource type here %>
19
- <%= f.submit "Add" %>
19
+ <%= f.submit t('add', :scope => 'refinery.admin.menu_links', resource: resource_type.to_s.titleize) %>
20
20
  <% end %>
21
21
  <% end %>
@@ -0,0 +1,6 @@
1
+ $('.pp-placeholder').remove();
2
+ reset_link_forms();
3
+ <% @menu_links.each do |menu_link| %>
4
+ var partial = '<%= j render partial: "refinery/admin/menu_links/menu_link", object: menu_link %>'
5
+ $('#sortable_list').append(partial);
6
+ <% end %>
@@ -0,0 +1,3 @@
1
+ $('#menu_link_<%= @menu_link.id %>').fadeOut(function(){
2
+ $('#menu_link_<%= @menu_link.id %>').remove();
3
+ });
@@ -10,24 +10,22 @@
10
10
  :include_object_name => true %>
11
11
 
12
12
 
13
-
14
13
  <ul id="sortable_list">
15
- <% if @page_positions.present? %>
16
- <% @page_positions.each do |page_position| %>
17
- <%= render partial: 'refinery/admin/page_positions/page_position', object: page_position %>
14
+ <% if @menu_links.present? %>
15
+ <% @menu_links.each do |menu_link| %>
16
+ <%= render partial: 'refinery/admin/menu_links/menu_link', object: menu_link %>
18
17
  <% end %>
19
18
  <% else %>
20
19
  <li class='pp-placeholder' id="">
21
20
  <%# We need a div here so we don't get a js error for a empty list %>
22
- <div>Use the left side to add links to your menu.</div>
21
+ <div><%= t('.no_links') %></div>
23
22
  </li>
24
23
  <% end %>
25
24
  </ul>
26
25
  </div>
27
26
 
28
-
29
27
  <%= render '/refinery/admin/form_actions', :f => f,
30
28
  :continue_editing => false,
31
- :delete_title => t('delete', :scope => 'refinery.travels.admin.travels.category'),
32
- :delete_confirmation => t('message', :scope => 'refinery.admin.delete') %>
29
+ :delete_title => t('delete', :scope => 'refinery.admin.page_menus.page_menu'),
30
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', title: @page_menu.title) %>
33
31
  <% end %>
@@ -1,23 +1,23 @@
1
1
  <div id='left_actions'>
2
2
 
3
3
  <div id="custom_url_box" class="pp-add-box">
4
- <%= form_for [refinery, :admin, @page_menu.positions.build], remote: true do |f| %>
4
+ <%= form_for [refinery, :admin, @page_menu.links.build], remote: true do |f| %>
5
5
  <%= f.hidden_field :refinery_menu_id %>
6
6
  <h3>Custom Link</h3>
7
7
  <div class='field'>
8
- <%= f.label :custom_url, "Url" %>
8
+ <%= f.label :custom_url, t('custom_url', scope: 'refinery.admin.menu_links.custom_link') %>
9
9
  <%= f.text_field :custom_url %>
10
10
  </div>
11
11
  <div class='field'>
12
12
  <%= f.label :label %>
13
13
  <%= f.text_field :label %>
14
14
  </div>
15
- <%= f.submit "Add" %>
15
+ <%= f.submit t('add', :scope => 'refinery.admin.menu_links.custom_link') %>
16
16
  <% end %>
17
17
  </div>
18
18
 
19
19
  <% Refinery::PageMenus.menu_resources.each do |resource_type, config| %>
20
- <%= render partial: "refinery/admin/page_positions/resource_link_editor_box", locals: { resource_type: resource_type, config: config } %>
20
+ <%= render partial: "refinery/admin/menu_links/resource_link_editor_box", locals: { resource_type: resource_type, config: config } %>
21
21
  <% end %>
22
22
 
23
23
  </div>
@@ -1,4 +1,4 @@
1
- <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%#= dom_id(test) %>">
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(page_menu) %>">
2
2
  <span class='title'>
3
3
  <%= page_menu.title %>
4
4
 
@@ -1,2 +1,3 @@
1
- <%= will_paginate @page_mennus if Refinery::Admin::PageMenusController.pageable? %>
2
- <%= render 'sortable_list' %>
1
+ <ul>
2
+ <%= render :partial => 'page_menu', :collection => @page_menus %>
3
+ </ul>
@@ -6,7 +6,5 @@
6
6
 
7
7
  <%= render '/refinery/admin/make_sortable', :tree => true %>
8
8
 
9
- <%#= render '/refinery/admin/sortable_list', :continue_reordering => !!local_assigns[:continue_reordering] %>
10
-
11
9
  <% content_for :stylesheets, stylesheet_link_tag('refinery/select_form') %>
12
10
  <% content_for :javascripts, javascript_include_tag('refinery/backend.js') %>
@@ -2,35 +2,33 @@ da:
2
2
  refinery:
3
3
  plugins:
4
4
  refinery_page_menus:
5
- title: Side Menu
6
- description: Opret og håndter brugerdefinerede menuer for din side
5
+ title: Menuer
6
+ description: Opret og administrer brugerdefinerede menuer for din side
7
7
  admin:
8
- pages:
9
- form_advanced_options:
10
- show_in_menu_title: Vis i hovedmenuen
11
- show_in_menu_description: Vis siden i hovedmenuen på sitet
12
- show_in_menu_help: Afkryds ikke, hvis du vil fjerne siden fra hovedmenuen på sitet. Dette kan benyttes, hvis du vil have en side, du kan linke til direkte, eller bruge i en anden menu, men som ikke skal vises i hovedmenuen.
13
- actions:
14
- pages:
15
- title: Sider
16
- create_new: Tilføj en ny side
17
- manage: Håndter sider
18
- menus:
19
- title: Menuer
20
- main: Hovedmenu
21
- create_new: Tilføj en ny menu
22
- manage: Håndter menuer
23
- edit: Redigér menuen
8
+ menu_links:
9
+ remove: fjern
10
+ add: "Tilføj %{resource}"
11
+ custom_link:
12
+ add: Tilføj brugerdefineret link
13
+ custom_url: Url
24
14
  page_menus:
25
15
  form:
26
- menu_pages: Sider i menuen
27
- pages_help: Dette er en liste over alle de sider der indgår i menuen. Vælg sider og tryk '<' for at fjerne dem.
28
- all_pages: Sider ikke i menuen
29
- all_pages_help: Dette er en liste over alle tilgængelige sider der ikke indgår i menuen. Vælg hvilke sider der skal indgå i menuen, og tryk '>'.
16
+ no_links: "Brug panelet i venstre, til at tilføje links til din menu."
17
+ records:
18
+ title: Menuer
19
+ no_items_yet: Der er ingen menuer endnu. Bed din webudvikler om at oprette en for dig.
20
+ page_menu:
21
+ edit: Redigér menuen
22
+ delete: Slet menuen permanent
30
23
  activerecord:
31
24
  models:
32
25
  refinery/page_menu: Menu
26
+ refinery/menu_link: Link
33
27
  attributes:
34
28
  refinery/page_menu:
35
29
  title: Titel
36
- pages: Sider
30
+ permatitle: Permanent titel
31
+ refinery/menu_link:
32
+ title_attribute: Titel attribut
33
+ custom_url: Url
34
+ label: Label
@@ -2,35 +2,33 @@ en:
2
2
  refinery:
3
3
  plugins:
4
4
  refinery_page_menus:
5
- title: Page Menu
5
+ title: Menus
6
6
  description: Create and manage custom menus for your site
7
7
  admin:
8
- pages:
9
- form_advanced_options:
10
- show_in_menu_title: Show in mainmenu
11
- show_in_menu_description: Show the page in the mainmenu on the site
12
- show_in_menu_help: Uncheck this box if you want to remove a page from your mainmenu. This can be handy if you have a page you want to link people to directly or use in another menu but don&apos;t want to show the page in the menu.
13
- actions:
14
- pages:
15
- title: Pages
16
- create_new: Add new page
17
- manage: Manage pages
18
- menus:
19
- title: Menus
20
- main: Mainmenu
21
- create_new: Add new menu
22
- manage: Manage menus
23
- edit: Edit this menu
8
+ menu_links:
9
+ remove: remove
10
+ add: "Add %{resource}"
11
+ custom_link:
12
+ add: Add Custom Link
13
+ custom_url: Url
24
14
  page_menus:
25
15
  form:
26
- menu_pages: Pages in the menu
27
- pages_help: This is a list of all the pages for this menu. Select pages and click '<' to remove them from the menu.
28
- all_pages: Pages not in the menu
29
- all_pages_help: This is a list of all available pages that&apos;s not in the menu already. Select those pages you want in the menu and click '>' to add them.
16
+ no_links: Use the left side to add links to your menu.
17
+ records:
18
+ title: Menus
19
+ no_items_yet: There are no menues yet. Ask your developer to create one for you.
20
+ page_menu:
21
+ edit: Edit this menu
22
+ delete: Remove this menu forever
30
23
  activerecord:
31
24
  models:
32
25
  refinery/page_menu: Menu
26
+ refinery/menu_link: Link
33
27
  attributes:
34
28
  refinery/page_menu:
35
29
  title: Title
36
- pages: Pages
30
+ permatitle: Permatitle
31
+ refinery/menu_link:
32
+ title_attribute: Title attribute
33
+ custom_url: Url
34
+ label: Label
@@ -2,32 +2,8 @@ fr:
2
2
  refinery:
3
3
  plugins:
4
4
  refinery_page_menus:
5
- title: Menu de pages
5
+ title: Menus
6
6
  description: Cr&eacute;er et g&eacute;rer des menus personnalis&eacute;s pour votre site
7
- admin:
8
- pages:
9
- form_advanced_options:
10
- show_in_menu_title: Afficher dans le menu principal (mainmenu)
11
- show_in_menu_description: Afficher la page dans le menu principal (mainmenu) du site
12
- show_in_menu_help: D&eacute;cochez cette case si vous souhaitez supprimer une page de votre menu principal (mainmenu). Cela peut &ecirc;tre pratique si vous avez une page que vous souhaitez lier directement ou utiliser dans un autre menu.
13
- This can be handy if you have a page you want to link people to directly or use in another menu but don&apos;t want to show the page in the menu.
14
- actions:
15
- pages:
16
- title: Pages
17
- create_new: Cr&eacute;er une nouvelle page
18
- manage: G&eacute;rer les pages
19
- menus:
20
- title: Menus
21
- main: Menu principal (mainmenu)
22
- create_new: Cr&eacute;er un nouveau menu
23
- manage: G&eacute;rer les menus
24
- edit: Modifier ce menu
25
- page_menus:
26
- form:
27
- menu_pages: Pages dans le menu
28
- pages_help: Ceci est la liste de toutes les pages ins&eacute;r&eacute;es dans le menu. S&eacute;lectionnez les pages et cliquez sur le bouton &apos;<&apos; pour les enlever de ce menu.
29
- all_pages: Pages hors du menu
30
- all_pages_help: Ceci est la liste de toutes les pages qui ne sont pas encore ins&eacute;r&eacute;es dans le menu. S&eacute;lectionnez les pages que vous souhaitez avoir dans le menu et cliquez sur le bouton &apos;>&apos; pour les ajouter.
31
7
  activerecord:
32
8
  models:
33
9
  refinery/page_menu: Menu
@@ -2,11 +2,11 @@ Refinery::Core::Engine.routes.draw do
2
2
 
3
3
  # Admin routes
4
4
  namespace :admin, :path => 'refinery' do
5
- resources :page_positions, only: [:create, :destroy]
5
+ resources :menu_links, only: [:create, :destroy]
6
6
 
7
7
  resources :page_menus do
8
8
  post :update_positions, :on => :collection
9
- resources :page_positions, :only => [:index, :show] do
9
+ resources :menu_links, :only => [:index, :show] do
10
10
  post :update_positions, :on => :collection
11
11
  end
12
12
  end
@@ -0,0 +1,5 @@
1
+ class RenamePagePositionsToMenuLinks < ActiveRecord::Migration
2
+ def change
3
+ rename_table :refinery_page_positions, :refinery_menu_links
4
+ end
5
+ end
@@ -14,5 +14,5 @@ if defined?(::Refinery::PageMenu)
14
14
  end
15
15
 
16
16
  Refinery::PageMenus.default_menus.each do |menu|
17
- Refinery::PageMenu.create(title: menu.titleize, permatitle: menu)
17
+ Refinery::PageMenu.create(title: menu.titleize, permatitle: menu.underscore)
18
18
  end
@@ -2,12 +2,10 @@ require 'refinerycms-core'
2
2
 
3
3
  module Refinery
4
4
  autoload :PageMenusGenerator, 'generators/refinery/page_menus/page_menus_generator'
5
- autoload :InstanceMethods, 'refinery/page_menus/admin/instance_methods'
6
5
 
7
6
  module PageMenus
8
7
  require 'refinery/page_menus/engine'
9
8
  require 'refinery/page_menus/configuration'
10
- require 'refinery/page_menus/controller_extension'
11
9
 
12
10
  autoload :InstanceMethods, 'refinery/page_menus/instance_methods'
13
11
 
@@ -14,7 +14,7 @@ module Refinery
14
14
  self.menu_resources = {
15
15
  refinery_page: {
16
16
  klass: 'Refinery::Page',
17
- admin_partial: '/refinery/admin/page_positions/page_position',
17
+ admin_partial: '/refinery/admin/menu_links/menu_link',
18
18
  title_attr: 'title',
19
19
  admin_page_filter: {
20
20
  draft: false
@@ -14,18 +14,12 @@ module Refinery
14
14
 
15
15
  initializer "register refinery_page_menus plugin" do
16
16
  Refinery::Plugin.register do |plugin|
17
- plugin.name = 'page_menus'
17
+ plugin.name = 'refinery_page_menus'
18
18
  plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_page_menus_path }
19
19
  plugin.pathname = root
20
- plugin.menu_match = /refinery\/(page_menus|main_menu|page_positions)/ #Match controller path
21
- # plugin.hide_from_menu = true
20
+ plugin.menu_match = /refinery\/(page_menus|menu_links)/ #Match controller path
22
21
  end
23
22
  end
24
-
25
- # config.to_prepare do
26
- # require 'refinerycms-pages'
27
- # Refinery::Admin::PagesController.send :has_and_belongs_to_page_menus
28
- # end
29
23
 
30
24
  config.after_initialize do
31
25
  Refinery.register_extension(Refinery::PageMenus)
@@ -8,7 +8,7 @@ module Refinery
8
8
 
9
9
  # Compiles a page menu.
10
10
  def refinery_page_menu(menu_title)
11
- ::Refinery::Menu.new(::Refinery::PageMenu.find_or_create_by_permatitle(menu_title).positions).roots
11
+ ::Refinery::Menu.new(::Refinery::PageMenu.find_or_create_by_permatitle(menu_title).links).roots
12
12
  end
13
13
 
14
14
  end
@@ -3,7 +3,7 @@ module Refinery
3
3
  class Version
4
4
  @major = 2
5
5
  @minor = 0
6
- @tiny = 4
6
+ @tiny = 5
7
7
  @build = nil
8
8
 
9
9
  class << self
@@ -0,0 +1,65 @@
1
+ namespace :refinery do
2
+
3
+ namespace :page_menus do
4
+
5
+ desc "Create a new menu"
6
+ task :create_menu => :environment do
7
+ permatitle = ENV['permatitle'] || ENV['perma']
8
+ title = ENV['title']
9
+ if title
10
+ permatitle = title.gsub(' ', '_').underscore if permatitle.nil?
11
+ begin
12
+ menu = Refinery::PageMenu.create!(title: title, permatitle: permatitle)
13
+ puts "Created new menu with title '#{title}' and permatitle '#{permatitle}'"
14
+ puts "To use this menu in your views, paste this code into your view file:"
15
+ puts "<%= render :partial => '/refinery/menu', :locals => { "
16
+ puts " :roots => refinery_page_menu('#{permatitle}') } %>"
17
+ rescue Exception => e
18
+ puts e
19
+ end
20
+ else
21
+ puts "You didn't specify a title for your menu. Here are some examples:"
22
+ puts "rake refinery:page_menus:create_menu title='Top Menu'"
23
+ puts "rake refinery:page_menus:create_menu permatitle=footer_menu"
24
+ puts "rake refinery:page_menus:create_menu title='Sitebar Menu' permatitle=sitebar_menu"
25
+ puts ""
26
+ puts "If not presnce permatitles will be underscored version of the title input, ie:"
27
+ puts "title='Top Menu' will result in the permatitle 'top_menu'"
28
+ end
29
+ end
30
+
31
+ desc "Create a new menu"
32
+ task :menus => :environment do
33
+ begin
34
+ menus = Refinery::PageMenu.all
35
+
36
+ if menus.none?
37
+ puts "You don't have any menus."
38
+ puts "To create a new menu, run this rake task:"
39
+ puts "rake refinery:page_menus:create_menu title='your menu title'"
40
+ elsif menus.one?
41
+ puts "You have the one menu '#{menus.first.title}' with the permatitle '#{menus.first.permatitle}'."
42
+ puts ""
43
+ puts "To use '#{menus.first.title}' in your views, paste this code into your view file:"
44
+ puts "<%= render :partial => '/refinery/menu', :locals => { "
45
+ puts " :roots => refinery_page_menu('#{menus.first.permatitle}') } %>"
46
+ elsif menus.many?
47
+ puts "Your have the following menus:"
48
+ menus.each do |menu|
49
+ puts "'#{menu.title}' with permatitle '#{menu.permatitle}'"
50
+ end
51
+ puts ""
52
+ puts "To use one of these menus in your views, paste this code into your view file:"
53
+ puts "<%= render :partial => '/refinery/menu', :locals => { "
54
+ puts " :roots => refinery_page_menu('<PERMATITLE>') } %>"
55
+ puts "and replace <PERMATITLE> with the permatitle for the choosen menu"
56
+ end
57
+
58
+ rescue Exception => e
59
+ puts e
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
data/readme.md CHANGED
@@ -1,22 +1,19 @@
1
1
  # Page Menus Extension for Refinery CMS
2
2
 
3
- ## IMPORTANT: IN DEVELOPMENT!
4
-
5
- This extension is still in development! There is no tests yet.
6
- Also you can't create new menus in the admin interface, you have to create them yourself.
7
-
8
- A stable complete version will soon be released.
9
-
10
3
  If you are willing to contribute please send me a mail (johan@pylonweb.dk), and follow the contribution guidelines below. Especially test would be appriciated!
11
4
 
12
5
  ## About
13
6
 
14
7
  Page menus allows you to create and edit several custom menus for your Refinery CMS app.
15
8
 
9
+ ![image](https://raw.github.com/pylonweb/refinerycms-page-menus/master/doc/refinery_menu_edit.png)
10
+
16
11
  ## Requirements
17
12
 
18
13
  * refinerycms >= 2.0.6
19
14
 
15
+ (have not been tested on lower versions but does most likely work on all versions after 2.0.0)
16
+
20
17
  ## Install
21
18
 
22
19
  Add this line to your applications `Gemfile`
@@ -42,19 +39,31 @@ rake db:migrate
42
39
  Now when you start up your Refinery application, go to the pages in your admin interface, and you should see a roll-down menu called "Menus".
43
40
 
44
41
  ## Usage
42
+ ### Add to your view
45
43
 
46
- `app/views/refinery/pages/_header.html.erb`
47
-
44
+ Go to `app/views/refinery/pages/_header.html.erb` in your application.
48
45
  If you don't have this file then Refinery will be using its default. You can override this with
49
46
 
50
47
  ```bash
51
48
  rake refinery:override view=refinery/_header
52
49
  ```
53
50
 
51
+ Then add this code to the header, to generate the custom menu:
54
52
  ```erb
55
- == render :partial => "/refinery/menu", :locals => {
56
- :roots => refinery_page_menu("custom_menu")
57
- }
53
+ <%= render :partial => "/refinery/menu", :locals => {
54
+ :roots => refinery_page_menu("custom_menu")
55
+ } %>
56
+ ```
57
+ "custom_menu" must be replaced by the permatitle of your menu.
58
+ ### Rake commands
59
+ To show list all your menus and their permatitles run this rake task:
60
+ ```bash
61
+ rake refinery:page_menus:menus
62
+ ```
63
+
64
+ You can create a new menu in the rails console, or you can use the following command:
65
+ ```bash
66
+ rake refinery:page_menus:create_menu title=some_title
58
67
  ```
59
68
 
60
69
  ## Contributing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-page-menus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,22 +59,6 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.1.0
62
- - !ruby/object:Gem::Dependency
63
- name: nokogiri
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 1.5.5
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 1.5.5
78
62
  - !ruby/object:Gem::Dependency
79
63
  name: refinerycms-testing
80
64
  requirement: !ruby/object:Gem::Requirement
@@ -99,25 +83,23 @@ extra_rdoc_files: []
99
83
  files:
100
84
  - app/assets/javascripts/refinery/backend.js.coffee
101
85
  - app/assets/stylesheets/refinery/select_form.css.scss
86
+ - app/controllers/refinery/admin/menu_links_controller.rb
102
87
  - app/controllers/refinery/admin/page_menus_controller.rb
103
- - app/controllers/refinery/admin/page_positions_controller.rb
104
- - app/helpers/refinery/page_positions_helper.rb
88
+ - app/models/refinery/menu_link.rb
105
89
  - app/models/refinery/page_menu.rb
106
- - app/models/refinery/page_position.rb
90
+ - app/views/refinery/admin/menu_links/_custom_link.html.erb
91
+ - app/views/refinery/admin/menu_links/_menu_link.html.erb
92
+ - app/views/refinery/admin/menu_links/_resource_link.html.erb
93
+ - app/views/refinery/admin/menu_links/_resource_link_editor_box.html.erb
94
+ - app/views/refinery/admin/menu_links/create.js.erb
95
+ - app/views/refinery/admin/menu_links/destroy.js.erb
107
96
  - app/views/refinery/admin/page_menus/_form.html.erb
108
97
  - app/views/refinery/admin/page_menus/_form_actions.html.erb
109
98
  - app/views/refinery/admin/page_menus/_page_menu.html.erb
110
99
  - app/views/refinery/admin/page_menus/_page_menus.html.erb
111
100
  - app/views/refinery/admin/page_menus/_records.html.erb
112
- - app/views/refinery/admin/page_menus/_sortable_list.html.erb
113
101
  - app/views/refinery/admin/page_menus/edit.html.erb
114
102
  - app/views/refinery/admin/page_menus/index.html.erb
115
- - app/views/refinery/admin/page_positions/_custom_link.html.erb
116
- - app/views/refinery/admin/page_positions/_page_position.html.erb
117
- - app/views/refinery/admin/page_positions/_resource_link.html.erb
118
- - app/views/refinery/admin/page_positions/_resource_link_editor_box.html.erb
119
- - app/views/refinery/admin/page_positions/create.js.erb
120
- - app/views/refinery/admin/page_positions/destroy.js.erb
121
103
  - config/locales/da.yml
122
104
  - config/locales/en.yml
123
105
  - config/locales/fr.yml
@@ -127,16 +109,17 @@ files:
127
109
  - db/migrate/03_add_menu_match_to_page_positions.rb
128
110
  - db/migrate/04_add_flex_fields_to_page_positions.rb
129
111
  - db/migrate/05_remove_refinery_page_id_from_refinery_page_positions.rb
112
+ - db/migrate/06_rename_page_positions_to_menu_links.rb
130
113
  - db/seeds.rb
131
114
  - lib/generators/refinery/page_menus/page_menus_generator.rb
132
115
  - lib/generators/refinery/page_menus/templates/config/initializers/refinery/page_menus.rb.erb
133
116
  - lib/refinery/page_menus/configuration.rb
134
- - lib/refinery/page_menus/controller_extension.rb
135
117
  - lib/refinery/page_menus/engine.rb
136
118
  - lib/refinery/page_menus/instance_methods.rb
137
119
  - lib/refinery/page_menus/version.rb
138
120
  - lib/refinery/page_menus.rb
139
121
  - lib/refinerycms-page-menus.rb
122
+ - lib/tasks/refinery/page_menus.rake
140
123
  - readme.md
141
124
  homepage: http://github.com/pylonweb/refinerycms-page-menus
142
125
  licenses:
@@ -151,12 +134,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
134
  - - ! '>='
152
135
  - !ruby/object:Gem::Version
153
136
  version: '0'
137
+ segments:
138
+ - 0
139
+ hash: 1045030147705129350
154
140
  required_rubygems_version: !ruby/object:Gem::Requirement
155
141
  none: false
156
142
  requirements:
157
143
  - - ! '>='
158
144
  - !ruby/object:Gem::Version
159
145
  version: '0'
146
+ segments:
147
+ - 0
148
+ hash: 1045030147705129350
160
149
  requirements: []
161
150
  rubyforge_project:
162
151
  rubygems_version: 1.8.23
@@ -1,66 +0,0 @@
1
- module Refinery
2
- module PagePositionsHelper
3
- require 'nokogiri'
4
-
5
- def render_menu_list(page_positions)
6
- results = "".html_safe
7
- page_positions.each do |page_position|
8
- if page_position.custom_link?
9
- results << render_custom_menu_link(page_position)
10
- else
11
- results << render_resource_menu_link(page_position)
12
- end
13
- end
14
- results
15
- end
16
-
17
- def render_custom_menu_link(page_position)
18
- list_partial = render(partial: "custom_page_position", locals: {page_position: page_position})
19
-
20
- dom = Nokogiri::HTML.fragment(list_partial)
21
- li = dom.css('li').first
22
-
23
- # append nested ul to end of this li
24
- li << nested_ul(page_position)
25
-
26
- dom.to_s.html_safe
27
- end
28
-
29
- def render_resource_menu_link(page_position)
30
- list_partial = render(:partial => page_position.resource_config[:admin_partial], :collection => [page_position.resource])
31
-
32
- dom = Nokogiri::HTML.fragment(list_partial)
33
- li = dom.css('li').first
34
-
35
- # change li's id to that of the page_partial
36
- li['id'] = dom_id(page_position)
37
-
38
- # wrap inside of li in div if it's not already
39
- if dom.css('li > div').empty?
40
- div = Nokogiri.make("<div class='clearfix'></div>")
41
- div.children = li.children
42
- li.children = div
43
- end
44
-
45
- # edit title to show actual link label as well
46
- title_div = dom.css('.title').first
47
- if title_div.present?
48
- title_div.content = page_position.label
49
- end
50
-
51
- # append nested ul to end of this li
52
- li << nested_ul(page_position)
53
-
54
- dom.to_s.html_safe
55
- end
56
-
57
- def nested_ul(page_position)
58
- # recursively create nested list of children
59
- content_tag :ul, class: 'nested' do
60
- render_menu_list(page_position.children)
61
- end
62
- end
63
-
64
-
65
- end
66
- end
@@ -1,5 +0,0 @@
1
- <ul id='sortable_list'>
2
- <%= render :partial => 'page_menu', :collection => @page_menus %>
3
- </ul>
4
- <%= render '/refinery/admin/sortable_list',
5
- :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
@@ -1,26 +0,0 @@
1
- <%= fields_for 'page_menu[positions_attributes]', page_position do |f| %>
2
- <li class='pp-link clearfix record' id="<%= dom_id(page_position)%>">
3
- <div class='header'>
4
- <div class='name'><%= page_position.title %></div>
5
- <div class='type'><%= page_position.type_name %></div>
6
- <span class='arrow'>&nbsp;</span>
7
- </div>
8
- <div class='body'>
9
- <%= f.hidden_field :id %>
10
- <% if f.object.custom_link? %>
11
- <%= render partial: "refinery/admin/page_positions/custom_link", object: page_position, locals: {f: f} %>
12
- <% else %>
13
- <%= render partial: "refinery/admin/page_positions/resource_link", object: page_position, locals: {f: f} %>
14
- <% end %>
15
- <%= link_to "remove", admin_page_position_path(page_position), method: :delete, remote: true, class: 'remove' %>
16
- </div>
17
-
18
- <% if page_position.children.any? %>
19
- <ul class='nested'>
20
- <% page_position.children.each do |child| %>
21
- <%= render partial: 'refinery/admin/page_positions/page_position', object: child %>
22
- <% end %>
23
- </ul>
24
- <% end %>
25
- </li>
26
- <% end %>
@@ -1,5 +0,0 @@
1
- $('.pp-placeholder').remove();
2
- <% @page_positions.each do |page_position| %>
3
- var partial = '<%= j render partial: "refinery/admin/page_positions/page_position", object: page_position %>'
4
- $('#sortable_list').append(partial);
5
- <% end %>
@@ -1,3 +0,0 @@
1
- $('#page_position_<%= @page_position.id %>').fadeOut(function(){
2
- $('#page_position_<%= @page_position.id %>').remove();
3
- });
@@ -1,48 +0,0 @@
1
- module Refinery
2
- module PageMenus
3
- module ControllerExtension
4
-
5
- def has_and_belongs_to_page_menus
6
-
7
- before_filter :find_all_menus, :only => [:index, :list]
8
-
9
- module_eval do
10
-
11
- def list
12
- unless searching?
13
- find_all_pages
14
- else
15
- search_all_pages
16
- end
17
-
18
- render_partial_response?
19
- end
20
-
21
- def index
22
- unless searching?
23
- if Refinery::PageMenus.show_hidden_pages_in_main_menu
24
- find_all_pages
25
- else
26
- @pages = Refinery::Page.where(:show_in_menu => true).includes(:translations, :children).order("lft ASC")
27
- end
28
- else
29
- search_all_pages
30
- end
31
-
32
- render_partial_response?
33
- end
34
-
35
- protected
36
-
37
- def find_all_menus
38
- @page_menus = Refinery::PageMenu.order('title ASC')
39
- end
40
-
41
- end
42
-
43
- end
44
- end
45
- end
46
- end
47
-
48
- ActionController::Base.send(:extend, Refinery::PageMenus::ControllerExtension)