Compare commits

...

10 commits
master ... web

Author SHA1 Message Date
Bill Niblock
d7bd464310 Gemspec: Add demo tree file to included files 2017-10-30 00:39:20 -04:00
Bill Niblock
5c71b1dd27 Add .gem to gitignore 2017-10-30 00:25:39 -04:00
Bill Niblock
ed521bfbcd Sapling: Add functionality for web and demo
- Web: Add `serve` functionality, which starts a simple Rack application
to serve a template page. Template still needs work.

- Demo: add `example` option, which starts the CLI using the "Example
Quest!" tree
2017-10-30 00:22:31 -04:00
Bill Niblock
522c23b206 Greenhouse: Simple Rack application 2017-10-30 00:22:00 -04:00
Bill Niblock
090a65ed8a Update Gemfile.lock 2017-10-30 00:21:44 -04:00
Bill Niblock
0c18f3cc80 Cleanup testing files 2017-10-30 00:20:46 -04:00
Bill Niblock
a3f9f5598b ERB Template for Rack server 2017-10-28 22:08:38 -04:00
Bill Niblock
d15a0c92ca Start working with Rack 2017-10-28 22:08:16 -04:00
Bill Niblock
50b59b0d2f Add .ruby-version 2017-10-28 22:07:16 -04:00
Bill Niblock
b31c9d0048 Organize Gemfile 2017-10-28 22:07:00 -04:00
8 changed files with 90 additions and 20 deletions

10
.gitignore vendored
View file

@ -53,9 +53,7 @@ Thumbs.db
.netrwhist
*.un~
# YARD Related #
################
# doc/ is the generated documentation for Yard, which can easily be generated
# locally with yardoc
# .yardoc/ is yard metadata, not necessary to be uploaded to GH
.yardoc/
# Ruby #
########
*.gem
/.yardoc/

1
.ruby-version Normal file
View file

@ -0,0 +1 @@
ruby-2.4.2

27
Gemfile
View file

@ -1,12 +1,21 @@
# frozen_string_literal: true
source "https://rubygems.org"
source 'https://rubygems.org'
# Documentation
gem "rdoc"
gem "redcarpet"
gem "thor"
gem "yard"
gem "yard-ghpages"
ruby '2.4.2'
# Testing
gem "rubocop"
gem 'thor'
group :documentation do
gem 'rdoc'
gem 'redcarpet'
gem 'yard'
gem 'yard-ghpages'
end
group :test do
gem 'rubocop'
end
group :web do
gem 'rack'
end

View file

@ -6,6 +6,7 @@ GEM
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
rack (2.0.3)
rainbow (2.2.2)
rake
rake (11.3.0)
@ -30,6 +31,7 @@ PLATFORMS
ruby
DEPENDENCIES
rack
rdoc
redcarpet
rubocop
@ -37,5 +39,8 @@ DEPENDENCIES
yard
yard-ghpages
RUBY VERSION
ruby 2.4.2p198
BUNDLED WITH
1.14.6
1.15.4

View file

@ -1,5 +1,7 @@
#!/usr/bin/env ruby
# frozen string literal: true
require 'rack'
require 'thor'
require 'yaml'
@ -7,6 +9,7 @@ Dir[File.join(__dir__, 'sapling', '*.rb')].each { |file| require file }
# The main Sapling interface.
class Sapling < Thor
# CLI-based options
desc 'read TREE', 'Load and traverse the TREE'
def read(file)
puts 'Welcome to Sapling, a Dialogue Tree Utility.'
@ -30,10 +33,16 @@ class Sapling < Thor
gardner.plant
end
# Web-based options
desc 'serve TREE', 'Load TREE in a web-based interface'
def serve(tree)
exit unless verify_tree(tree)
puts 'Sinatra will be cool.'
def serve(file)
exit unless verify_tree(file)
tree = Gardner::Plot.new(YAML.load_file(file))
Rack::Server.new(
app: Greenhouse.new(tree),
server: 'webrick',
Port: 9000
).start
end
desc 'export TREE', 'Save a portable HTML version of TREE'
@ -41,4 +50,15 @@ class Sapling < Thor
exit unless verify_tree(tree)
puts 'Cool feature, bro!'
end
# Miscellaneous options
desc 'example', 'Play Example Quest!'
def example
file = File.join(__dir__, '..', 'var', 'trees', 'example_quest.yaml')
puts 'Welcome to Sapling, a Dialogue Tree Utility.'
exit unless verify_tree(file)
tree = Gardner::Plot.new(YAML.load_file(file))
speaker = Dialogue::Speaker.new(tree, false)
speaker.conversation
end
end

15
lib/sapling/greenhouse.rb Normal file
View file

@ -0,0 +1,15 @@
require 'erb'
# The rack application
class Greenhouse
attr_reader :tree
def initialize(file)
@tree = file
@response = ERB.new(File.read('lib/sapling/index.erb')).result(binding)
end
def call(_env)
['200', { 'Content-Type' => 'text/html' }, [@response]]
end
end

20
lib/sapling/index.erb Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sapling: Adventure Awaits!</title>
</head>
<body>
<div class="header">
<div><p>Sapling</p></div>
<div>
<a href="https://www.github.com/vagabondazulien/sapling">GitHub</a>
</div>
</div>
<div class="main">
<%= @tree.trunk %>
<div class="footer">
<div><p>Made with <3 by Nibz</p></div>
</div>
</body>

View file

@ -7,7 +7,9 @@ Gem::Specification.new do |s|
s.description = 'Create, edit, and traverse dialogue trees'
s.authors = ['Bill Niblock']
s.email = 'azulien@gmail.com'
s.files = Dir['lib/**/*.rb'] + Dir['bin/*']
s.files = Dir['lib/**/*.rb'] +
Dir['bin/*'] +
Dir['var/trees/*']
s.homepage = 'http://www.theinternetvagabond.com/sapling/'
s.license = 'MIT'
end