Open udon3 opened 9 years ago
I haven't been able to replicate the error yet. Here are a few things you can try:
require 'middleman-navtree'
and activate :navtree
with any settings you want).next_link(data.tree)
. Do these give you errors too? What about helpers provided by other gems, or middleman itself. Any errors with those?Hope you can find what's going on!
It turns out my first mistake was was to activate the extension from within configure :build
.
I do still have problems with tree_to_html(data.tree)
since I moved the activate :middleman-navtree
to outside of the build statement, BUT not the same error* - I tried next_link(data.tree)
as per your suggestion, and that is working.
*FYI: the error message I now get for tree_to_html(data.tree)
is: NoMethodError at / undefined method
data' for nil:NilClass`.
I will try 'Franklin' - it will do me good to see how things are done, as I'm feeling a bit out of my depth! Many thanks
Since I cannot replicate this issue, I'm closing it for now. Please reopen if you can confirm there is an issue and provide steps to replicate it.
bump.
Steps to replicate:
middleman init --template=blog
gem "middleman-navtree"
to gemfilebundle install
./source/2012-01-01-example-article.html.markdown.erb
and add
<ul><%= tree_to_html(data.tree) %></ul>
in there. activate :navtree
in config.rbmiddleman server
http://localhost:4567/
I get the exception
NoMethodError at /
undefined method `data' for nil:NilClass
Ruby /Users/Saro/.rvm/gems/ruby-2.1.5/gems/middleman-navtree-0.1.10/lib/middleman-navtree/helpers.rb: in discover_title, line 131
My gemfile.lock
contents are here.
More info:
If I change the erb to <ul><%= tree_to_html(data) %></ul>
and disable navtree
in the config file, then I am loading up the page correctly. So seems like there is some problem with the tree_to_html
function. Also, as the OP mentioned, next_link(data.tree)
is loading up fine for me too.
Found the issue. The reason was the layout.erb
file was included in the tree.yaml
that was generated. while trying to call discover_title
for layout.erb
, the page object comes as nil
. So, for now, I removed the layout.erb
by ignoring it as options.ignore_files = ['layout.erb']
.
So the question is , should layout files be excluded by default from the tree generation logic?
Thanks for identifying the issue, and I'm glad you found a workaround.
I think it makes sense for middleman-navtree
to ignore layout files, when building tree.yaml
, and looking at the docs, layout files are predictable enough that this change shouldn't be too complicated.
No promises on when I can get around to adding this (given that there's a workaround), but I do think it makes sense (in case anybody wants to start on a PR).
@bryanbraun , is there a reason why you implemented tree generation using the scan_directory
?
The Resource
object, as specified in here has the parent
, children
and siblings
accessors, using which, IMO, we can create a tree for the current resource easily with a helper alone. In this case , there is no need to have a tree.yml
.
I actually created this gem because I wasn't able to build the navigation I wanted using the sitemap
traversal methods. The main obstacle was that the traversal methods depended on there being an index.html
file in each directory, to represent each level—for example, any given parent
would be the index.html
file in the directory above. That's fine for many sites, but I was working with online books where the home-page-per-directory paradigm wasn't working very well.
You can see some background conversation about it here: https://forum.middlemanapp.com/t/generating-navigation-tree-and-including-in-layout/597
I had this same issue. @saravanak's fix worked for me.
Thanks for this great gem!
For anybody else who comes across this issue, if your layout.erb
file is kept in the middleman's configured layouts
folder, then this shouldn't be an issue since we exclude that directory from the nav-tree by default.
The default middleman init
project template is structured with layout.erb
inside a layouts
folder, so to have it outside is probably more uncommon than not.
I'm struggling to figure out what's causing this error when I run build - NoMethodError at / undefined method `tree_to_html'
I'm using Middleman with Haml, and admit to being fairly new to ruby, rubygems as well as Haml...
The tree.yml file has been built, suggesting the gem is installed properly.
I'm testing the treenav in my master layout file, which is in Haml, but I don't see how this would make a difference:
%ul = tree_to_html(data.tree)
I'm running ruby 2.0 on Windows. Any pointers would be much appreciated!