-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
34 changed files
with
744 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"directory": "lib/components", | ||
"public": "public/_components" | ||
} |
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 @@ | ||
# Development specific: | ||
.rspec_status | ||
.tags* | ||
|
||
# Temporary data should not be added to the repository: | ||
tmp/ | ||
|
||
# This file should only ever exist on production, and may contain sensitive information: | ||
config/environment.yaml |
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,4 @@ | ||
--format documentation | ||
--backtrace | ||
--warnings | ||
--require spec_helper |
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,35 @@ | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "utopia", "~> 2.3.0" | ||
# gem "utopia-gallery" | ||
# gem "utopia-analytics" | ||
|
||
gem "rake" | ||
gem "bundler" | ||
|
||
gem 'async-websocket' | ||
|
||
gem "rack-freeze", "~> 1.2" | ||
|
||
group :development do | ||
# For `rake server`: | ||
gem "guard-falcon", require: false | ||
gem 'guard-rspec', require: false | ||
|
||
# For `rake console`: | ||
gem "pry" | ||
gem "rack-test" | ||
|
||
# For `rspec` testing: | ||
gem "rspec" | ||
gem "simplecov" | ||
|
||
# For testing: | ||
gem 'async-rspec' | ||
end | ||
|
||
group :production do | ||
# Used for passenger-config to restart server after deployment: | ||
gem "passenger" | ||
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,29 @@ | ||
|
||
group :development do | ||
guard :falcon, port: 9292 do | ||
watch('Gemfile.lock') | ||
watch('config.ru') | ||
watch(%r{^config|lib|pages/.*}) | ||
|
||
notification :off | ||
end | ||
end | ||
|
||
group :test do | ||
guard :rspec, cmd: 'rspec' do | ||
# Notifications can get a bit tedious: | ||
# notification :off | ||
|
||
# Re-run specs if they are changed: | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch('spec/spec_helper.rb') {'spec'} | ||
|
||
# Run relevent specs if files in `lib/` or `pages/` are changed: | ||
watch(%r{^lib/(.+)\.rb$}) {|match| "spec/lib/#{match[1]}_spec.rb" } | ||
watch(%r{^pages/(.+)\.(rb|xnode)$}) {|match| "spec/pages/#{match[1]}_spec.rb"} | ||
watch(%r{^pages/(.+)controller\.rb$}) {|match| Dir.glob("spec/pages/#{match[1]}*_spec.rb")} | ||
|
||
# If any files in pages changes, ensure the website still works: | ||
watch(%r{^pages/.*}) {'spec/website_spec.rb'} | ||
end | ||
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,16 @@ | ||
# Example WebSocket Chat Server | ||
|
||
This is a simple chat client/server implementation with specs. | ||
|
||
## Starting Development Server | ||
|
||
To start the development server, simply execute | ||
|
||
> rake | ||
Generating transient session key for development... | ||
20:57:36 - INFO - Starting Falcon HTTP server on localhost:9292 | ||
20:57:36 - INFO - Guard::RSpec is running | ||
20:57:36 - INFO - Guard is now watching at '...' | ||
[1] guard(main)> | ||
|
||
Then browse http://localhost:9292 (or as specified) to see your new site. |
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,8 @@ | ||
|
||
require 'pathname' | ||
SITE_ROOT = Pathname.new(__dir__).realpath | ||
|
||
# Load all rake tasks: | ||
import(*Dir.glob('tasks/**/*.rake')) | ||
|
||
task :default => :development |
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,47 @@ | ||
#!/usr/bin/env rackup | ||
|
||
require_relative 'config/environment' | ||
|
||
require 'rack/freeze' | ||
|
||
if RACK_ENV == :production | ||
# Handle exceptions in production with a error page and send an email notification: | ||
use Utopia::Exceptions::Handler | ||
use Utopia::Exceptions::Mailer | ||
else | ||
# We want to propate exceptions up when running tests: | ||
use Rack::ShowExceptions unless RACK_ENV == :test | ||
|
||
# Serve the public directory in a similar way to the web server: | ||
use Utopia::Static, root: 'public' | ||
end | ||
|
||
use Rack::Sendfile | ||
|
||
use Utopia::ContentLength | ||
|
||
use Utopia::Redirection::Rewrite, | ||
'/' => '/client/index' | ||
|
||
use Utopia::Redirection::DirectoryIndex | ||
|
||
use Utopia::Redirection::Errors, | ||
404 => '/errors/file-not-found' | ||
|
||
use Utopia::Localization, | ||
:default_locale => 'en', | ||
:locales => ['en', 'de', 'ja', 'zh'] | ||
|
||
require 'utopia/session' | ||
use Utopia::Session, | ||
:expires_after => 3600 * 24, | ||
:secret => ENV['UTOPIA_SESSION_SECRET'] | ||
|
||
use Utopia::Controller | ||
|
||
use Utopia::Static | ||
|
||
# Serve dynamic content | ||
use Utopia::Content | ||
|
||
run lambda { |env| [404, {}, []] } |
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,7 @@ | ||
# Utopia Config | ||
|
||
This directory contains `environment.rb` which is used to initialize the running environment for tasks and servers. | ||
|
||
## Setting Environment Variables | ||
|
||
If you wish to set environment variables on a per-deployment basis, you can do so by creating an `config/environment.yaml` and populating it with key-value pairs. |
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,8 @@ | ||
|
||
require 'bundler/setup' | ||
Bundler.setup | ||
|
||
require 'utopia/setup' | ||
Utopia.setup | ||
|
||
RACK_ENV = ENV.fetch('RACK_ENV', :development).to_sym unless defined? RACK_ENV |
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 @@ | ||
You can add additional code for your application in this directory, and require it directly from the config.ru. |
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,2 @@ | ||
<?r document.attributes[:title] ||= content ?> | ||
<h1><utopia:content/></h1> |
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,30 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<?r response.cache! ?> | ||
|
||
<?r if title = self[:title] ?> | ||
<title>#{title.gsub(/<.*?>/, "")} - Utopia</title> | ||
<?r else ?> | ||
<title>Utopia</title> | ||
<?r end ?> | ||
|
||
<base href="#{first.node.uri_path}"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
|
||
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous" /> | ||
|
||
<link rel="icon" type="image/png" href="/_static/icon.png" /> | ||
<link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" /> | ||
</head> | ||
|
||
<body class="#{attributes[:class]}"> | ||
<header> | ||
<img src="/_static/utopia.svg" /> | ||
</header> | ||
|
||
<div id="page"> | ||
<utopia:content/> | ||
</div> | ||
</body> | ||
</html> |
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,28 @@ | ||
|
||
var url = new URL('/server/connect', window.location.href); | ||
url.protocol = url.protocol.replace('http', 'ws'); | ||
|
||
console.log("Connecting to server", url); | ||
var server = new WebSocket(url.href); | ||
console.log("Connected to", server); | ||
|
||
server.onopen = function(event) { | ||
chat.onkeypress = function(event) { | ||
if (event.keyCode == 13) { | ||
server.send(JSON.stringify({text: chat.value})); | ||
|
||
chat.value = ""; | ||
} | ||
} | ||
}; | ||
|
||
server.onmessage = function(event) { | ||
console.log("Got message", event); | ||
|
||
var message = JSON.parse(event.data); | ||
|
||
var pre = document.createElement('pre'); | ||
pre.innerText = message.text; | ||
|
||
response.appendChild(pre); | ||
}; |
Empty file.
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,8 @@ | ||
<content:page> | ||
<content:heading>Client</content:heading> | ||
|
||
<script src="client.js?#{rand}"></script> | ||
<section id="response" style="border: 1px;"></section> | ||
|
||
<input id="chat" /> | ||
</content:page> |
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,5 @@ | ||
<content:page> | ||
<content:heading>Exception</content:heading> | ||
|
||
<p>It seems like something didn't quite work out as expected!</p> | ||
</content:page> |
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,5 @@ | ||
<content:page> | ||
<content:heading>File Not Found</content:heading> | ||
|
||
<p>The file you requested is unfortunately not available at this time!</p> | ||
</content:page> |
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,2 @@ | ||
errors: | ||
display: false |
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,21 @@ | ||
|
||
prepend Actions | ||
|
||
require 'async/websocket/server' | ||
|
||
$connections = [] | ||
|
||
on 'connect' do |request| | ||
Async::WebSocket::Server.open(request.env) do |connection| | ||
$connections << connection | ||
|
||
while message = connection.next_message | ||
$connections.each do |connection| | ||
puts "Server sending message: #{message.inspect}" | ||
connection.send_message(message) | ||
end | ||
end | ||
end | ||
|
||
succeed! | ||
end |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.