Git Product home page Git Product logo

railslite's Introduction

#Rails Lite

Rails Lite is a web server MVC framework inspired by the functionality of Ruby on Rails.

##Features

###Server

A simple server is implemented using the Rack module.

app = Proc.new do |env|
  req = Rack::Request.new(env)
  res = Rack::Response.new
  MyController.new(req, res).go
  res.finish
end

Rack::Server.start(
  app: app,
  Port: 3000
)

###ControllerBase

ControllerBase has similar functionality to Rails' ActiveController::Base. The ControllerBase class initializes with request and response objects as arguments. Similarly to ActiveController::Base, it has render and redirect_to methods. The render function utilizes the uncommonly used binding method to capture the instance variables used in the template that belong to the controller class.

def render(template_name)
  controller_name = self.class.name.underscore
  path = "views/#{controller_name}/#{template_name.to_s}.html.erb"

  template = File.read(path)
  erb_template = ERB.new(template).result(binding)

  render_content(erb_template, 'text/html')
end

A Session class was also developed so that a cookie could be attached to the response and stored on the client's browser. Rack's set_cookie method was used for this.

#session.rb

def store_session(res)
  res.set_cookie('_rails_lite_app', {path: "/", value: @data.to_json} )
end

###Router

The Router class finds and invokes the appropriate controller action by matching the request's URL path (/users/17) and method (GET, POST, etc.) to a Route's URL pattern and HTTP method, respectively. The route also sends params to the controller class.

#router.rb

def matches?(req)
  @pattern =~ req.path && @http_method.to_s.upcase == req.request_method
end

##Todo

  • Integrate a version of ActiveRecord

railslite's People

Contributors

davidnoah avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

resilientred

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.