This commit is contained in:
Ryan McGrath 2016-04-19 17:21:03 +09:00
commit 3ccef121b8
No known key found for this signature in database
GPG key ID: 811674B62B666830
7 changed files with 50 additions and 0 deletions

20
app.rb Normal file
View file

@ -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

2
config.ru Normal file
View file

@ -0,0 +1,2 @@
require './app'
run CorgBotApp

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

19
readme.md Normal file
View file

@ -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.

9
views/index.erb Normal file
View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0">
</head>
<body>
<img src="/images/<%= corgi %>" width="320" />
</body>
</html>