Lotus Web Framework

A new framework crossed my radar on HackerNews today called Lotus. It is based on Ruby and attempts to adhere to proper OO principles. It looks simple to learn so I thought I'd give it a try.

I ran into a few issues with the first example in the docs provided in the Github project, so I'll post some fixes. This is running version 0.1.0 of the lotusrb gem.

# config.ru
require 'lotus'

module OneFile
  class Application < Lotus::Application
    configure do
      routes do
        get '/', to: 'home#index'
      end
    end
  end

  module Controllers::Home
    include OneFile::Controller

    action 'Index' do
      def call(params)
      end
    end
  end

  module Views::Home
    class Index
      include OneFile::View

      def render
        'Hello'
      end
    end
  end
end

run OneFile::Application.new

If you paste that into a file called config.ru, you can then run it with rack:

$ cd path/to/project
$ rackup

You will find that there are a few issues with the code above:

  1. OneFile::Controllers does not exist in the object namespace.
  2. OneFile::Controller cannot be included as it does not exist.
  3. OneFile::Views does not exist in the object namespace.
  4. OneFile::View cannot be included as it does not exist.

The simple fix for issues 1 and 3 is to ensure that the modules exist, so we change:

module Controllers::Home
  ...
end

module Views::Home
  ...
end

into

module Controllers
  module Home
    ...
  end
end

module Views
  module Home
    ...
  end
end

and now the modules exist in the Ruby namespace.

For issues 2 and 4, these classes/modules cannot be included because nothing was created for them by Lotus. The proper name for these (in the case of this simple application) is to use the Lotus:: equivalent classes.

Change:

...
include OneFile::Controller

...
include OneFile::View

to:

...
include Lotus::Controller

...
include Lotus::View

and now the classes can be loaded by Ruby.

Now try to load the file again through rack and you'll see that the server starts successfully on port 9292 (default). Open up your web browser to http://localhost:9292 and it will print "hello".

Onward to learning more Lotus!