Permalink
Browse files

Initial commit

  • Loading branch information...
mrako committed Oct 20, 2011
0 parents commit 54cb3e3f4b8b76fd2a6112dd9e3c777bde7be047
@@ -0,0 +1,4 @@
+tmp
+.DS_Store
+**/.DS_Store
+**/*(Autosaved)*
1 .rspec
@@ -0,0 +1 @@
+--colour
10 Gemfile
@@ -0,0 +1,10 @@
+source :rubygems
+
+gem "sinatra"
+gem "haml"
+
+group :test, :development do
+ gem "rack-test"
+ gem "rspec"
+ gem "rcov"
+end
@@ -0,0 +1,34 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.3)
+ haml (3.1.3)
+ rack (1.3.5)
+ rack-protection (1.1.4)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rcov (0.9.11)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ sinatra (1.3.1)
+ rack (>= 1.3.4, ~> 1.3)
+ rack-protection (>= 1.1.2, ~> 1.1)
+ tilt (>= 1.3.3, ~> 1.3)
+ tilt (1.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ haml
+ rack-test
+ rcov
+ rspec
+ sinatra
No changes.
@@ -0,0 +1,31 @@
+require 'rubygems'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+end
+
+RSpec::Core::RakeTask.new(:rcov) do |t|
+ t.rcov = true
+ t.rcov_opts = %q[--include "app" --exclude "spec"]
+end
+
+namespace :war do
+ task :compile do
+ sh "cd java; ant"
+ end
+
+ task :bundle do
+ sh "warble"
+ end
+
+ task :rename_and_copy do
+ sh "mv sinatra-jruby-warbler.war jetty/webapps/ROOT.war"
+ end
+
+ task :start do
+ sh "cd jetty; java -Djetty.port=8000 -jar start.jar"
+ end
+
+ task :deploy => [:compile, :bundle, :rename_and_copy, :start]
+end
@@ -0,0 +1,6 @@
+require 'init'
+
+set :run, false
+set :environment, :production
+
+run Sinatra::Application
@@ -0,0 +1,11 @@
+development:
+ host: localhost
+ port: 27017
+ database: dict_dev
+
+production:
+ host: localhost
+ port: 27017
+ database: dict_prod
+
+environment: development
@@ -0,0 +1,14 @@
+require "rubygems"
+require "haml"
+
+get '/' do
+ @values = KeyValue.all
+
+ haml :home, :layout => :layout
+end
+
+post '/' do
+ KeyValue.create!(params)
+
+ redirect '/'
+end
37 init.rb
@@ -0,0 +1,37 @@
+require 'rubygems'
+require 'sinatra'
+require 'yaml'
+require 'mongo_mapper'
+
+configure do
+ root = File.expand_path(File.dirname(__FILE__))
+end
+
+not_found do
+ status 404
+end
+
+
+
+# Else read the local configuration
+@config = YAML.load_file("config/database.yml")
+
+@environment = @config["environment"]
+
+@db_host = @config[@environment]["host"]
+@db_port = @config[@environment]["port"]
+@db_name = @config[@environment]["database"]
+
+
+# Configure the environment
+
+MongoMapper.connection = Mongo::Connection.new(@db_host, @db_port)
+MongoMapper.database = @db_name
+
+MongoMapper.connection.connect
+
+
+Dir["models/*.rb"].each{ |file| require file }
+
+Dir["controllers/*.rb"].each{ |file| load file }
+
Binary file not shown.
@@ -0,0 +1,9 @@
+require 'rubygems'
+require 'mongo_mapper'
+
+class KeyValue
+ include MongoMapper::Document
+
+ key :key, String, :required => true
+ key :value, String, :required => true
+end
@@ -0,0 +1,16 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'init'
+
+describe "controller" do
+ include Rack::Test::Methods
+
+ def app
+ @app ||= Sinatra::Application
+ end
+
+ it "should return the list of installed printers" do
+ get "/"
+ last_response.should be_ok
+ end
+end
@@ -0,0 +1,9 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe KeyValue do
+
+ it "should create a new key-value pair" do
+ KeyValue.new(:key => "test", :value => "val").should_not be_nil
+ end
+
+end
@@ -0,0 +1,9 @@
+require 'rubygems'
+require 'sinatra'
+require 'rack/test'
+
+set :environment, :test
+set :views, File.dirname(__FILE__) + "/../views"
+
+
+Dir["app/models/*.rb"].each{ |file| require file }
@@ -0,0 +1,14 @@
+%form(action='/' method='POST')
+ %input(type='text' name='key' value='')
+ %input(type='text' name='value' value='')
+ %input(type='submit')
+
+.saved
+ %h2 Saved values
+
+ %ul
+ - @values.each do |v|
+ %li
+ = v.key
+ \-
+ = v.value
@@ -0,0 +1,7 @@
+!!!
+%html{:lang => "en", "xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
+ %head
+ %meta{:content => "text/html;charset=UTF-8", "http-equiv" => "content-type"}
+
+ %body
+ =yield

0 comments on commit 54cb3e3

Please sign in to comment.