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

Lists

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) instead

This 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.1

dependencies:
amatista:
github: werner/amatista
```

### Basic Usage

```crystal
require "amatista"

class HelloWorldController < Amatista::Controller
get "/" do
html = %(

Hello World

)
respond_to(:html, html)
end
end

class Main < Amatista::Base
configure do |conf|
conf[:secret_key] = "secret"
end
end

app = Main.new

app.run 3000
```

### Callbacks
```crystal

class 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
end

class LayoutView < Amatista::BaseView
def initialize(@include)
end

set_ecr "layout"
end

class IndexView < Amatista::BaseView
def initialize(@tasks)
end

def tasks_count
@tasks.count
end

set_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