Skip to content

Commit

Permalink
Updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
Catbuntu committed Jul 25, 2013
1 parent 8c3726a commit 97f57b1
Showing 1 changed file with 59 additions and 39 deletions.
98 changes: 59 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ Ruby MVC [![Gem Version](https://badge.fury.io/rb/rmvc.png)](http://badge.fury.i
-------
Ruby MVC (`rmvc`) is a gem to help you use the MVC (Model-View-Controller) architecture in all your Ruby applications. It's not limited to web applications like Rails! In fact, it's like a *Rails without Rack*.

Get RMVC
===
It's an official gem now! If you want the last available gem, run this:

$ gem install rmvc

Depending on your setup, you might have to prefix the command with `sudo`.

If you want the last version and the gem isn't updated (look at the top of the README to know what version the gem is), just download the sources from GitHub:

$ git init
$ git clone https://github.com/unrar/rmvc.git

Now install the gem:

$ gem install rmvc-x.x.x.gem

### Dependencies ###
The only dependency of RMVC is [colorize](https://rubygems.org/gems/colorize). Rubygems should automatically install colorize for you.

Create a project
====
RMVC is made to be friendly to Rails developers. So, as you can guess, the only command you need to run to create
Expand All @@ -24,38 +44,38 @@ It will create a structure like the following:

The file the user will run is `ProjectName.rb`. It has a very simple content.

```ruby
require './app/controllers/default_controller'
DefaultController.main
```
```ruby
require './app/controllers/default_controller'
DefaultController.main
```

The controller, which is the file that, obviously, **controls** everything, contains this by default:

```ruby
require './app/models/default'
require './app/views/main'
class DefaultController
class << self
# Add your variables here!
attr_accessor :name
end
@name = "James!"
def main
MainView.load
end
end
```
```ruby
require './app/models/default'
require './app/views/main'
class DefaultController
class << self
# Add your variables here!
attr_accessor :name
end
@name = "James!"
def main
MainView.load
end
end
```

And the contents of the view:

```ruby
require './app/controllers/default_controller'
class MainView
def load
puts "Hello, hello {#DefaultController.name}!"
end
end
```
```ruby
require './app/controllers/default_controller'
class MainView
def load
puts "Hello, hello {#DefaultController.name}!"
end
end
```

The model is void by default, just a declaration of the class `SomethingModel`.

Expand All @@ -71,16 +91,16 @@ Declaring Variables
===
It's very easy! Just add the variable at the `attr_accessor` statement of your controller:

```ruby
attr_accessor :onevariable, :anothervariable, :myvariable
```
```ruby
attr_accessor :onevariable, :anothervariable, :myvariable
```

And declare it using an instance variable (`@var`) after the `class << self` block.

```ruby
end
@onevariable, @anothervariable, @myvariable = "A", "B", "C"
```
```ruby
end
@onevariable, @anothervariable, @myvariable = "A", "B", "C"
```

This can sound stupid, but it's useful if you want to get data from a database and make it available for all the views under
a controller (MVC rules!).
Expand Down Expand Up @@ -132,17 +152,17 @@ Indeed. You just have to do an extra step that has to be done manually. Not beca

It's as easy as linking to the controller at your main file (if your project is `sudoku`, say `sudoku.rb`).

```ruby
require `./app/controllers/sudokusolver_controller`
```
```ruby
require `./app/controllers/sudokusolver_controller`
```

**Important!** The `./` before *app* is very important, don't ignore it! Also, don't add a `.rb` extension to the file, that's how require wants it!

Now you have access to all the controller, model and view's methods from your main/executable file. But usually all what you want to do is call the `main` method of the controller, so all what you would do is:

```ruby
SudokusolverController.main
```
```ruby
SudokusolverController.main
```

Then add all the desired code under the controller, views and models. And you're done!

Expand Down

0 comments on commit 97f57b1

Please sign in to comment.