Giter Club home page Giter Club logo

amberframework / amber Goto Github PK

View Code? Open in Web Editor NEW
2.5K 72.0 204.0 2.22 MB

A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance.

Home Page: https://amberframework.org

License: MIT License

Crystal 87.51% HTML 10.29% JavaScript 1.85% Makefile 0.17% Dockerfile 0.10% Shell 0.06% CSS 0.02%
crystal web cohesive efficient fast framework amber amber-framework scaffolding cli

amber's Introduction

amber

Productivity. Performance. Happiness.

Amber makes building web applications fast, simple, and enjoyable - with fewer bugs and blazing fast performance.

Build Status Version License

Liberapay patrons

Welcome to Amber

Amber is a web application framework written in Crystal inspired by Kemal, Rails, Phoenix and other popular application frameworks.

The purpose of Amber is not to create yet another framework, but to take advantage of the beautiful Crystal language capabilities and provide engineers and the Crystal community with an efficient, cohesive, well maintained web framework that embraces the language philosophies, conventions, and guidelines.

Amber borrows concepts that have already been battle tested and successful, and embraces new concepts through team and community collaboration and analysis, which also aligns with Crystal's philosophy.

Community

Questions? Join our Discord.

Guidelines? We have adopted the Contributor Covenant to be our CODE OF CONDUCT for Amber.

Our Philosophy? Read Amber Philosophy H.R.T.

Documentation

Read Amber documentation on https://docs.amberframework.org/amber

Benchmarks

Techempower Framework Benchmarks - Round 18 (2019-07-09)

  • Filtered by Full Stack, Full ORM, Mysql or Pg for comparing similar frameworks.

Installation & Usage

Homebrew (macOS/Linux)

brew install amber

Linux

Currently, the only option to install on Linux is from source. At the time of this writing, v1.4.1 is the current stable release, but you should use the most recent tag in place of that.

sudo apt-get install libreadline-dev libsqlite3-dev libpq-dev libmysqlclient-dev libssl-dev libyaml-dev libpcre3-dev libevent-dev
git clone https://github.com/amberframework/amber.git
cd amber
git checkout v1.4.1
shards install
make
sudo make install

If you're using ArchLinux or similar distro try:

yay -S amber

Common

To compile a local bin/amber per project use shards build amber

To use it as dependency, add this to your application's shard.yml:

dependencies:
  amber:
    github: amberframework/amber

Read Amber quick start guide

Read Amber CLI commands usage

Read more about Amber CLI installation guide

Have an Amber-based Project?

Use Amber badge

Amber Framework

