vanilla 1.2 → 1.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +61 -60
- data/bin/vanilla +6 -35
- data/config.example.yml +6 -0
- data/config.ru +10 -0
- data/lib/defensio.rb +59 -0
- data/lib/tasks/vanilla.rake +173 -0
- data/lib/vanilla.rb +3 -10
- data/lib/vanilla/app.rb +48 -104
- data/lib/vanilla/console.rb +5 -19
- data/lib/vanilla/dynasnips/comments.rb +108 -0
- data/lib/vanilla/dynasnips/current_snip.rb +32 -0
- data/{pristine_app/soups → lib/vanilla}/dynasnips/debug.rb +3 -5
- data/lib/vanilla/dynasnips/edit.rb +60 -0
- data/lib/vanilla/dynasnips/edit_link.rb +20 -0
- data/{pristine_app/soups → lib/vanilla}/dynasnips/index.rb +2 -4
- data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/kind.rb +12 -14
- data/{pristine_app/soups → lib/vanilla}/dynasnips/link_to.rb +0 -2
- data/lib/vanilla/dynasnips/link_to_current_snip.rb +16 -0
- data/lib/vanilla/dynasnips/login.rb +56 -0
- data/lib/vanilla/dynasnips/new.rb +14 -0
- data/lib/vanilla/dynasnips/notes.rb +42 -0
- data/{pristine_app/soups → lib/vanilla}/dynasnips/pre.rb +4 -6
- data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/rand.rb +0 -2
- data/{pristine_app/soups → lib/vanilla}/dynasnips/raw.rb +5 -8
- data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/url_to.rb +0 -0
- data/lib/vanilla/renderers/base.rb +22 -32
- data/lib/vanilla/renderers/bold.rb +2 -0
- data/lib/vanilla/renderers/erb.rb +2 -0
- data/lib/vanilla/renderers/markdown.rb +2 -0
- data/lib/vanilla/renderers/raw.rb +2 -0
- data/lib/vanilla/renderers/ruby.rb +5 -9
- data/lib/vanilla/renderers/textile.rb +2 -0
- data/lib/vanilla/request.rb +15 -16
- data/lib/vanilla/routes.rb +18 -5
- data/lib/vanilla/snip_reference.rb +534 -0
- data/lib/vanilla/snip_reference.treetop +48 -0
- data/lib/vanilla/snip_reference_parser.rb +99 -82
- data/lib/vanilla/snips/start.rb +28 -0
- data/lib/vanilla/snips/system.rb +77 -0
- data/lib/vanilla/snips/tutorial.rb +244 -0
- data/lib/vanilla/soup_with_timestamps.rb +21 -0
- data/public/hatch.png +0 -0
- data/public/javascripts/jquery.autogrow-textarea.js +54 -0
- data/public/javascripts/jquery.js +4376 -0
- data/public/javascripts/vanilla.js +22 -0
- data/spec/dynasnip_spec.rb +28 -0
- data/spec/renderers/base_renderer_spec.rb +40 -0
- data/spec/renderers/erb_renderer_spec.rb +27 -0
- data/spec/renderers/markdown_renderer_spec.rb +29 -0
- data/spec/renderers/raw_renderer_spec.rb +21 -0
- data/spec/renderers/ruby_renderer_spec.rb +59 -0
- data/spec/renderers/vanilla_app_detecting_renderer_spec.rb +35 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/tmp/config.yml +2 -0
- data/spec/tmp/soup/current_snip.yml +15 -0
- data/spec/tmp/soup/system.yml +5 -0
- data/spec/vanilla_app_spec.rb +38 -0
- data/spec/vanilla_presenting_spec.rb +84 -0
- data/spec/vanilla_request_spec.rb +73 -0
- metadata +79 -170
- data/lib/vanilla/renderers.rb +0 -12
- data/lib/vanilla/renderers/haml.rb +0 -13
- data/lib/vanilla/static.rb +0 -28
- data/pristine_app/Gemfile +0 -3
- data/pristine_app/Gemfile.lock +0 -32
- data/pristine_app/README +0 -47
- data/pristine_app/config.ru +0 -26
- data/pristine_app/public/vanilla.css +0 -15
- data/pristine_app/soups/base/layout.snip +0 -18
- data/pristine_app/soups/base/start.snip +0 -19
- data/pristine_app/soups/dynasnips/current_snip.rb +0 -29
- data/pristine_app/soups/dynasnips/link_to_current_snip.rb +0 -14
- data/pristine_app/soups/dynasnips/page_title.rb +0 -9
- data/pristine_app/soups/extras/comments.rb +0 -78
- data/pristine_app/soups/tutorial/bad_dynasnip.snip +0 -8
- data/pristine_app/soups/tutorial/hello_world.snip +0 -20
- data/pristine_app/soups/tutorial/markdown_example.snip +0 -13
- data/pristine_app/soups/tutorial/snip.snip +0 -9
- data/pristine_app/soups/tutorial/soup.snip +0 -3
- data/pristine_app/soups/tutorial/test.snip +0 -30
- data/pristine_app/soups/tutorial/textile_example.snip +0 -11
- data/pristine_app/soups/tutorial/tutorial-another-snip.snip +0 -1
- data/pristine_app/soups/tutorial/tutorial-basic-snip-inclusion.snip +0 -1
- data/pristine_app/soups/tutorial/tutorial-dynasnips.snip.markdown +0 -56
- data/pristine_app/soups/tutorial/tutorial-layout.snip +0 -56
- data/pristine_app/soups/tutorial/tutorial-links.snip +0 -4
- data/pristine_app/soups/tutorial/tutorial-renderers.snip.markdown +0 -77
- data/pristine_app/soups/tutorial/tutorial.snip.markdown +0 -69
- data/pristine_app/soups/tutorial/vanilla-rb.snip +0 -16
- data/pristine_app/soups/tutorial/vanilla.snip +0 -8
- data/test/dynasnip_test.rb +0 -42
- data/test/dynasnips/link_to_current_snip_test.rb +0 -19
- data/test/dynasnips/link_to_test.rb +0 -27
- data/test/dynasnips/page_title_test.rb +0 -19
- data/test/renderers/base_renderer_test.rb +0 -43
- data/test/renderers/erb_renderer_test.rb +0 -29
- data/test/renderers/haml_renderer_test.rb +0 -35
- data/test/renderers/markdown_renderer_test.rb +0 -31
- data/test/renderers/raw_renderer_test.rb +0 -23
- data/test/renderers/ruby_renderer_test.rb +0 -59
- data/test/snip_inclusion_test.rb +0 -56
- data/test/snip_reference_parser_test.rb +0 -123
- data/test/test_helper.rb +0 -75
- data/test/vanilla_app_test.rb +0 -83
- data/test/vanilla_presenting_test.rb +0 -125
- data/test/vanilla_request_test.rb +0 -87
data/Rakefile
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
|
|
2
|
+
require 'vanilla'
|
|
3
|
+
load File.join(File.dirname(__FILE__), *%w[lib tasks vanilla.rake])
|
|
4
|
+
|
|
5
|
+
require 'spec'
|
|
6
|
+
require 'spec/rake/spectask'
|
|
7
|
+
Spec::Rake::SpecTask.new do |t|
|
|
8
|
+
t.spec_opts = %w(--format specdoc --colour)
|
|
9
|
+
t.libs = ["spec"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task :default => :spec
|
|
13
|
+
|
|
1
14
|
require "rubygems"
|
|
2
15
|
require "rake/gempackagetask"
|
|
3
16
|
require "rake/rdoctask"
|
|
4
17
|
|
|
5
|
-
require "bundler/setup"
|
|
6
|
-
require "vanilla"
|
|
7
|
-
|
|
8
|
-
task :default => :test
|
|
9
|
-
|
|
10
|
-
require "rake/testtask"
|
|
11
|
-
Rake::TestTask.new do |t|
|
|
12
|
-
t.libs << "test"
|
|
13
|
-
t.ruby_opts << "-rubygems"
|
|
14
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
|
15
|
-
t.verbose = true
|
|
16
|
-
end
|
|
17
|
-
|
|
18
18
|
if Object.const_defined?(:Gem)
|
|
19
19
|
# This builds the actual gem. For details of what all these options
|
|
20
20
|
# mean, and other ones you can add, check the documentation here:
|
|
@@ -25,7 +25,7 @@ if Object.const_defined?(:Gem)
|
|
|
25
25
|
|
|
26
26
|
# Change these as appropriate
|
|
27
27
|
s.name = "vanilla"
|
|
28
|
-
s.version =
|
|
28
|
+
s.version = "1.9.9"
|
|
29
29
|
s.summary = "A bliki-type web content thing."
|
|
30
30
|
s.author = "James Adam"
|
|
31
31
|
s.email = "james@lazyatom.com.com"
|
|
@@ -36,58 +36,37 @@ if Object.const_defined?(:Gem)
|
|
|
36
36
|
s.rdoc_options = %w(--main README)
|
|
37
37
|
|
|
38
38
|
# Add any extra files to include in the gem
|
|
39
|
-
s.files = %w(Rakefile README) + Dir.glob("{
|
|
39
|
+
s.files = %w(config.example.yml config.ru Rakefile README) + Dir.glob("{spec,lib,bin,public}/**/*")
|
|
40
40
|
s.executables = ['vanilla']
|
|
41
41
|
s.require_paths = ["lib"]
|
|
42
42
|
|
|
43
43
|
# All the other gems we need.
|
|
44
44
|
s.add_dependency("rack", ">= 0.9.1")
|
|
45
|
-
s.add_dependency("soup", ">=
|
|
45
|
+
s.add_dependency("soup", ">= 0.9.9")
|
|
46
46
|
s.add_dependency("ratom", ">= 0.3.5")
|
|
47
47
|
s.add_dependency("RedCloth", ">= 4.1.1")
|
|
48
48
|
s.add_dependency("BlueCloth", ">= 1.0.0")
|
|
49
|
-
s.add_dependency("
|
|
50
|
-
s.add_dependency("parslet", ">= 1.2.0")
|
|
49
|
+
s.add_dependency("treetop", ">= 1.4.1")
|
|
51
50
|
|
|
52
|
-
s.add_development_dependency("
|
|
53
|
-
s.add_development_dependency("mocha")
|
|
51
|
+
s.add_development_dependency("rspec") # add any other gems for testing/development
|
|
54
52
|
|
|
55
53
|
# If you want to publish automatically to rubyforge, you'll may need
|
|
56
54
|
# to tweak this, and the publishing task below too.
|
|
57
55
|
s.rubyforge_project = "vanilla"
|
|
58
56
|
end
|
|
59
57
|
|
|
60
|
-
# This task actually builds the gem. We also regenerate a static
|
|
58
|
+
# This task actually builds the gem. We also regenerate a static
|
|
61
59
|
# .gemspec file, which is useful if something (i.e. GitHub) will
|
|
62
60
|
# be automatically building a gem for this project. If you're not
|
|
63
61
|
# using GitHub, edit as appropriate.
|
|
64
|
-
#
|
|
65
|
-
# To publish your gem online, install the 'gemcutter' gem; Read more
|
|
66
|
-
# about that here: http://gemcutter.org/pages/gem_docs
|
|
67
62
|
Rake::GemPackageTask.new(spec) do |pkg|
|
|
68
63
|
pkg.gem_spec = spec
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Stolen from jeweler
|
|
72
|
-
def prettyify_array(gemspec_ruby, array_name)
|
|
73
|
-
gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
|
|
74
|
-
leadin, files = match[0..-2].split("[")
|
|
75
|
-
leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
64
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
output = prettyify_array(output, :test_files)
|
|
83
|
-
output = prettyify_array(output, :extra_rdoc_files)
|
|
84
|
-
|
|
85
|
-
file = File.expand_path("../#{spec.name}.gemspec", __FILE__)
|
|
86
|
-
File.open(file, "w") {|f| f << output }
|
|
65
|
+
# Generate the gemspec file for github.
|
|
66
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
|
67
|
+
File.open(file, "w") {|f| f << spec.to_ruby }
|
|
87
68
|
end
|
|
88
69
|
|
|
89
|
-
task :package => :gemspec
|
|
90
|
-
|
|
91
70
|
# Generate documentation
|
|
92
71
|
Rake::RDocTask.new do |rd|
|
|
93
72
|
rd.main = "README"
|
|
@@ -100,25 +79,47 @@ if Object.const_defined?(:Gem)
|
|
|
100
79
|
rm "#{spec.name}.gemspec"
|
|
101
80
|
end
|
|
102
81
|
|
|
103
|
-
|
|
104
|
-
task
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
82
|
+
# If you want to publish to RubyForge automatically, here's a simple
|
|
83
|
+
# task to help do that. If you don't, just get rid of this.
|
|
84
|
+
# Be sure to set up your Rubyforge account details with the Rubyforge
|
|
85
|
+
# gem; you'll need to run `rubyforge setup` and `rubyforge config` at
|
|
86
|
+
# the very least.
|
|
87
|
+
begin
|
|
88
|
+
require "rake/contrib/sshpublisher"
|
|
89
|
+
namespace :rubyforge do
|
|
90
|
+
|
|
91
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
|
92
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
|
93
|
+
|
|
94
|
+
namespace :release do
|
|
95
|
+
desc "Release a new version of this gem"
|
|
96
|
+
task :gem => [:package] do
|
|
97
|
+
require 'rubyforge'
|
|
98
|
+
rubyforge = RubyForge.new
|
|
99
|
+
rubyforge.configure
|
|
100
|
+
rubyforge.login
|
|
101
|
+
rubyforge.userconfig['release_notes'] = spec.summary
|
|
102
|
+
path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem")
|
|
103
|
+
puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..."
|
|
104
|
+
rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
desc "Publish RDoc to RubyForge."
|
|
108
|
+
task :docs => [:rdoc] do
|
|
109
|
+
config = YAML.load(
|
|
110
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
host = "#{config['username']}@rubyforge.org"
|
|
114
|
+
remote_dir = "/var/www/gforge-projects/vanilla-rb/" # Should be the same as the rubyforge project name
|
|
115
|
+
local_dir = 'rdoc'
|
|
116
|
+
|
|
117
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
|
118
|
+
end
|
|
108
119
|
end
|
|
109
|
-
`git add #{File.expand_path("../#{spec.name}.gemspec", __FILE__)}`
|
|
110
|
-
`git commit -m "Released version #{spec.version}"`
|
|
111
|
-
`git tag v#{spec.version}`
|
|
112
|
-
`git push --tags`
|
|
113
|
-
`git push`
|
|
114
|
-
else
|
|
115
|
-
raise "Unstaged changes still waiting to be committed"
|
|
116
120
|
end
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
desc "Tag and publish the gem to rubygems.org"
|
|
120
|
-
task :publish => :tag do
|
|
121
|
-
`gem push pkg/#{spec.name}-#{spec.version}.gem`
|
|
121
|
+
rescue LoadError
|
|
122
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
|
122
123
|
end
|
|
123
124
|
else
|
|
124
125
|
puts "Gem management tasks unavailable, as rubygems was not fully loaded."
|
data/bin/vanilla
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'rake'
|
|
4
|
+
load File.join(File.dirname(__FILE__), *%w[.. lib tasks vanilla.rake])
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
pristine_app = File.expand_path("../../pristine_app", __FILE__)
|
|
6
|
-
FileUtils.cp_r(pristine_app, new_app_dir)
|
|
7
|
-
FileUtils.mkdir_p(File.join(new_app_dir, "tmp"))
|
|
8
|
-
require 'vanilla'
|
|
9
|
-
File.open(File.join(new_app_dir, "Gemfile"), "w") do |f|
|
|
10
|
-
f.write "source :rubygems\n\n# Vanilla itself.\ngem 'vanilla', '#{Vanilla::VERSION}'"
|
|
11
|
-
end
|
|
12
|
-
puts File.readlines(File.join(new_app_dir, "README"))[0..16].join
|
|
13
|
-
end
|
|
6
|
+
mkdir(ARGV[0])
|
|
7
|
+
cd(ARGV[0])
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
$LOAD_PATH << "lib"
|
|
17
|
-
require "rubygems"
|
|
18
|
-
require "bundler/setup"
|
|
19
|
-
require "irb"
|
|
20
|
-
require "vanilla/console"
|
|
21
|
-
ARGV.clear
|
|
22
|
-
puts "The Soup is simmering."
|
|
23
|
-
IRB.start
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def upgrade
|
|
27
|
-
# TODO
|
|
28
|
-
puts "TODO, but should be easier thanks to multi-space soup."
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
case ARGV[0]
|
|
32
|
-
when "console"
|
|
33
|
-
console
|
|
34
|
-
when "upgrade"
|
|
35
|
-
upgrade
|
|
36
|
-
else
|
|
37
|
-
create(ARGV[0])
|
|
38
|
-
end
|
|
9
|
+
Rake::Task['vanilla:setup'].invoke
|
data/config.example.yml
ADDED
data/config.ru
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[lib])
|
|
2
|
+
require 'vanilla'
|
|
3
|
+
|
|
4
|
+
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
|
|
5
|
+
use Rack::Session::Cookie, :key => 'vanilla.session',
|
|
6
|
+
:path => '/',
|
|
7
|
+
:expire_after => 2592000,
|
|
8
|
+
:secret => app.config[:secret]
|
|
9
|
+
use Rack::Static, :urls => ["/public"], :root => File.join(File.dirname(__FILE__))
|
|
10
|
+
run app
|
data/lib/defensio.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class Defensio
|
|
2
|
+
class << self
|
|
3
|
+
attr_accessor :format
|
|
4
|
+
attr_accessor :service_type
|
|
5
|
+
attr_accessor :api_version
|
|
6
|
+
attr_accessor :api_key
|
|
7
|
+
attr_accessor :owner_url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
self.format = :xml
|
|
11
|
+
self.service_type = :app # Can be :blog
|
|
12
|
+
self.api_version = '1.2'
|
|
13
|
+
|
|
14
|
+
def self.configure(confhash)
|
|
15
|
+
if confhash['test']
|
|
16
|
+
@mock = true
|
|
17
|
+
self.owner_url = 'http://www.example.com'
|
|
18
|
+
return
|
|
19
|
+
else
|
|
20
|
+
confhash.each do |prop, val|
|
|
21
|
+
self.send("#{prop}=", val)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.method_missing(name, *args)
|
|
27
|
+
self.post(name.to_s.dasherize, *args)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
def self.connection
|
|
32
|
+
uri = URI.parse('http://api.defensio.com/')
|
|
33
|
+
Net::HTTP.start(uri.host, uri.port)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.post(action, params = {})
|
|
37
|
+
resp = connection.post(real_path(action), params_from_hash(params))
|
|
38
|
+
raise "Problem with request: #{action}" unless resp.code == '200'
|
|
39
|
+
parse_response(resp.body)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.real_path(action)
|
|
43
|
+
"/#{service_type}/#{api_version}/#{action}/#{api_key}.#{format}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.params_from_hash(params = {})
|
|
47
|
+
# Thanks Net::HTTPHeader
|
|
48
|
+
params.stringify_keys.merge('owner-url' => owner_url).map {|k,v| "#{CGI.escape(k.dasherize.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.parse_response(body)
|
|
52
|
+
case format
|
|
53
|
+
when :yaml
|
|
54
|
+
YAML.load(body)
|
|
55
|
+
when :xml
|
|
56
|
+
Hash.from_xml(body)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
|
2
|
+
require 'vanilla'
|
|
3
|
+
|
|
4
|
+
namespace :vanilla do
|
|
5
|
+
desc "Open an irb session preloaded with this library"
|
|
6
|
+
task :console do
|
|
7
|
+
sh "irb -Ilib -rubygems -rvanilla -rvanilla/console"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
task :clean do
|
|
11
|
+
# TODO: get the database name from Soup
|
|
12
|
+
FileUtils.rm "soup.db" if File.exist?("soup.db")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
task :load_snips do
|
|
16
|
+
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
|
|
17
|
+
Dynasnip.all.each { |ds| app.soup << ds.snip_attributes }
|
|
18
|
+
|
|
19
|
+
Dir[File.join(File.dirname(__FILE__), '..', 'vanilla', 'snips', '*.rb')].each do |f|
|
|
20
|
+
load f
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
puts "The soup is simmering."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc 'Resets the soup to contain the base snips only. Dangerous!'
|
|
27
|
+
task :reset => [:clean, :load_snips]
|
|
28
|
+
|
|
29
|
+
namespace :upgrade do
|
|
30
|
+
desc 'Upgrade the dynasnips'
|
|
31
|
+
task :dynasnips do
|
|
32
|
+
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
|
|
33
|
+
Dynasnip.all.each do |dynasnip|
|
|
34
|
+
print "Upgrading #{dynasnip.snip_name}... "
|
|
35
|
+
# TODO: our confused Soup interface might return an array.
|
|
36
|
+
snip = app.soup[dynasnip.snip_name]
|
|
37
|
+
if snip.empty? || snip.nil?
|
|
38
|
+
# it's a new dyna
|
|
39
|
+
app.soup << dynasnip.snip_attributes
|
|
40
|
+
puts "(new)"
|
|
41
|
+
elsif snip.created_at == snip.updated_at
|
|
42
|
+
# it's not been changed, let's upgrade
|
|
43
|
+
snip.destroy
|
|
44
|
+
app.soup << dynasnip.snip_attributes
|
|
45
|
+
puts "(unedited)"
|
|
46
|
+
else
|
|
47
|
+
# the dyna exists and has been changed
|
|
48
|
+
dynasnip.snip_attributes.each do |name, value|
|
|
49
|
+
unless (existing_value = snip.get_value(name)) == value
|
|
50
|
+
puts "Conflict in attribute '#{name}':"
|
|
51
|
+
puts "> Your soup: '#{existing_value}'"
|
|
52
|
+
puts "> New soup: '#{value}"
|
|
53
|
+
print "Upgrade? [Y/n]: "
|
|
54
|
+
upgrade_value = ["Y", "y", ""].include? STDIN.gets.chomp.strip
|
|
55
|
+
snip.set_value(name, value) if upgrade_value
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
snip.save
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
desc 'Upgrade dynasnips and system snips'
|
|
65
|
+
task :upgrade => ["upgrade:dynasnips"]
|
|
66
|
+
|
|
67
|
+
desc 'Add a user (or change an existing password)'
|
|
68
|
+
task :add_user => :prepare do
|
|
69
|
+
puts "Adding a new user"
|
|
70
|
+
# config_file = ENV['VANILLA_CONFIG'] || 'config.yml'
|
|
71
|
+
# config_file = YAML.load(File.open(config_file)) rescue {}
|
|
72
|
+
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
|
|
73
|
+
print "Username: "
|
|
74
|
+
username = STDIN.gets.chomp.strip
|
|
75
|
+
print "Password: "
|
|
76
|
+
password = STDIN.gets.chomp.strip
|
|
77
|
+
print "Confirm password: "
|
|
78
|
+
confirm_password = STDIN.gets.chomp.strip
|
|
79
|
+
if password != confirm_password
|
|
80
|
+
raise "Passwords don't match!"
|
|
81
|
+
else
|
|
82
|
+
app.config[:credentials] ||= {}
|
|
83
|
+
app.config[:credentials][username] = MD5.md5(password).to_s
|
|
84
|
+
app.config.save!
|
|
85
|
+
puts "User '#{username}' added."
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
desc 'Generate file containing secret for cookie-based session storage'
|
|
90
|
+
task :generate_secret do
|
|
91
|
+
# Adapted from old rails secret generator.
|
|
92
|
+
require 'openssl'
|
|
93
|
+
if !File.exist?("/dev/urandom")
|
|
94
|
+
# OpenSSL transparently seeds the random number generator with
|
|
95
|
+
# data from /dev/urandom. On platforms where that is not
|
|
96
|
+
# available, such as Windows, we have to provide OpenSSL with
|
|
97
|
+
# our own seed. Unfortunately there's no way to provide a
|
|
98
|
+
# secure seed without OS support, so we'll have to do with
|
|
99
|
+
# rand() and Time.now.usec().
|
|
100
|
+
OpenSSL::Random.seed(rand(0).to_s + Time.now.usec.to_s)
|
|
101
|
+
end
|
|
102
|
+
data = OpenSSL::BN.rand(2048, -1, false).to_s
|
|
103
|
+
secret = OpenSSL::Digest::SHA1.new(data).hexdigest
|
|
104
|
+
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
|
|
105
|
+
app.config[:secret] = secret
|
|
106
|
+
app.config.save!
|
|
107
|
+
puts "Secret generated."
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
desc 'Prepare standard files to run Vanilla'
|
|
111
|
+
task :prepare_files do
|
|
112
|
+
cp File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. config.ru])), 'config.ru'
|
|
113
|
+
cp_r File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. public])), 'public'
|
|
114
|
+
mkdir 'tmp'
|
|
115
|
+
File.open("Rakefile", "w") do |f|
|
|
116
|
+
rakefile =<<-EOF
|
|
117
|
+
require 'vanilla'
|
|
118
|
+
load 'tasks/vanilla.rake'
|
|
119
|
+
|
|
120
|
+
# Add any other tasks here.
|
|
121
|
+
EOF
|
|
122
|
+
f.write rakefile.strip
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
desc 'Prepare a new vanilla.rb installation'
|
|
128
|
+
task :setup do
|
|
129
|
+
puts <<-EOM
|
|
130
|
+
|
|
131
|
+
===================~ Vanilla.rb ~====================
|
|
132
|
+
|
|
133
|
+
Congratulations! You have elected to try out the weirdest web thing ever.
|
|
134
|
+
Lets get started. Firstly, I'm going to cook you some soup:
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
EOM
|
|
138
|
+
Rake::Task['vanilla:load_snips'].invoke
|
|
139
|
+
|
|
140
|
+
puts <<-EOM
|
|
141
|
+
|
|
142
|
+
Now I'm going to generate your configuration. This will be stored either in
|
|
143
|
+
'config.yml' in the current directory, or in the path you provide via the
|
|
144
|
+
environment variable VANILLA_CONFIG.
|
|
145
|
+
|
|
146
|
+
Generating the secret for cookie-based session storage.
|
|
147
|
+
EOM
|
|
148
|
+
Rake::Task['vanilla:prepare_files'].invoke
|
|
149
|
+
Rake::Task['vanilla:generate_secret'].invoke
|
|
150
|
+
|
|
151
|
+
puts <<-EOM
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
Now that we've got our broth, you'll want to add a user, so you can edit stuff.
|
|
155
|
+
Lets do that now:
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
EOM
|
|
159
|
+
Rake::Task['vanilla:add_user'].invoke
|
|
160
|
+
puts <<-EOM
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
OK! You're ready to go. To start vanilla.rb, you'll want to get it running under
|
|
164
|
+
a webserver that supports Rack. The easiest way to do this locally is via 'rackup':
|
|
165
|
+
|
|
166
|
+
$ rackup
|
|
167
|
+
|
|
168
|
+
Then go to http://localhost:9292
|
|
169
|
+
|
|
170
|
+
I'm going now, Goodbye!
|
|
171
|
+
EOM
|
|
172
|
+
end
|
|
173
|
+
end
|