Code Monkey home page Code Monkey logo

laris's Introduction

Laris

A lightweight MVC framework inspired by Ruby on Rails.

To see it in action, check out my minesweeper game: live โ€ข github

Getting Started

  • gem install laris
  • Put sql files in db/migrations/ numbered in the order you want them to be executed (NB I need to add a rake task for migrating. At the moment you will need to run DBConnection.migrate yourself)
  • Create models in app/models/
# app/models/post.rb

class Post < LarisrecordBase
  belongs_to :author, class_name: "User", foreign_key: :user_id
end
  • Construct routes using a regex, controller name, and method name
# config/routes.rb

ROUTER.draw do
  get Regexp.new("^/users$"), UsersController, :index
  get Regexp.new("^/users/new$"), UsersController, :new
  post Regexp.new("^/users$"), UsersController, :create
  get Regexp.new("^/users/(?<id>\\d+)$"), UsersController, :show
  get Regexp.new("^/users/(?<id>\\d+)/edit$"), UsersController, :edit
  patch Regexp.new("^/users/(?<id>\\d+)$"), UsersController, :update
  delete Regexp.new("^/users/(?<id>\\d+)$"), UsersController, :destroy
end
  • Add controllers in app/controllers/
# app/controllers/users_controller.rb

class UsersController < ControllerBase
  def index
    @users = User.all

    render :index
  end
end
  • Create erb views in app/views/
# app/views/users/index.html.erb

<ul>
  <% @users.each do |user| %>
    <li><%= user.name %></li>
  <% end %>
</ul>
  • Place any assets in app/assets
  • You will need a database URL to run locally (yeah, I have work to do). If you are feeling adventurous, you can use your Heroku database URL, but probably you shouldn't...
export DATABASE_URL=$(heroku config -s | grep DATABASE_URL | sed -e "s/^DATABASE_URL='//" -e "s/'//")
  • Add these to the root of your project:
# laris.ru

require 'laris'
Laris.root = File.expand_path(File.dirname(__FILE__))

require_relative 'config/routes'

run Laris.app
# Procfile

web: bundle exec rackup laris.ru -p $PORT
  • Start up your app with bundle exec rackup laris.ru or push to Heroku
  • You did it!

TODO

  • Database config file
  • Rake task for migrations
  • Migrations in Ruby, not raw SQL
  • laris new

laris's People

Contributors

composerinteralia avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.