Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for other menus #111

Closed
wants to merge 4 commits into from

3 participants

@ashmckenzie

Hi Graham,

I had the need to create a categories.txt (in the same style as menu.txt), so made a few minor changes to support this.

Hopefully it's a desirable change.

Ash.

Ash McKenzie added support for different menus
menu.txt is still the default, but other menus can now be read.
dca61f9
@gma
Owner

Hi Ash. Thanks. Does this allow you to setup menus that can't be produced by including whatever menu hierarchy you like in menu.txt, and then using the menu rendering helpers to render just a small part of the full menu.txt file?

@ashmckenzie

Hi :) I'm using the menu.txt for page links and wanted to keep links to page / article categories separate. I tried to work menu.txt to my needs but it didn't seem like a logical fit. The site I'm working on is http://new.ashmckenzie.org/ (still a WIP)

Happy for advice on how I might be able to achieve this using the existing heleprs ?

@gma
Owner
@ashmckenzie

Sorry for the (very) late response. Thanks for the suggestion, I tried it but it didn't work for me as in my case the contents of my categories.txt are located at the root level:

euro-trip-2010
mongo
ruby
devops
display_menu(Nesta::Menu.for_path('/', 'categories.txt'), :levels => 1)

See the menu.txt entries on the left and the categories.txt entries on the right - http://ashmckenzie.org/

@travisbot

This pull request passes (merged c58158a into 025188a).

@gma
Owner

I'm going to have a think about whether or not this can be done sensibly with a single menu file. I'm not massively comfortable with the proliferation of lots of .txt files in content (perhaps they should be .menu files). Thinking about it…

In the meantime, I'm going to close this issue to things tidy and help me get the next release out of the door.

@gma gma closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 21, 2012
  1. added support for different menus

    Ash McKenzie authored
    menu.txt is still the default, but other menus can now be read.
Commits on Aug 27, 2012
  1. Merge branch 'upstream'

    Ash McKenzie authored
Commits on Oct 28, 2012
  1. Merge remote-tracking branch 'upstream/master'

    Ash McKenzie authored
  2. Allow plugins to register routes

    Ash McKenzie authored
This page is out of date. Refresh to see the latest.
View
9 lib/nesta/app.rb
@@ -84,6 +84,12 @@ class App < Sinatra::Base
cache haml(:sitemap, :format => :xhtml, :layout => false)
end
+ Nesta::Plugin.load_local_plugins
+ Nesta::Plugin.initialize_plugins
+
+ # Load the 'catchall' route last which gives plugins a chance to register
+ # routes if need be
+ #
get '*' do
set_common_variables
parts = params[:splat].map { |p| p.sub(/\/$/, '') }
@@ -95,6 +101,3 @@ class App < Sinatra::Base
end
end
end
-
-Nesta::Plugin.load_local_plugins
-Nesta::Plugin.initialize_plugins
View
10 lib/nesta/models.rb
@@ -341,9 +341,9 @@ def valid_paths(paths)
class Menu
INDENT = " " * 2
- def self.full_menu
+ def self.full_menu filename='menu.txt'
menu = []
- menu_file = Nesta::Config.content_path('menu.txt')
+ menu_file = Nesta::Config.content_path(filename)
if File.exist?(menu_file)
File.open(menu_file) { |file| append_menu_item(menu, file, 0) }
end
@@ -354,12 +354,12 @@ def self.top_level
full_menu.reject { |item| item.is_a?(Array) }
end
- def self.for_path(path)
+ def self.for_path(path, filename='menu.txt')
path.sub!(Regexp.new('^/'), '')
if path.empty?
- full_menu
+ full_menu filename
else
- find_menu_item_by_path(full_menu, path)
+ find_menu_item_by_path(full_menu(filename), path)
end
end
View
4 spec/model_factory.rb
@@ -38,8 +38,8 @@ def write_menu_item(indent, file, menu_item)
end
end
- def create_menu(menu_text)
- file = filename(Nesta::Config.content_path, 'menu', :txt)
+ def create_menu(menu_text, filename='menu')
+ file = filename(Nesta::Config.content_path, filename, :txt)
File.open(file, 'w') { |file| file.write(menu_text) }
end
View
16 spec/models_spec.rb
@@ -628,6 +628,12 @@ def create_page(options)
Nesta::Menu.for_path('/').should == [@page]
end
+ it "should find all items in the 'categories' menu" do
+ create_menu(@page.path, 'categories')
+ Nesta::Menu.full_menu('categories.txt').should == [@page]
+ Nesta::Menu.for_path('/', 'categories.txt').should == [@page]
+ end
+
describe "with nested sub menus" do
before(:each) do
(2..6).each do |i|
@@ -657,6 +663,16 @@ def create_page(options)
Nesta::Menu.for_path(@page2.path).should == [@page2, [@page3, @page4]]
end
+ it "should return part of the tree of menu items for categories.txt" do
+ text = <<-EOF
+#{@page2.path}
+ #{@page5.path}
+ #{@page6.path}
+ EOF
+ create_menu(text, 'categories')
+ Nesta::Menu.for_path(@page2.path, 'categories.txt').should == [@page2, [@page5, @page6]]
+ end
+
it "should deem menu for path that isn't in menu to be nil" do
Nesta::Menu.for_path('wibble').should be_nil
end
Something went wrong with that request. Please try again.