Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
288 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pkg | |
*~ | ||
tmp | ||
config.yml | ||
rdoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,118 @@ | ||
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib') | ||
require 'vanilla' | ||
|
||
desc "Open an irb session preloaded with this library" | ||
task :console do | ||
sh "irb -Ilib -rvanilla/console" | ||
end | ||
|
||
task :clean do | ||
# TODO: get the database name from Soup | ||
FileUtils.rm "soup.db" if File.exist?("soup.db") | ||
end | ||
|
||
task :prepare do | ||
Soup.prepare | ||
end | ||
|
||
task :bootstrap => :prepare do | ||
Dynasnip.persist_all!(overwrite=true) | ||
|
||
Dir[File.join(File.dirname(__FILE__), 'lib', 'vanilla', 'snips', '*.rb')].each do |f| | ||
p "loading #{f}" | ||
load f | ||
end | ||
|
||
load File.join(File.dirname(__FILE__), *%w[lib vanilla test_snips.rb]) | ||
|
||
puts "The soup is simmering. Loaded #{Soup.tuple_class.count} tuples" | ||
end | ||
|
||
desc 'Resets the soup to contain the base snips only. Dangerous!' | ||
task :reset => [:clean, :bootstrap] | ||
|
||
namespace :upgrade do | ||
desc 'Upgrade the dynasnips' | ||
task :dynasnips => :prepare do | ||
Dynasnip.all.each do |dynasnip| | ||
print "Upgrading #{dynasnip.snip_name}... " | ||
# TODO: our confused Soup interface might return an array. | ||
snip = Soup[dynasnip.snip_name] | ||
if snip.empty? || snip.nil? | ||
# it's a new dyna | ||
Soup << dynasnip.snip_attributes | ||
puts "(new)" | ||
elsif snip.created_at == snip.updated_at | ||
# it's not been changed, let's upgrade | ||
snip.destroy | ||
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"] | ||
|
||
desc 'Add a user (or change an existing password)' | ||
task :add_user => :prepare do | ||
puts "Adding a new user" | ||
# config_file = ENV['VANILLA_CONFIG'] || 'config.yml' | ||
# config_file = YAML.load(File.open(config_file)) rescue {} | ||
app = Vanilla::App.new(ENV['VANILLA_CONFIG']) | ||
print "Username: " | ||
username = STDIN.gets.chomp.strip | ||
print "Password: " | ||
password = STDIN.gets.chomp.strip | ||
print "Confirm password: " | ||
confirm_password = STDIN.gets.chomp.strip | ||
if password != confirm_password | ||
raise "Passwords don't match!" | ||
else | ||
app.config[:credentials] ||= {} | ||
app.config[:credentials][username] = MD5.md5(password).to_s | ||
app.config.save! | ||
puts "User '#{username}' added." | ||
end | ||
end | ||
|
||
desc 'Generate file containing secret for cookie-based session storage' | ||
task :generate_secret do | ||
# Adapted from old rails secret generator. | ||
require 'openssl' | ||
if !File.exist?("/dev/urandom") | ||
# OpenSSL transparently seeds the random number generator with | ||
# data from /dev/urandom. On platforms where that is not | ||
# available, such as Windows, we have to provide OpenSSL with | ||
# our own seed. Unfortunately there's no way to provide a | ||
# secure seed without OS support, so we'll have to do with | ||
# rand() and Time.now.usec(). | ||
OpenSSL::Random.seed(rand(0).to_s + Time.now.usec.to_s) | ||
end | ||
data = OpenSSL::BN.rand(2048, -1, false).to_s | ||
secret = OpenSSL::Digest::SHA512.new(data).hexdigest | ||
app = Vanilla::App.new(ENV['VANILLA_CONFIG']) | ||
app.config[:secret] = secret | ||
app.config.save! | ||
puts "Secret generated." | ||
require 'spec' | ||
require 'spec/rake/spectask' | ||
Spec::Rake::SpecTask.new do |t| | ||
t.spec_opts = %w(--format specdoc --colour) | ||
t.libs = ["spec"] | ||
end | ||
|
||
task :default => :spec | ||
|
||
desc 'Prepare a new vanilla.rb installation' | ||
task :setup do | ||
puts <<-EOM | ||
===================~ Vanilla.rb ~==================== | ||
Congratulations! You have elected to try out the weirdest web thing ever. | ||
Lets get started. Firstly, I'm going to cook you some soup: | ||
|
||
require "rubygems" | ||
require "rake/gempackagetask" | ||
require "rake/rdoctask" | ||
|
||
EOM | ||
Rake::Task[:bootstrap].invoke | ||
# This builds the actual gem. For details of what all these options | ||
# mean, and other ones you can add, check the documentation here: | ||
# | ||
# http://rubygems.org/read/chapter/20 | ||
# | ||
spec = Gem::Specification.new do |s| | ||
|
||
puts <<-EOM | ||
# Change these as appropriate | ||
s.name = "vanilla" | ||
s.version = "1.0.0" | ||
s.summary = "A bliki-type web content thing." | ||
s.author = "James Adam" | ||
s.email = "james@lazyatom.com.com" | ||
s.homepage = "http://github.com/lazyatom/vanilla-rb" | ||
|
||
s.has_rdoc = true | ||
s.extra_rdoc_files = %w(README) | ||
s.rdoc_options = %w(--main README) | ||
|
||
# Add any extra files to include in the gem | ||
s.files = %w(config.example.yml config.ru Rakefile README) + Dir.glob("{spec,lib,bin}/**/*") | ||
s.executables = ['vanilla'] | ||
s.require_paths = ["lib"] | ||
|
||
Now I'm going to generate your configuration. This will be stored either in | ||
'config.yml' in the current directory, or in the path you provide via the | ||
environment variable VANILLA_CONFIG. | ||
Generating the secret for cookie-based session storage. | ||
EOM | ||
Rake::Task[:generate_secret_file].invoke | ||
# If you want to depend on other gems, add them here, along with any | ||
# relevant versions | ||
# s.add_dependency("some_other_gem", "~> 0.1.0") | ||
|
||
puts <<-EOM | ||
Now that we've got our broth, you'll want to add a user, so you can edit stuff. | ||
Lets do that now: | ||
EOM | ||
Rake::Task[:add_user].invoke | ||
puts <<-EOM | ||
s.add_development_dependency("rspec") # add any other gems for testing/development | ||
|
||
# If you want to publish automatically to rubyforge, you'll may need | ||
# to tweak this, and the publishing task below too. | ||
s.rubyforge_project = "vanilla" | ||
end | ||
|
||
OK! You're ready to go. To start vanilla.rb, you'll want to get it running under | ||
a webserver that supports Rack. The easiest way to do this locally is via 'rackup': | ||
$ rackup | ||
# This task actually builds the gem. We also regenerate a static | ||
# .gemspec file, which is useful if something (i.e. GitHub) will | ||
# be automatically building a gem for this project. If you're not | ||
# using GitHub, edit as appropriate. | ||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.gem_spec = spec | ||
|
||
Then go to http://localhost:9292 | ||
I'm going now, Goodbye! | ||
# Generate the gemspec file for github. | ||
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec" | ||
File.open(file, "w") {|f| f << spec.to_ruby } | ||
end | ||
|
||
EOM | ||
# Generate documentation | ||
Rake::RDocTask.new do |rd| | ||
rd.main = "README" | ||
rd.rdoc_files.include("README", "lib/**/*.rb") | ||
rd.rdoc_dir = "rdoc" | ||
end | ||
|
||
require 'spec' | ||
require 'spec/rake/spectask' | ||
Spec::Rake::SpecTask.new do |t| | ||
t.spec_opts = %w(--format specdoc --colour) | ||
t.libs = ["spec"] | ||
desc 'Clear out RDoc and generated packages' | ||
task :clean => [:clobber_rdoc, :clobber_package] do | ||
rm "#{spec.name}.gemspec" | ||
end | ||
|
||
task :default => :spec | ||
# If you want to publish to RubyForge automatically, here's a simple | ||
# task to help do that. If you don't, just get rid of this. | ||
# Be sure to set up your Rubyforge account details with the Rubyforge | ||
# gem; you'll need to run `rubyforge setup` and `rubyforge config` at | ||
# the very least. | ||
begin | ||
require "rake/contrib/sshpublisher" | ||
namespace :rubyforge do | ||
|
||
desc "Release gem and RDoc documentation to RubyForge" | ||
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"] | ||
|
||
namespace :release do | ||
desc "Release a new version of this gem" | ||
task :gem => [:package] do | ||
require 'rubyforge' | ||
rubyforge = RubyForge.new | ||
rubyforge.configure | ||
rubyforge.login | ||
rubyforge.userconfig['release_notes'] = spec.summary | ||
path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem") | ||
puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..." | ||
rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem) | ||
end | ||
|
||
desc "Publish RDoc to RubyForge." | ||
task :docs => [:rdoc] do | ||
config = YAML.load( | ||
File.read(File.expand_path('~/.rubyforge/user-config.yml')) | ||
) | ||
|
||
host = "#{config['username']}@rubyforge.org" | ||
remote_dir = "/var/www/gforge-projects/vanilla-rb/" # Should be the same as the rubyforge project name | ||
local_dir = 'rdoc' | ||
|
||
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload | ||
end | ||
end | ||
end | ||
rescue LoadError | ||
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured." | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
require 'rubygems' | ||
require 'rake' | ||
load File.join(File.dirname(__FILE__), *%w[.. lib tasks vanilla.rake]) | ||
|
||
mkdir(ARGV[0]) | ||
cd(ARGV[0]) | ||
|
||
Rake::Task['vanilla:setup'].invoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib') | ||
require 'vanilla' | ||
|
||
app = Vanilla::App.new(ENV['VANILLA_CONFIG']) | ||
use Rack::Session::Cookie, :key => 'vanilla.session', | ||
:path => '/', | ||
:expire_after => 2592000, | ||
:secret => app.config[:secret] | ||
:secret => app.config[:secret] | ||
use Rack::Static, :urls => ["/public"], :root => File.join(File.dirname(__FILE__)) | ||
run app |
Oops, something went wrong.