Popularity
2.8
Declining
Activity
0.0
Stable
10
1
2
Programming language: Crystal
License: MIT License
Tags:
Web Frameworks
chocolate alternatives and similar shards
Based on the "Web Frameworks" category.
Alternatively, view chocolate alternatives based on common mentions on social networks and blogs.
-
lucky
A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts. -
amber
A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance. -
runcobo
An api framework with type-safe params, elegant json serializer. Thanks for enjoying it! ๐ป๐ป https://runcobo.github.io/docs/ -
Shivneri
Component based MVC web framework based on fort architecture targeting good code structures, modularity & performance.
InfluxDB โ Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
Promo
www.influxdata.com

Do you think we are missing an alternative of chocolate or a related project?
README
chocolate
Simple web framework and template engine
Installation
Add this to your application's shard.yml
:
dependencies:
chocolate:
github: Grabli66/chocolate
Usage
Need latest crystal compiler to compile some samples.
Hello world
require "chocolate"
include Zephyr
include Chocolate
get "/" do
"Hello, world!"
end
listen {
port 8080
}
Hello with template
require "chocolate"
include Zephyr
include Chocolate
get "/" do
html {
head {
title(text: "Hello world")
}
body {
div(text: "Hello, world!")
}
}
end
listen {
port 8080
}
Hello with view
require "chocolate"
include Zephyr
include Chocolate
class HelloView
def render
html {
head {
title(text: "Hello world")
}
body {
div(text: "Hello, world!")
}
}
end
end
get "/" do
HelloView.new
end
listen {
port 8080
}
Handle params
require "chocolate"
include Zephyr
include Chocolate
get "/registration/success" do
html {
body {
div(css: "result", text: "Success")
}
}
end
get "/blog/:id" do |req|
blog = Database.get_blog(req.params["id"])
blog.to_s
end
post "/registration/singup" do |req|
Database.save_user(req.params["email"], req.params["password"])
redirect("/registration/success")
end
Handle static files
require "chocolate"
include chocolate
include zephyr
listen {
port 8080
static_dir "./static"
}
Handle errors
require "chocolate"
include Zephyr
include Chocolate
on_exception ResourceNotFoundException do
"NOT FOUND"
end
on_exception Exception do
"INTERNAL ERROR"
end
listen {
port 8080
}
JSON response
require "json"
require "chocolate"
include Zephyr
include Chocolate
class Database
def self.get_user(id)
User.new(1, "John", "Doe")
end
end
class User
JSON.mapping({
id: Int32,
name: String,
email: String
})
def initialize(@id, @name, @email)
end
end
get "/user/:id" do |req|
user = Database.get_user(req.params["id"] as String)
json(user)
end
listen {
port 8080
}
View inheritance
require "chocolate"
include Zephyr
include Chocolate
abstract class RootView < View
abstract def render_content
def render
html {
head {
title(text: @title)
}
body {
header {
ul(css: "menu") {
li(text: "Home") {
css_add("active") if @location == :home
}
li(text: "Blog") {
css_add("active") if @location == :blog
}
}
}
include_element(render_content)
}
}
end
end
class HomeView < RootView
def initialize
@title = "Home"
@location = :home
end
def render_content
div(css: "home") {
h1(text: "HOME")
}
end
end
class BlogView < RootView
def initialize
@title = "Blog"
@location = :blog
end
def render_content
div(css: "blog") {
h1(text: "Blog")
}
end
end
get "/" do
HomeView.new
end
get "/blog" do
BlogView.new
end
listen {
port 8080
}
Route group
require "../chocolate/src/**"
include Chocolate
include Zephyr
class SessionNotFoundException < Exception
end
on_exception SessionNotFoundException do
"SESSION NOT FOUND"
end
group do
before do |req|
raise SessionNotFoundException.new unless req.params["session_id"]?
end
get "/user/:id" do |req|
req.params["id"] as String
end
get "/blog/:id" do |req|
req.params["id"] as String
end
end
listen {
port 8080
}
Contributing
- Fork it ( https://github.com/Grabli66/chocolate/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Grabli66 (https://github.com/Grabli66) Grabli66 - creator, maintainer