Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Scrolls entered twice are now removed rather than duplicated

  • Loading branch information...
commit 36737fae669030bc4b13864410e585b883949073 1 parent 9288ead
@rupert654 rupert654 authored Thom Mahoney committed
Showing with 19 additions and 13 deletions.
  1. +19 −13 lib/appscrolls/command.rb
View
32 lib/appscrolls/command.rb
@@ -13,10 +13,12 @@ def new(name)
else
@scrolls = []
- while scroll = ask("#{print_scrolls}#{bold}Which scroll would you like to add? #{clear}#{yellow}(blank to finish)#{clear}")
- if scroll == ''
- run_template(name, @scrolls)
- break
+ question = "#{bold}Which scroll would you like to add/remove? #{clear}#{yellow}(blank to finish)#{clear}"
+ while (scroll = ask(scrolls_message + question)) != ''
+ if @scrolls.include?(scroll)
+ @scrolls.delete(scroll)
+ puts
+ puts "> #{yellow}Removed '#{scroll}' from template.#{clear}"
elsif AppScrollsScrolls::Scrolls.list.include?(scroll)
@scrolls << scroll
puts
@@ -26,6 +28,8 @@ def new(name)
puts "> #{red}Invalid scroll, please try again.#{clear}"
end
end
+
+ run_template(name, @scrolls)
end
end
@@ -50,16 +54,18 @@ def red; "\033[31m" end
def green; "\033[32m" end
def yellow; "\033[33m" end
- def print_scrolls
- puts
- puts
- puts
+ def scrolls_message
+ message = "\n\n\n"
if @scrolls && @scrolls.any?
- puts "#{green}#{bold}Your Scrolls:#{clear} " + @scrolls.join(", ")
- puts
+ message << "#{green}#{bold}Your Scrolls:#{clear} #{@scrolls.join(", ")}"
+ message << "\n\n"
end
- puts "#{bold}#{cyan}Available Scrolls:#{clear} " + AppScrollsScrolls::Scrolls.list.join(', ')
- puts
+ available_scrolls = AppScrollsScrolls::Scrolls.list - @scrolls
+ if available_scrolls.any?
+ message << "#{bold}#{cyan}Available Scrolls:#{clear} #{available_scrolls.join(', ')}"
+ message << "\n\n"
+ end
+ message
end
def run_template(name, scrolls, display_only = false)
@@ -67,7 +73,7 @@ def run_template(name, scrolls, display_only = false)
puts
puts "#{bold}Generating and Running Template...#{clear}"
puts
- file = Tempfile.new('template')
+ file = Tempfile.new('template')
template = AppScrollsScrolls::Template.new(scrolls)
puts "Using the following scrolls:"
Please sign in to comment.
Something went wrong with that request. Please try again.