Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML id and class attributes to MenuLinks #18

Merged
merged 9 commits into from
Jan 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,30 @@ pkg/
wiki/

# Other stuff
.idea/
.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
33 changes: 17 additions & 16 deletions app/assets/stylesheets/refinery/select_form.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.select_to{
display:block;
float:left;
float:left;
width: 100%;
}

Expand All @@ -22,7 +22,6 @@
.pp-add-box {
background: #aaa;
margin-top: 20px;
width: 220px;
padding: 15px;

h3 {
Expand Down Expand Up @@ -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;
}
Expand All @@ -74,32 +73,29 @@
}
}


}

#pp-select-container {
position: relative;
}

#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;
Expand Down Expand Up @@ -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;
Expand All @@ -147,7 +143,7 @@
display: none;
background: #dbedff;
padding: 15px;
height: 100px;

position: relative;

label {
Expand All @@ -161,7 +157,7 @@
input {
width: 250px;
}

a.remove {
position: absolute;
right: 10px;
Expand All @@ -177,6 +173,11 @@

}

#page_menu_form {
float: right;
width: 700px;
}

.field input[type=text] {
padding: 3px 5px;
}
22 changes: 12 additions & 10 deletions app/models/refinery/menu_link.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -59,7 +59,7 @@ def resource_config
def resource_type
refinery_resource_type || "Custom link"
end

def type_name
resource_type.titleize
end
Expand Down Expand Up @@ -88,7 +88,7 @@ def title
def resource_url
resource.present? ? resource.url : '/'
end

def url
if custom_link?
custom_url
Expand Down Expand Up @@ -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
19 changes: 15 additions & 4 deletions app/views/refinery/admin/menu_links/_menu_link.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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,

<div class="field">
<%= f.label :id_attribute, t('id_attribute', :scope => 'refinery.admin.menu_links') %>
<%= f.text_field :id_attribute %>
</div>

<div class="field">
<%= f.label :class_attribute %>
<%= f.text_field :class_attribute %>
</div>

<%= link_to t('remove', :scope => 'refinery.admin.menu_links'), admin_menu_link_path(menu_link),
method: :delete,
remote: true,
class: 'remove' %>
</div>

<ul class='nested'>
<% menu_link.children.each do |child| %>
<%= render partial: 'refinery/admin/menu_links/menu_link', object: child %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/07_add_class_and_id_attribute_to_menu_links.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand Down
19 changes: 15 additions & 4 deletions spec/models/refinery/menu_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down