Commit
This commit is contained in:
commit
3ccef121b8
7 changed files with 50 additions and 0 deletions
20
app.rb
Normal file
20
app.rb
Normal 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
2
config.ru
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require './app'
|
||||
run CorgBotApp
|
||||
BIN
public/images/PembrokeWelshCorgi_hero.jpg
Normal file
BIN
public/images/PembrokeWelshCorgi_hero.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
BIN
public/images/o-CORGI-ROCK-TURTLE-facebook.jpg
Normal file
BIN
public/images/o-CORGI-ROCK-TURTLE-facebook.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 385 KiB |
BIN
public/images/o-CORGI-facebook.jpg
Normal file
BIN
public/images/o-CORGI-facebook.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 173 KiB |
19
readme.md
Normal file
19
readme.md
Normal 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
9
views/index.erb
Normal 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>
|
||||
Reference in a new issue