From b31c9d0048aab0cf0befef815d06d6eda198743b Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Sat, 28 Oct 2017 22:07:00 -0400 Subject: [PATCH 01/10] Organize Gemfile --- Gemfile | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index f52d7ba..b8028e2 100644 --- a/Gemfile +++ b/Gemfile @@ -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 From 50b59b0d2f0133fab0963ad943f299f48b2d7977 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Sat, 28 Oct 2017 22:07:16 -0400 Subject: [PATCH 02/10] Add .ruby-version --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..951d42f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.4.2 From d15a0c92ca98fe2561e4c9527b3ed3afbc0097d1 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Sat, 28 Oct 2017 22:08:16 -0400 Subject: [PATCH 03/10] Start working with Rack --- lib/sapling/middleware.rb | 14 ++++++++++++++ lib/sapling/server.ru | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 lib/sapling/middleware.rb create mode 100644 lib/sapling/server.ru diff --git a/lib/sapling/middleware.rb b/lib/sapling/middleware.rb new file mode 100644 index 0000000..604338c --- /dev/null +++ b/lib/sapling/middleware.rb @@ -0,0 +1,14 @@ +require_relative './gardner' + +class Middle + attr_reader :tree + + def initialize(app) + @app = app + @tree = Gardner::Plot.new(YAML.load_file('lib/sapling/example.yaml')) + end + + def call(env) + @app.call(env) + end +end diff --git a/lib/sapling/server.ru b/lib/sapling/server.ru new file mode 100644 index 0000000..1b09c14 --- /dev/null +++ b/lib/sapling/server.ru @@ -0,0 +1,17 @@ +require 'erb' + +require_relative './gardner' + +# Rack Stuff +class Greenhouse + + def initialize + @response = ERB.new(File.read('lib/sapling/index.erb')).result(binding) + end + + def call(_env) + ['200', { 'Content-Type' => 'text/html' }, [@response]] + end +end + +run Greenhouse.new From a3f9f5598beec446d9725d21a27f9471c283252e Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Sat, 28 Oct 2017 22:08:38 -0400 Subject: [PATCH 04/10] ERB Template for Rack server --- lib/sapling/index.erb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/sapling/index.erb diff --git a/lib/sapling/index.erb b/lib/sapling/index.erb new file mode 100644 index 0000000..949984a --- /dev/null +++ b/lib/sapling/index.erb @@ -0,0 +1,20 @@ + + + + + + Sapling: Adventure Awaits! + + +
+

Sapling

+
+ GitHub +
+
+
+ <%= @tree.trunk %> + + From 0c18f3cc80b9b59675915436fe6adc3c6fddca24 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Mon, 30 Oct 2017 00:20:46 -0400 Subject: [PATCH 05/10] Cleanup testing files --- lib/sapling/middleware.rb | 14 -------------- lib/sapling/server.ru | 17 ----------------- 2 files changed, 31 deletions(-) delete mode 100644 lib/sapling/middleware.rb delete mode 100644 lib/sapling/server.ru diff --git a/lib/sapling/middleware.rb b/lib/sapling/middleware.rb deleted file mode 100644 index 604338c..0000000 --- a/lib/sapling/middleware.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative './gardner' - -class Middle - attr_reader :tree - - def initialize(app) - @app = app - @tree = Gardner::Plot.new(YAML.load_file('lib/sapling/example.yaml')) - end - - def call(env) - @app.call(env) - end -end diff --git a/lib/sapling/server.ru b/lib/sapling/server.ru deleted file mode 100644 index 1b09c14..0000000 --- a/lib/sapling/server.ru +++ /dev/null @@ -1,17 +0,0 @@ -require 'erb' - -require_relative './gardner' - -# Rack Stuff -class Greenhouse - - def initialize - @response = ERB.new(File.read('lib/sapling/index.erb')).result(binding) - end - - def call(_env) - ['200', { 'Content-Type' => 'text/html' }, [@response]] - end -end - -run Greenhouse.new From 090a65ed8a75be10444ff4420786e65364a98913 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Mon, 30 Oct 2017 00:21:44 -0400 Subject: [PATCH 06/10] Update Gemfile.lock --- Gemfile.lock | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index bd564d0..a13aa84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 From 522c23b206530507c1f291db4e8b2abd8a72074b Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Mon, 30 Oct 2017 00:22:00 -0400 Subject: [PATCH 07/10] Greenhouse: Simple Rack application --- lib/sapling/greenhouse.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/sapling/greenhouse.rb diff --git a/lib/sapling/greenhouse.rb b/lib/sapling/greenhouse.rb new file mode 100644 index 0000000..cf88e19 --- /dev/null +++ b/lib/sapling/greenhouse.rb @@ -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 From ed521bfbcd97ad5a57d3065ee42e1233122da631 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Mon, 30 Oct 2017 00:22:31 -0400 Subject: [PATCH 08/10] 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 --- lib/sapling.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/sapling.rb b/lib/sapling.rb index 901094b..721455a 100644 --- a/lib/sapling.rb +++ b/lib/sapling.rb @@ -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 From 5c71b1dd270626a792e5d2dec0c3839dfd0a40a8 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Mon, 30 Oct 2017 00:25:17 -0400 Subject: [PATCH 09/10] Add .gem to gitignore --- .gitignore | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 3a20835..bf65b63 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ From d7bd464310f3e2ea42a7396a1bf5e4d60c2234dc Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Mon, 30 Oct 2017 00:39:20 -0400 Subject: [PATCH 10/10] Gemspec: Add demo tree file to included files --- sapling-dialogue.gemspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sapling-dialogue.gemspec b/sapling-dialogue.gemspec index 3aebab3..ad7550a 100644 --- a/sapling-dialogue.gemspec +++ b/sapling-dialogue.gemspec @@ -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