commit 3ccef121b8261c54330c8a83cc31750105e5d78e Author: Ryan McGrath Date: Tue Apr 19 17:21:03 2016 +0900 Commit diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..512f9f3 --- /dev/null +++ b/app.rb @@ -0,0 +1,20 @@ +require 'sinatra' +require 'tilt/erb' + + +set :public_folder, 'public' + +class CorgBotApp < Sinatra::Base + get '/' do + extensions = ['.png', '.jpg', '.jpeg', '.gif'] + images = Dir.entries('public/images').delete_if { |x| + extension = x[-4, 4] + !extensions.index(extension) + } + + corgi = images[rand(images.length)] + erb :index, :locals => { + :corgi => corgi + } + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..e9b473d --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require './app' +run CorgBotApp diff --git a/public/images/PembrokeWelshCorgi_hero.jpg b/public/images/PembrokeWelshCorgi_hero.jpg new file mode 100644 index 0000000..c75efd5 Binary files /dev/null and b/public/images/PembrokeWelshCorgi_hero.jpg differ diff --git a/public/images/o-CORGI-ROCK-TURTLE-facebook.jpg b/public/images/o-CORGI-ROCK-TURTLE-facebook.jpg new file mode 100644 index 0000000..13bc928 Binary files /dev/null and b/public/images/o-CORGI-ROCK-TURTLE-facebook.jpg differ diff --git a/public/images/o-CORGI-facebook.jpg b/public/images/o-CORGI-facebook.jpg new file mode 100644 index 0000000..e572c13 Binary files /dev/null and b/public/images/o-CORGI-facebook.jpg differ diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a29b244 --- /dev/null +++ b/readme.md @@ -0,0 +1,19 @@ +# CorgBot Example Repo +My girlfriend was interested in Ruby development, putting up a tutorial for her to break down as desired. + + +## Steps +``` bash +# Install Sinatra +gem install sinatra + +# Run development server +rackup +``` + +## How It Works +On each index (`/`) load, selects a random image from the `public/images` directory and returns a view (`views/index.erb`) that displays the image. Run with it as you will. + + +## License +None, do what you want with it. Simply an example. diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000..fc4f5ea --- /dev/null +++ b/views/index.erb @@ -0,0 +1,9 @@ + + + + + + + + +