[![Amber Framework](https://img.shields.io/badge/using-amber_framework-orange.svg)](https://amberframework.org/)

Release Checklist

  • Test and release all dependencies
  • Test everything locally
  • Run crelease 0.36.0
  • repoint amber to master branch in src/amber/cli/templates/app/shard.yml.ecr template
  • update release notes
  • update homebrew version and sha
  • update linux repositories
  • build and deploy docker image:
    • verify Dockerfile is using the latest crystal version
    • docker login
    • docker build -t amberframework/amber:0.36.0
    • docker push amberframework/amber:0.36.0

Contributing

Contributing to Amber can be a rewarding way to learn, teach, and build experience in just about any skill you can imagine. You don’t have to become a lifelong contributor to enjoy participating in Amber.

Tracking issues? Check our project board.

Code Triage? Join us on codetriage.

Open Source Contributors

Amber is a community effort and we want You to be part of it. Join Amber Community!

  1. Fork it https://github.com/amberframework/amber/fork
  2. Create your feature branch git checkout -b my-new-feature
  3. Write and execute specs and formatting checks ./bin/amber_spec
  4. Commit your changes git commit -am 'Add some feature'
  5. Push to the branch git push origin my-new-feature
  6. Create a new Pull Request

Contributors

See more Amber contributors

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

amber's People

Contributors

alex-min avatar anamba avatar andilavera avatar ashishbista avatar bcardiff avatar c910335 avatar chenrui333 avatar crimson-knight avatar damianham avatar docelic avatar drujensen avatar dwightwatson avatar eliasjpr avatar elorest avatar epergo avatar faustinoaq avatar fridgerator avatar gabrielengel avatar hugopl avatar infernalmaster avatar jackturnbull avatar marksiemers avatar mixflame avatar papilip avatar pynixwang avatar robacarp avatar shobhitic avatar sija avatar veelenga avatar westonganger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amber's Issues

Helpers

Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of the need to handle form control naming and its numerous attributes.

* HTML 5
* **Routing** generate route methods, redirect, have these methods available in views and controllers 
* **Forms**
* **Assets**
* Links
* Markup Escape
* Numbers
* Custom Helpers

Optimize Session Cookie Store

As a developer I want to be able to specify when to sign or encrypt cookies for session store.

Acceptance Criteria:

  • Sets a signed cookie, which prevents users from tampering with its value.
  • Sets an encrypted cookie value before sending it to the client which prevent users from reading and tampering with its value.

Mailers

As a Developer I want to deliver a mail message, by rendering one or more templates.

Acceptance Criteria:

  • Send and receive email within the framework.
  • Generate and edit an Mailer class and mailer view.
  • Configure Action Mailer for my environment.
  • Be able to test your Action Mailer classes.

Fix Example demo site.

Currently the example demo site is not working due to the changes that we have been making to the framework.

Folder Conventions

* **Amber::Router** all related router components
* **Amber::Validations** all related validations params and model validations
* **Amber::Views** all view related components and interfaces
* **Amber::Helpers **framework** **helper methods such as form helpers, view helpers
* **Amber::Utils **
* **Amber::Extensions**
* **Amber::DSL**
* **Amber::Controllers** 
* **Amber::WebSockets **

Route Scopes

Scopes are a way to group routes under a common path prefix and scoped set of plug middleware. We might want to do this for admin functionality, APIs, and especially for versioned APIs. Let's say we have user generated reviews on a site, and that those reviews first need to be approved by an admin. The semantics of these resources are quite different, and they might not share the same controller. Scopes enable us to segregate these routes.

Wrong amber version number displayed in log messages

When launching a new application, the log message shows version 0.1.4 but it should be running version 0.1.17

web_1      | I, [2017-07-16 15:18:00 +0000 #752]  INFO -- : [Amber 0.1.4] serving application "Blog web application." at http://0.0.0.0:3000

Helpers

As a developer I want to add modules and methods to enrich views with a collection of useful features. i.e (csrf_tag, checkbox_field, etc)

Acceptance Criteria:

  • Isolate and Abstract additional functionality into modules and make them available using include language keyword.
  • Wrap views with presenters to abstract functionality

Request Forgery Protection

Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user's knowledge or permission.

The first step to avoid this is to make sure all "destructive" actions (create, update and destroy) can only be accessed with non-GET requests. If you're following RESTful conventions you're already doing this. However, a malicious site can still send a non-GET request to your site quite easily, and that's where the request forgery protection comes in. As the name says, it protects from forged requests.

Controller Actions Params Validation

  • Parameters are taken from the context env and passed as an argument to #call. They are similar to a Ruby Hash, but they offer an expanded set of features.

  • Whitelisting and Validations

  • params do
    required(:name).filled(:str?)
    required(:email).filled(:str?, format?: /@/).confirmation
    required(:password).filled(:str?).confirmation
    required(:terms_of_service).filled(:bool?)
    required(:age).filled(:int?, included_in?: 18..99)
    optional(:avatar).filled(size?: 1..(MEGABYTE * 3))
    end

Routes Resources

The router supports other macros besides those for HTTP verbs like get, post, and put. The most important among them is resources, which expands out to eight clauses of the match/3 function.

GET /users UserController :index
GET /users/:id/edit UserController :edit
GET /users/new UserController :new
GET /users/:id UserController :show
POST /users UserController :create
PATCH /users/:id UserController :update
PUT /users/:id UserController :update
DELETE /users/:id UserController :delete

Controller/View Flash

The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for passing error messages etc.

Add caching to static handler.

Change static handler to cache static assets or perhaps even compile them in. Currently static asset delivery is orders of magnitude slower than slang/ecr rendering.

Websockets pub/sub

The user should have the ability to publish (and subscribe) all messages to a pub/sub service like Redis (or postgres). This will allow for sockets on multiple servers scaled in parallel to still communicate with each other.

Acceptance Criteria:

  • Socket messages should be published to a pubsub service
  • Amber servers should subscribe to pubsub service, and broadcast messages to sockets

Load application controller before any other controller

Hello,

I add a problem when generating a controller with a name that comes before "application_controller.cr".
The default loader could be like

class ApplicationController < Amber::Controller::Base
  LAYOUT = "application.slang"
end

require "./**"

and in the init could be

require "amber"
require "./controllers/application_controller"
# ...

What do you think ?

Fix Static Handler

In crystal 0.23 adds a new argument to the static handler called directory_listing, currently, this argument is not being instantiated in the existing handler causing it to break Amber static sites.

Acceptance Criteria

  • - Add and initialize directory listing
  • - Default directory listing to false
  • - Add specs.

Serving static files

As a Developer I want to serve static files.

Acceptance Criteria:

  • [] Define static pipeline to render static files.
  • [] Be able to serve an html file with static content

[I18n] Support for Internationalization

As a Developer I want to abstract all strings and other locale specific bits (such as date or currency formats) out of the application

Acceptance Criteria:

  • Ensure you have support for i18n.
  • Setup where to find locale dictionaries.
  • Setup how to set, preserve and switch locales.

[Pipes] HTTP Caching

We refer to HTTP caching as the set of techniques for HTTP 1.1 and implemented by browser vendors in order to make faster interactions with the server. There are a few headers that, if sent, will enable these HTTP caching mechanisms.

html, json, text, xml controller helper methods

The html, json, text and xml helpers simplify setting the response headers.

Tasks:

Acceptance Criteria:

  • The ability to use templates to render text, xml, html, json
  • The proper content-type and response code is set

Controller Session Variable

The application must have a session for each user in which you can store small amounts of data that will be persisted between requests. The session is only available in the controller and the view and can use one of a number of different storage mechanisms

WebSockets

Web-sockets are based on a simple idea - sending and receiving messages. Senders broadcast messages about topics. Receivers subscribe to topics so that they can get those messages. Senders and receivers can switch roles on the same topic at any time.

[Suggestion] Use full class name in routes, instead of symbol

The current route definition get "/", :hello, :index, :api is a little unreadable with 3 symbols in a row, and is not immediately obvious what each symbol does.

Using the full class name, in my opinion, makes the route more readable and obvious what the route is doing:
get "/", HelloController, :index, :api

Websockets heartbeat

"heartbeat" prevents stale connections from being kept on the server. Also notifies connected clients if the server becomes unreachable.

Acceptance Criteria:

server

  • Server should send periodic ping frames should be sent out by the server.
  • Clients that quit responding to pings (with pong) frame, should be removed from the connections list
  • Exceptions when sending messages should be caught, and inactive connections removed

client

  • Clients should send periodic ping frames.
  • Clients should try to reconnect if the server stops responding to pings

Get All Available Routes for App

As a developer I would like to know all the available routes define in my application

Acceptance Criteria:

  • Have a hash with the routes resources and the route class.

route resources fail if all actions don't exist in controller.

If I create resourceful routes like:

resources "posts", PostController, [:index, :show]

It errors on compile because all the other actions don't exist in my controller. This happens because the if in the following code happens at run time but the macro that creates the route happens at compile time.

    macro resources(path, controller, actions = [:index, :edit, :new, :show, :create, :update, :put, :delete])
      get "{{path.id}}", {{controller}}, :index if {{actions}}.includes?(:index)
      get "{{path.id}}/:id/edit", {{controller}}, :edit  if {{actions}}.includes?(:edit)
      get "{{path.id}}/new", {{controller}}, :new if {{actions}}.includes?(:new)
      get "{{path.id}}/:id", {{controller}}, :show if {{actions}}.includes?(:show)
      post "{{path.id}}", {{controller}}, :create if {{actions}}.includes?(:create)
      patch "{{path.id}}/:id", {{controller}}, :update if {{actions}}.includes?(:update)
      put "{{path.id}}/:id", {{controller}}, :update if {{actions}}.includes?(:update)
      delete "{{path.id}}/:id", {{controller}}, :delete if {{actions}}.includes?(:delete)
    end

The fix would probably be to check if actions include the right thing at compile time in the macro before creating the route. Like this:

{% if actions.includes?(:index) %}
get "{{path.id}}", {{controller}}, :index
{% end %}

I can send a PR on this unless there's a specific reason the code is written that way.

Environment **Hot reloading

The idea behind hot reloading is to keep the app running and to inject new versions of the files that you edited at runtime. This way, you don't lose any of your state which is especially useful if you are tweaking the UI.

App doesn't compile the same on Linux as it does on OS X

Prerequisites

Description

App compiles and runs perfectly fine on OS X El Capitan 10.11.4

Yet on Linux (tried Debian 8 and Linux Mint) I get:

Error in lib/amber/src/amber/router/pipe/static.cr:15: this 'initialize' doesn't initialize instance variable '@directory_listing' of HTTP::StaticFileHandler,
                  with Amber::Pipe::Static < HTTP::StaticFileHandler, rendering it nilable

I tried but I can't solve this error. Is this a Crystal compiler bug?

Steps to Reproduce

  1. Write an Amber app
  2. Compile and run it on OS X with 0.23.0
  3. Try compiling it on Debian 8 64-bit with latest Crystal

Expected behavior: App should compile and run like on OS X.

Actual behavior: amber w, amber r, and crystal run src/myapp.cr won't work.

Reproduces how often: 100%

Versions

Amber CMD (ambercr.io) - v0.1.15

Darwin Jonathans-MacBook-Pro-2.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64

Linux mixflame 4.9.15-x86_64-linode81 #1 SMP Fri Mar 17 09:47:36 EDT 2017 x86_64 GNU/Linux

Crystal 0.23.0 [3c3d3e2] (2017-06-28) LLVM 3.8.1

Accessing Cookies in Controller

Your application can store small amounts of data on the client - called cookies - that will be persisted across requests and even sessions.

colorize(:yellow) actually a bad idea for app.env

This line in config/application.cr

app.env = (ENV["AMBER_ENV"] ||= "development").colorize(:yellow).to_s

should be changed to

app.env = (ENV["AMBER_ENV"] ||= "development").to_s

otherwise Amber.server.instance will contain, for example "\e[33mproduction\e[0m" as the app.env instead of "production"

Thanks πŸ• πŸ’Ž

Rendering Layouts and views

Views are objects that's responsible for rendering a template. Views also provide functions which takes raw data and make it easier for templates to consume. If you are familiar with decorators or the facade pattern, this is similar.

Controller Filters

Controller Filters are reusable modules that lives within the controller layer and the sole purpose is to validate and transform request/response data. Filters are useful for validating controller action, transforming controller actions the difference between a Pipe and a Filter is that a filter acts on a specific context such as the request, response, session, headers etc., while a Pipe action on the connection lifecycle.

Too many open files, crash when serving static files.

When running a stress test against the example hello world app I got it to crash when trying to hit /index.html

wrk -d 20 -t 4 -c 1015 http://0.0.0.0:4000/index.html

Params: =index.html
accept: Too many open files (Errno)
0x10defddc5: *CallStack::new:CallStack at ??
0x10df00a6e: *raise<Errno>:NoReturn at ??
0x10dfbb065: *Amber::Server#start:Nil at ??
0x10defbfa2: __crystal_main at ??
0x10df24bdb: main at ??

I'm thinking it could be an open file descriptor issue or something else, but I'll look into see if its a crystal-lang bug or something that we can tackle.
Possibly related - crystal-lang/crystal#780

Routing

Pipes Is a series composable transformations thru out the connection lifecycle. We interact with pipes at every step of the connection lifecycle, and the core Amber components like Endpoints, Routers, and Controllers are all just Pipes internally. The basic idea of a Pipe is to unify the concept of a "connection" that we operate on. This differs from other HTTP middleware layers such as Rack, where the request and response are separated in the middleware stack.

AmberCLI

Generators for action, routes, html views, json views, models, migrations,
start and end server
run tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.