Coder Social home page Coder Social 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 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

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.

AmberCLI

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

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.

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.

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.

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

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 ๐Ÿ• ๐Ÿ’Ž

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.

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/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.

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

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

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 **

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

Fix Example demo site.

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

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.

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

[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

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

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.

[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.

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

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

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.

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.

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 ?

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.

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.

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

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

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.

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

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.

[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.

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

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.