Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/werner/amatista
Web Framework for Crystal http://crystal-lang.org
https://github.com/werner/amatista
Last synced: about 1 month ago
JSON representation
Web Framework for Crystal http://crystal-lang.org
- Host: GitHub
- URL: https://github.com/werner/amatista
- Owner: werner
- License: mit
- Created: 2015-04-22T14:51:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-17T12:42:52.000Z (almost 7 years ago)
- Last Synced: 2024-02-17T11:35:32.176Z (5 months ago)
- Language: Crystal
- Size: 115 KB
- Stars: 51
- Watchers: 7
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-crystal - Amatista - inspired framework (Web Frameworks)
- awesome-crystal - amatista - A web framework to create quick applications (Web Frameworks)
README
# Amatista [![Build Status](https://travis-ci.org/werner/amatista.png)](https://travis-ci.org/werner/amatista) [![docrystal.org](http://www.docrystal.org/badge.svg?style=round)](http://www.docrystal.org/github.com/werner/amatista)
# Deprecated!.
## you want to use [Kemal](https://github.com/kemalcr/kemal) insteadThis is a web framework build in [Crystal](https://github.com/manastech/crystal) to create quick applications.
### Shard file
shard.yml
```yml
name: myapp
version: 0.0.1dependencies:
amatista:
github: werner/amatista
```### Basic Usage
```crystal
require "amatista"class HelloWorldController < Amatista::Controller
get "/" do
html = %(Hello World
)
respond_to(:html, html)
end
endclass Main < Amatista::Base
configure do |conf|
conf[:secret_key] = "secret"
end
endapp = Main.new
app.run 3000
```### Callbacks
```crystalclass ApplicationController < Amatista::Controller
#It will be a redirection if the condition is fulfilled,
#it should not be a session with a key user_id for the redirect to works
before_filter(condition: -> { !get_session("user_id") }) do
redirect_to("/sessions/new")
end
end
```### View System
```crystal
class HelloWorldController < Amatista::Controller
get "/tasks" do
tasks = Task.all
# You're going to need a LayoutView class as
# a layout for set_view method to work
respond_to(:html, IndexView.new(tasks).set_view)
end
get "/tasks.json" do
tasks = Task.all
respond_to(:json, tasks.to_s.to_json)
end
endclass LayoutView < Amatista::BaseView
def initialize(@include)
endset_ecr "layout"
endclass IndexView < Amatista::BaseView
def initialize(@tasks)
enddef tasks_count
@tasks.count
endset_ecr "index"
end#Views:
#layout.ecr
Todo App
<%= @include %>
#index.ecr
Todo Tasks
<% @tasks.each do |task| %>
<%= check_box_tag(:task, "id#{task[0]}", task[0], task[2], { class: "checkTask" }) %>
<%= label_tag("task_id#{task[0]}", task[1].to_s) %>
<%= link_to("Edit", "/tasks/edit/#{task[0]}", { class: "btn btn-success btn-xs" }) %>
<%= link_to("Delete", "/tasks/delete/#{task[0]}", { class: "del btn btn-danger btn-xs" }) %>
<% end %>
<%= link_to("New Task", "/tasks/new", { class: "btn btn-info btn-xs" } ) %>
<%= label_tag("total", "Total: #{tasks_count}" ) %>
```
##### [Example](https://github.com/werner/todo_crystal)## Contributing
1. Fork it ( https://github.com/werner/amatista/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request