• Stars
    star
    165
  • Rank 228,906 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An extremely simple web framework.

Busker ๐Ÿšถ๐ŸŽถ

An extremely simple web framework. It's called Busker as a reference to Sinatra. It mimics Sinatra in some aspects while still trying to stay a true wanderer of the streets.

Featured in the German Linux Magazin for some reason O.o

Gem Version Installs security

Design principles ๐Ÿ“ƒ

  • Small code base that is easily understandable, hackable and embeddable
  • No dependencies except what is in the Ruby Standard Lib
  • Backward compatibility to older Ruby versions
  • Ease of use / Some minor resemblance to Sinatra, hence the name
  • It's not meant as a complete web framework but concentrates on the basics

Installation ๐Ÿ’พ

Add this line to your application's Gemfile:

gem 'busker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install busker

Or copy the code into your project ... it's tiny!

Usage ๐Ÿ’ฅ

require 'busker'

Busker::Busker.new do

  # minimal route definition
  route '/' do
    "Busker version: #{Busker::VERSION}"
  end
  
  # respond to multiple HTTP methods, overwrite response content_type
  route '/info', [:GET, :POST, :PUT, :DELETE] do |params, request, response|
    response.content_type = 'text/plain'
    request.inspect
  end

  # usage of URL params, render template with variable
  route '/template', :GET do |params|
    @title = params[:title] || 'no title'
    if params[:external]
      render './template.erb'
    else
      render :template
    end
  end
  
  # render another layout than the default
  route '/alt_layout', :GET do |params|
    render :template, :layout => :another_layout
  end
  
  # usage of dynamic route params
  route '/item/:id' do |params|
    "requested item with id: #{params[:id]}"
  end

  # list all defined routes
  route '/routes', :GET do |params, request, response|
    response.content_type = 'text/plain'
    @_[:routes].keys.map{|k| "#{k[:methods].join('/')} #{k[:path]}"}.join("\n")
  end

  # implicit route definitions
  route :implicit
  route '/implicit/something'

end.start # notice the call to start

# inline templates like in Sinatra
__END__
@@ layout
<header>Header</header>
<%= yield %>
<footer>Footer</footer>

@@ another_layout
<div class="batman"><%= yield %></div>

@@ template
<h1><%= @title %></h1>

@@ /implicit
<h1><%= @params.inspect %></h1>

@@ /implicit/something
<h1><%= @request.inspect %></h1>

Questions โ”

Why not use Sinatra?

Sinatra is about 2000 lines of code (nothing you would directly, as in copy the code, embed in your single-file project) while Busker is less than 50 lines of code. Plus Sinatra depends on Rack and Tilt. Both external Gems while one of Buskers design principles is to only rely on modules that are within the Ruby Standard Library.

This makes it literally small and deployable enough to be used in a tiny single file project. This is great for toy projects, educational purposes, payloads, embedded projects ...

But that all being said, you should probably use Rails or Sinatra for your project.

When shouldn't I use Busker?

I wouldn't consider Busker to be "production ready" by any means. (WEBrick is not the smartest choice for production environments!) It's something to play around and have fun with. I haven't made exhaustive benchmarks or in depths security checks. And I would love to get honest, constructive opinions (considering the design principles).

When should I use Busker?

You find yourself hacking a tiny dirty little web app on your Raspberry Pi and getting annoyed by using only Webrick but not annoyed enough to setup a good Ruby environment and install Sinatra. Or you might have a weird fascination for single file projects that just run with minimal effort. Busker is your best buddy now. Lots of convenience and syntactic sugar for almost no cost.

TODO / Ideas ๐Ÿ’ก

  • More tests! (especially integration tests with Capybara)
  • Improve render method, allow yield etc
  • Improve error handling, honor production/development environment?
  • Auto reload?
  • A fork that doesn't need WEBrick?
  • Anything cool that doesn't break the design principles ...

Contributing ๐Ÿšง

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Don't forget to write- and run tests for your new feature (run rspec)!
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Or just use GitHubs on page editing ... it will do all of the above for you and is reasonable given the size of the source. Make sure to add an explanation though!

More Repositories

1

rinect

pure ruby kinect driver - not a wrapper
Ruby
41
star
2

markdown-converter

convert markdown to html and pdf - with syntax highlighting
CSS
24
star
3

stimmung

Sentiment analysis for the German language
Ruby
20
star
4

js13kgames_2016_glitchcon

A glitchy (that's the theme of the competition) version of Galcon for js13kgames
HTML
17
star
5

jg3d

Pure Java implementation of an interactive 3D graph rendering engine and editor using a spring embedder algorithm. Nice looking sterile real time 3D environment. Feel free to extend this project and build something awesome :D
Java
17
star
6

gameb0x

This project aims to deliver a pleasant casual local multiplayer gaming- and development experience.
JavaScript
17
star
7

spectrum_analyzer

HTML5 Spectrum Analyzer and Tone Generator
JavaScript
16
star
8

mapper

A tiny geo coordinate converter - basically for plotting latitude/longitude pairs to an image
Ruby
14
star
9

picodepen

A tiny frontend only codepen.io inspired code editor with live preview and sharing
HTML
13
star
10

vidup

Tiny Ruby App That Allows Browser Based P2P Video Chatting
Ruby
11
star
11

procedural_plants

Breed procedurally generated plants based on their DNA
HTML
10
star
12

command_line_google_maps

Lets you download, draw on, and display a google map image in your command line. Ya it's hacky...
Ruby
9
star
13

OfficeBlaster

Unite machines and form an army of sound!
Ruby
9
star
14

js_marker_detector

Detects AR Markers in JavaScript
JavaScript
9
star
15

sessg

SimpleExtendableStaticSiteGenerator
JavaScript
7
star
16

rasm

Miniature Assembler-like Language and Interpreter
JavaScript
6
star
17

TinyDBTimestamps

Timestamps Middleware for TinyDB
Python
6
star
18

kasten

Let users draw a Kasten (German for box) in an X environment and get its dimensions
C
5
star
19

jing

A tiny static site generator packing a punch - ้™ๆ€็ฝ‘้กต็”Ÿๆˆๅ™จ
Ruby
5
star
20

git-tasks

Have a SCRUM/KANBAN like task board, based on plain text files, directly in your git repository.
JavaScript
4
star
21

COherent_LIabilities

Displays your coherent liabilities .. everybody has them .. everybody gets f*cked by them once in a while .. stay on top!
Ruby
3
star
22

aw-playground

just a personal test, nothing useful
3
star
23

github_neighbors

visualize your github neighborhood
Ruby
2
star
24

kraken

Decentralised RESTful synchronization service
Ruby
2
star
25

letsencrypt_this

simple letsencrypt client
Ruby
1
star
26

swagchart

Small Wrapper Around Google CHARTS
Ruby
1
star
27

kreachers

A little experiment in genetic algorithms / digital life
Ruby
1
star
28

js-galaxy-conflict

a JS implementation of the famous game galaxy conflict or galcon.
HTML
1
star
29

ESSSE

ESSSE - Embedding Searchable Static Site Example
JavaScript
1
star
30

chirpy

Sending and receiving data via audio because why not?
JavaScript
1
star
31

JingExampleSite

An example site for Jing, the static site generator. Directly deployable to Netlify
HTML
1
star
32

doc-avatar

Tiny web component that shows a unique'ish SVG based doc icon depending on a name. Think identicon/gravatar for doc icons.
HTML
1
star