Giter Club home page Giter Club logo

mini-rails's Introduction

mini-rails

RubyChina讨论贴:https://ruby-china.org/topics/32764

What is mini-rails?

本想学习一下Rails源码,看看有什么magic;
但源码文件太多,核心代码都淹没在大量细节实现中,全部看完不现实,走马观花又很难领会精髓;
纸上得来终觉浅,眼过千遍,不如手过一遍,干脆重新造个轮子;
于是就有了mini-rails,参照Rails源码,省略细节,实现了一个self-host mvc框架;
再也不用对着庞大的Rails望洋兴叹了,600行代码为您还原一个真实的Rails;

mini-rails实现了从socket到controller的层层封装,并注释了Rails源码中相应模块的位置,可作为学习Rails源码的目录或大纲;

Socket -> WEBrick GenericServer -> WEBrick HTTPServer -> WEBrick HTTPServlet
-> Rack WEBrick -> Rack Handler -> Rack Server
-> Rails Server -> Engine -> Application -> Middleware -> ActionDispatch::Executor
-> MiddlewareStack -> Routing
-> Journey Router -> AbstractController -> Metal -> ActionController::Base

How to run it?

#运行test.rb,打开浏览器:
http://localhost:8081/Home/index        => "hello from Home Index."
http://localhost:8081/User/about        => "hello from User About."
http://localhost:8081/unkown_url        => "404"

How to define a web page?

require_relative 'mini-rails'

#define your controllers and actions
class UserController < ActionController::Base
    def about
        ['200',[],["hello from User About."]]
    end
end

start_server

mini-rails's People

Contributors

xaqi avatar

Watchers

James Cloos avatar

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.