Skip to content
Open
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
50 changes: 50 additions & 0 deletions lib/appscrolls/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ def new(name)
end
end

desc "history", "view history of past scroll choices"
method_option :save, :desc => "Save a past choice of scrolls to a new scroll."
method_option :use, :desc => "Directly use a past choice of scrolls to generate a new app."
def history
lines = File.readlines history_file
lines.each_with_index do |line, i|
puts "#{i}: #{line}"
end
if options[:save]
print "Enter line number and name to save to a new scroll (e.g. 1 my_defaults): "
index, name = STDIN.gets.strip.split(' ')
create_new_scroll(:scrolls => lines[index.to_i].chomp.split(' '), :name => name)
elsif options[:use]
print "Enter line number and name to create a new scroll from past selection (e.g. 1 new_app_name): "
index, name = STDIN.gets.strip.split(' ')
run_template(name, lines[index.to_i].chomp.split(' '))
end
end

desc "list [CATEGORY]", "list available scrolls (optionally by category)"
def list(category = nil)
if category
Expand Down Expand Up @@ -85,9 +104,40 @@ def run_template(name, scrolls, display_only = false)
else
system "rails new #{name} -m #{file.path} #{template.args.join(' ')}"
end
write_history scrolls
ensure
file.unlink
end

def scrolls_dir
File.join ENV['HOME'], '.scrolls'
end

def ensure_scrolls_dir
Dir.mkdir scrolls_dir unless Dir.exists? scrolls_dir
end

def history_file
ensure_scrolls_dir
File.join scrolls_dir, 'history'
end

def write_history(scrolls)
File.open(history_file, "a") do |file|
file.puts scrolls.join(' ')
end
end

def create_new_scroll(hash)
require 'active_support/inflector'
require 'erb'
require 'appscrolls/template'
name = hash[:name]
requires = hash[:scrolls]
scroll = AppScrollsScrolls::Template.render("saved_scrolls", binding)
scroll_path = "scrolls/#{name}.rb"
File.open(scroll_path, "w") { |file| file << scroll }
end
end
end
end
19 changes: 19 additions & 0 deletions templates/saved_scrolls.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

__END__

name: <%= name.humanize.capitalize %>
description:
website:
author: <%= `whoami`.strip %>

requires: [<%= requires.join(', ') %>]
run_after: []
run_before: []

category: other # authentication, testing, persistence, javascript, css, services, deployment, and templating
# exclusive:

# config:
# - foo:
# type: boolean
# prompt: "Is foo true?"