Skip to content

Commit

Permalink
Tidy up creation of new vanilla sites given multi-soups.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyatom committed Jul 14, 2010
1 parent e42d470 commit af0ec96
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -24,7 +24,7 @@ if Object.const_defined?(:Gem)

# Change these as appropriate
s.name = "vanilla"
s.version = "1.11.1"
s.version = "1.11.2"
s.summary = "A bliki-type web content thing."
s.author = "James Adam"
s.email = "james@lazyatom.com.com"
Expand Down
7 changes: 5 additions & 2 deletions config.example.yml
@@ -1,3 +1,6 @@
---
:soup: soup
:secret: a6bc097eff86cabd92ee72ba4687c3f057b7556deaa3e4a6b284460871056b87ba3e91548c37dcc44fbc10241cee5b386556e6bcc2946fd9b609dc3bc1b24488
:soups:
- soup
- soup/dynasnips
- soup/system
- soup/system/dynasnips
115 changes: 39 additions & 76 deletions lib/tasks/vanilla.rake
Expand Up @@ -7,61 +7,11 @@ namespace :vanilla do
sh "irb -Ilib -rubygems -rvanilla -rvanilla/console"
end

task :clean do
# TODO: get the database name from Soup
FileUtils.rm "soup.db" if File.exist?("soup.db")
end

task :load_snips do
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
print "Preparing soup... "
Dynasnip.all.each { |ds| app.soup << ds.snip_attributes }
Dir[File.join(File.dirname(__FILE__), '..', 'vanilla', 'snips', '*.rb')].each do |f|
load f
end
puts "the soup is simmering."
end

desc 'Resets the soup to contain the base snips only. Dangerous!'
task :reset => [:clean, :load_snips]

namespace :upgrade do
desc 'Upgrade the dynasnips'
task :dynasnips do
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
Dynasnip.all.each do |dynasnip|
print "Upgrading #{dynasnip.snip_name}... "
# TODO: our confused Soup interface might return an array.
snip = app.soup[dynasnip.snip_name]
if snip.empty? || snip.nil?
# it's a new dyna
app.soup << dynasnip.snip_attributes
puts "(new)"
elsif snip.created_at == snip.updated_at
# it's not been changed, let's upgrade
snip.destroy
app.soup << dynasnip.snip_attributes
puts "(unedited)"
else
# the dyna exists and has been changed
dynasnip.snip_attributes.each do |name, value|
unless (existing_value = snip.get_value(name)) == value
puts "Conflict in attribute '#{name}':"
puts "> Your soup: '#{existing_value}'"
puts "> New soup: '#{value}"
print "Upgrade? [Y/n]: "
upgrade_value = ["Y", "y", ""].include? STDIN.gets.chomp.strip
snip.set_value(name, value) if upgrade_value
end
end
snip.save
end
end
end
end

desc 'Upgrade dynasnips and system snips'
task :upgrade => ["upgrade:dynasnips"]
task :upgrade do
# TODO
puts "TODO, but should be easier thanks to multi-space soup."
end

desc 'Add a user (or change an existing password)'
task :add_user => :prepare do
Expand Down Expand Up @@ -107,37 +57,18 @@ namespace :vanilla do
puts "done; cookies are twice baked. BIS-CUIT!"
end

desc 'Prepare standard files to run Vanilla'
task :prepare_files do
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. config.ru])), 'config.ru'
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. config.example.yml])), 'config.yml'
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. README_FOR_APP])), 'README'
cp_r File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. public])), 'public'
mkdir 'tmp'
File.open("Rakefile", "w") do |f|
rakefile =<<-EOF
require 'vanilla'
load 'tasks/vanilla.rake'
# Add any other tasks here.
EOF
f.write rakefile.strip
end
end


desc 'Prepare a new vanilla.rb installation'
task :setup do
puts <<-EOM
____________________.c( Vanilla.rb )o._____________________
Congratulations! You have elected to try out the weirdest web
Congratulations! You have elected to try out the weirdest web
thing ever. Lets get started.
EOM
Rake::Task['vanilla:prepare_files'].invoke
Rake::Task['vanilla:setup:prepare_files'].invoke
Rake::Task['vanilla:generate_secret'].invoke
Rake::Task['vanilla:load_snips'].invoke
Rake::Task['vanilla:setup:load_snips'].invoke

puts <<-EOM
Expand All @@ -146,4 +77,36 @@ ___________________.c( You Are Ready )o.___________________
#{File.readlines('README')[0,16].join}
EOM
end

namespace :setup do
desc 'Prepare standard files to run Vanilla'
task :prepare_files do
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. config.ru])), 'config.ru'
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. config.example.yml])), 'config.yml'
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. README_FOR_APP])), 'README'
cp_r File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. public])), 'public'
mkdir 'tmp'
File.open("Rakefile", "w") do |f|
rakefile =<<-EOF
require 'vanilla'
load 'tasks/vanilla.rake'
# Add any other tasks here.
EOF
f.write rakefile.strip
end
end

task :load_snips do
print "Preparing soup... "
system_soup = ::Soup.new(::Soup::Backends::YAMLBackend.new("soup/system"))
system_soup << eval(File.read(File.join(File.dirname(__FILE__), '..', 'vanilla', 'snips', 'system.rb')))
dynasnip_soup = ::Soup.new(::Soup::Backends::YAMLBackend.new("soup/system/dynasnips"))
Dynasnip.all.each { |ds| dynasnip_soup << ds.snip_attributes }
Dir[File.join(File.dirname(__FILE__), '..', 'vanilla', 'snips', '{start,tutorial}.rb')].each do |f|
load f
end
puts "the soup is simmering."
end
end
end
2 changes: 1 addition & 1 deletion lib/vanilla/app.rb
Expand Up @@ -86,7 +86,7 @@ def render_missing_snip(snip_name)
end

def snip(attributes)
@soup.new_snip(attributes)
@soup << attributes
end

private
Expand Down
26 changes: 9 additions & 17 deletions lib/vanilla/snips/system.rb
@@ -1,8 +1,6 @@
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
system = app.snip(:name => "system")
system.content = "You're in the system snip now. You probably want to {edit_link system,edit} it though."

system.main_template = <<-HTML
{:name => "system",
:content => "You're in the system snip now. You probably want to {edit_link system,edit} it though.",
:main_template => %^
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
Expand All @@ -24,10 +22,8 @@
{current_snip}
</div>
</body>
</html>
HTML

system.login_template = <<-HTML
</html>^,
:login_template => %^
<html>
<head><link rel="stylesheet" type="text/css" media="screen" href="/system/css.css" /></head>
<body id="login">
Expand All @@ -38,10 +34,8 @@
<button>login</button>
</form>
</body>
</html>
HTML

system.css = <<-CSS
</html>^,
:css => %^
body {
font-family: Helvetica;
background-color: #666;
Expand Down Expand Up @@ -86,7 +80,5 @@
a.new:hover {
text-decoration: underline;
}
CSS

system.save
}^
}
2 changes: 1 addition & 1 deletion vanilla.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{vanilla}
s.version = "1.11.1"
s.version = "1.11.2"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Adam"]
Expand Down

0 comments on commit af0ec96

Please sign in to comment.