diff --git a/.gitignore b/.gitignore
index 8948c7c..a3f0b7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,30 @@ pkg/
wiki/
# Other stuff
-.idea/
\ No newline at end of file
+.idea/
+.bundle/config
+bin/autospec
+bin/coderay
+bin/erubis
+bin/guard
+bin/htmldiff
+bin/launchy
+bin/ldiff
+bin/nokogiri
+bin/pry
+bin/rackup
+bin/rails
+bin/rake
+bin/rake2thor
+bin/rdoc
+bin/refinerycms
+bin/ri
+bin/rspec
+bin/sass
+bin/sass-convert
+bin/scss
+bin/spork
+bin/sprockets
+bin/thor
+bin/tilt
+bin/tt
\ No newline at end of file
diff --git a/app/assets/stylesheets/refinery/select_form.css.scss b/app/assets/stylesheets/refinery/select_form.css.scss
index 1a791cf..ad1128b 100644
--- a/app/assets/stylesheets/refinery/select_form.css.scss
+++ b/app/assets/stylesheets/refinery/select_form.css.scss
@@ -6,7 +6,7 @@
.select_to{
display:block;
- float:left;
+ float:left;
width: 100%;
}
@@ -22,7 +22,6 @@
.pp-add-box {
background: #aaa;
margin-top: 20px;
- width: 220px;
padding: 15px;
h3 {
@@ -51,17 +50,17 @@
}
#left_actions {
- position:absolute;
- top: 63px;
+ float: left;
+ width: 250px;
- .controls a {
+ .controls a {
background-color: #dbedff;
background-position: 12px;
background-repeat: no-repeat;
border: 1px solid #65C3F7;
display: block;
padding: 9px 12px 9px 36px;
-
+
&:hover {
background-color: #cae7fb;
}
@@ -74,7 +73,7 @@
}
}
-
+
}
#pp-select-container {
@@ -82,24 +81,21 @@
}
#links-container {
- padding-left: 250px;
- padding-right: 10px;
#sortable_list {
- margin: 20px 0 0 20px;
padding: 10px 20px 20px 20px;
background: #eee;
width: 650px;
min-height: 400px;
-
+
list-style: none;
-
+
ul {
li {
list-style: none;
}
list-style: none;
}
-
+
.pp-placeholder {
margin-top: 10px;
cursor: default;
@@ -133,7 +129,7 @@
.arrow {
background-repeat: no-repeat;
background-image: url(/assets/refinery/icons/down.gif);
- background-position:center;
+ background-position:center;
position: absolute;
right: 0px;
top: 0px;
@@ -147,7 +143,7 @@
display: none;
background: #dbedff;
padding: 15px;
- height: 100px;
+
position: relative;
label {
@@ -161,7 +157,7 @@
input {
width: 250px;
}
-
+
a.remove {
position: absolute;
right: 10px;
@@ -177,6 +173,11 @@
}
+#page_menu_form {
+ float: right;
+ width: 700px;
+}
+
.field input[type=text] {
padding: 3px 5px;
}
\ No newline at end of file
diff --git a/app/models/refinery/menu_link.rb b/app/models/refinery/menu_link.rb
index ccf19f2..8825e89 100644
--- a/app/models/refinery/menu_link.rb
+++ b/app/models/refinery/menu_link.rb
@@ -1,16 +1,16 @@
module Refinery
class MenuLink < Refinery::Core::BaseModel
-
+
attr_accessible :parent_id, :refinery_page_id, :refinery_menu_id, :refinery_resource_id, :refinery_resource_type,
- :title_attribute, :custom_url, :label, :menu
-
+ :title_attribute, :custom_url, :label, :menu, :id_attribute, :class_attribute
+
belongs_to :menu, :class_name => '::Refinery::PageMenu', :foreign_key => :refinery_menu_id
belongs_to :resource, :foreign_key => :refinery_resource_id, :polymorphic => true
# Docs for acts_as_nested_set https://github.com/collectiveidea/awesome_nested_set
# rather than :delete_all we want :destroy
acts_as_nested_set :dependent => :destroy
-
+
validates :menu, :presence => true
validates :label, :presence => true
@@ -38,12 +38,12 @@ def set_label
if label.blank?
if custom_link?
begin
- self.label = custom_url.match(/(\w+)\.\w+$/).captures.join.titleize
+ self.label = custom_url.match(/(\w+)\.\w+$/).captures.join.titleize
rescue
self.label = custom_url
end
else
- self.label = resource.send(resource_config[:title_attr])
+ self.label = resource.send(resource_config[:title_attr])
end
end
end
@@ -59,7 +59,7 @@ def resource_config
def resource_type
refinery_resource_type || "Custom link"
end
-
+
def type_name
resource_type.titleize
end
@@ -88,7 +88,7 @@ def title
def resource_url
resource.present? ? resource.url : '/'
end
-
+
def url
if custom_link?
custom_url
@@ -119,9 +119,11 @@ def to_refinery_menu_item
:menu_title => label,
:title => title,
:type => self.class.name,
- :url => url
+ :url => url,
+ :id_attribute => id_attribute,
+ :class_attribute => class_attribute
}
end
-
+
end
end
diff --git a/app/views/refinery/admin/menu_links/_menu_link.html.erb b/app/views/refinery/admin/menu_links/_menu_link.html.erb
index 137a959..aba387c 100644
--- a/app/views/refinery/admin/menu_links/_menu_link.html.erb
+++ b/app/views/refinery/admin/menu_links/_menu_link.html.erb
@@ -12,12 +12,23 @@
<% else %>
<%= render partial: "refinery/admin/menu_links/resource_link", object: menu_link, locals: {f: f} %>
<% end %>
- <%= link_to t('remove', :scope => 'refinery.admin.menu_links'), admin_menu_link_path(menu_link),
- method: :delete,
- remote: true,
+
+
+ <%= f.label :id_attribute, t('id_attribute', :scope => 'refinery.admin.menu_links') %>
+ <%= f.text_field :id_attribute %>
+
+
+
+ <%= f.label :class_attribute %>
+ <%= f.text_field :class_attribute %>
+
+
+ <%= link_to t('remove', :scope => 'refinery.admin.menu_links'), admin_menu_link_path(menu_link),
+ method: :delete,
+ remote: true,
class: 'remove' %>
-
+
<% menu_link.children.each do |child| %>
<%= render partial: 'refinery/admin/menu_links/menu_link', object: child %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d5845e2..38b3c42 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -11,6 +11,7 @@ en:
custom_link:
add: Add Custom Link
custom_url: Url
+ id_attribute: ID attribute
page_menus:
form:
no_links: Use the left side to add links to your menu.
diff --git a/db/migrate/07_add_class_and_id_attribute_to_menu_links.rb b/db/migrate/07_add_class_and_id_attribute_to_menu_links.rb
new file mode 100644
index 0000000..fd03550
--- /dev/null
+++ b/db/migrate/07_add_class_and_id_attribute_to_menu_links.rb
@@ -0,0 +1,6 @@
+class AddClassAndIdAttributeToMenuLinks < ActiveRecord::Migration
+ def change
+ add_column :refinery_menu_links, :id_attribute, :string
+ add_column :refinery_menu_links, :class_attribute, :string
+ end
+end
diff --git a/readme.md b/readme.md
index 1f8f4ba..2cb8a66 100644
--- a/readme.md
+++ b/readme.md
@@ -57,9 +57,9 @@ rake refinery:override view=refinery/_header
Then add this code to the header, to generate the custom menu:
```erb
-<%= render :partial => "/refinery/menu", :locals => {
+<%= render :partial => "/refinery/menu", :locals => {
:roots => refinery_page_menu("custom_menu")
- } %>
+ } %>
```
"custom_menu" must be replaced by the permatitle of your menu.
### Rake commands
@@ -75,7 +75,7 @@ rake refinery:page_menus:create_menu title=some_title
### Configuration
Refinerycms Page Menus is very flexible and is very easy to setup your own models, so you can link to them in your menus. To add a new model to Refinerycms Page Menus, just go to the config file (`config/initializers/refinery/page_menus.rb`) and follow the instructions on how to add your model to the `menu_resources` configuration option.
-Your model only have to respond to two methods:
+Your model only have to respond to two methods:
* `url` which must define which path the menu link should link to.
* A custom title method that you can specify in the configuration.
@@ -99,7 +99,10 @@ We will very much appreciate all kinds of contributions to refinerycms-page-menu
If you have any issues or questions, that you cannot find the answer to here, then please feel free to add an [issue on GitHub](https://github.com/refinery/refinerycms-page-images/issues/new).
### Running tests
-Refinery Page Menus uses RSpec to test. See the documentation on [RSpec GitHub page](https://github.com/rspec/rspec). You can run all specs by running the command `bundle exec rake`.
+Refinery Page Menus uses RSpec to test. See the documentation on [RSpec GitHub page](https://github.com/rspec/rspec).
+
+1. To run the test suite, you must first install a dummy refinery app to test against: `bundle exec refinery:testing:dummy_app`. See the [Refinery Testing Guide](http://refinerycms.com/guides/testing) for more info.
+2. You can run all specs by running the command `bundle exec rake`.
## Screenshot
diff --git a/spec/models/refinery/menu_link_spec.rb b/spec/models/refinery/menu_link_spec.rb
index e38c141..95f3cc5 100644
--- a/spec/models/refinery/menu_link_spec.rb
+++ b/spec/models/refinery/menu_link_spec.rb
@@ -51,6 +51,17 @@ module Refinery
end
end
+ describe 'attributes' do
+ %w(class_attribute id_attribute).each do |attribute|
+ it "makes the #{attribute} attribute available to Refinery MenuItems" do
+ ml = MenuLink.new
+ ml.send("#{attribute}=".to_sym, 'the_test_val')
+ m = Refinery::MenuItem.new(ml.to_refinery_menu_item)
+ m[attribute].should eq('the_test_val')
+ end
+ end
+ end
+
describe ".find_all_of_type" do
before(:each) do
@configuration = { admin_page_filter: { draft: false }}
@@ -76,7 +87,7 @@ module Refinery
it "should apply admin_page_filters if present" do
Refinery::MenuLink.stub(:resource_config).with(:refinery_resource).and_return(@configuration)
-
+
Refinery::MenuLink.find_all_of_type(:refinery_resource).should_not include(@resource_draft)
Refinery::MenuLink.find_all_of_type(:refinery_resource).should include(@resource_puplished)
end
@@ -91,7 +102,7 @@ module Refinery
draft: false
}
}
-
+
Refinery::MenuLink.stub(:resource_config).with(:refinery_resource).and_return(@configuration)
Refinery::MenuLink.stub(:resource_config).with(:refinery_another_resource).and_return(nil)
end
@@ -152,7 +163,7 @@ module Refinery
expect{ @menu_link.set_label }.to change { @menu_link.label }.from(nil).to(@resource.title)
end
- end
+ end
describe "#resource_klass" do
it "should call class method resource_klass" do
@@ -258,7 +269,7 @@ module Refinery
@menu_link.resource_title.should == "A title"
end
end
-
+
describe "#title" do
it "should return title_attribute if present" do
@menu_link = FactoryGirl.build(:menu_link, title_attribute: "Title")