Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests for # hidden setting

  • Loading branch information...
commit f69f1a06beeae54d71938d0a81b0f4ac9c8e6753 1 parent aedee44
@andrefs authored
View
9 lib/polvo/menu.rb
@@ -25,11 +25,12 @@ def generate_menu_items(cur_dir, options={})
Dir.foreach("#{rootdir}/#{cur_dir}") do |item|
next if item == 'info.menu' or item =~ /^\./
path = "#{cur_dir}/#{item}"
- items_info[path] = if File.directory? "#{rootdir}/#{path}"
+ cur_item_info = if File.directory? "#{rootdir}/#{path}"
get_dir_info(rootdir,path)
else
get_script_info(rootdir,path)
end
+ items_info[path] = cur_item_info unless cur_item_info.nil?
end
end
return items_info.values.sort {|a,b| [(a[:priority] || 0), a[:title] ] <=> [(b[:priority] || 0), b[:title]] }
@@ -99,6 +100,7 @@ def get_dir_info(rootdir,dir)
return get_script_info rootdir,"#{dir}/exec.bash"
elsif File.exist? "#{rootdir}/#{dir}/info.menu"
info = get_script_info rootdir,"#{dir}/info.menu"
+ return nil if info.nil?
info[:path] = dir
info[:type] = 'dir'
return info
@@ -125,8 +127,11 @@ def get_script_info(rootdir,file)
end
if filestr =~ /^#\spriority:\s*(\d*)\s*$/
priority = $1.to_i || 0
+ end
+ if filestr =~ /^#\shidden:\s*(\d*)\s*$/
+ hidden = $1.to_i || 0
+ return nil if hidden == 1
end
- # hidden
# description
return {
:title => title,
View
1  spec/fixtures/rootdir3/dira/dir_hidden/info.menu
@@ -0,0 +1 @@
+# hidden: 1
View
1  spec/fixtures/rootdir3/dira/script_hidden
@@ -0,0 +1 @@
+# hidden: 1
View
11 spec/polvo/menu_spec.rb
@@ -136,12 +136,21 @@
priority_ordered_items.collect {|i| i[:title]}.should == ['Ruby script', 'Bash script', 'Perl script']
end
+ it "should not show folder if it contains info.menu with 'hidden' setting" do
+ menu = Polvo::Menu.new ["spec/fixtures/rootdir3/"]
+ items = menu.generate_menu_items('dira').collect {|i| i[:path] }.should_not include 'dira/dir_hidden'
+ end
+
+ it "should not show script if it contains 'hidden' setting" do
+ menu = Polvo::Menu.new ["spec/fixtures/rootdir3/"]
+ items = menu.generate_menu_items('dira').collect {|i| i[:path] }.should_not include 'dira/script_hidden'
+ end
+
# Next tests:
#
# it "should show only Ubuntu/all scripts if OS is Ubuntu"
# it "should show only MacOS/all scripts if OS is MacOS"
#
-# it "should not show folder if folder contains info.menu with 'hidden' setting"
# it "should warn when directory is empty"
end
Please sign in to comment.
Something went wrong with that request. Please try again.