<commit_before># SimplestView

SimplestView splits up views and templates in a Rails 3 application to make it easier to improve the code quality therein.
This happens by replacing the anonymous class that inherits from ActionView::Base with your own view class.
This view class becomes the context within your existing rails templates.

[![Build Status](https://travis-ci.org/tpitale/simplest_view.png?branch=master)](https://travis-ci.org/tpitale/simplest_view)
[![Code Climate](https://codeclimate.com/github/tpitale/simplest_view.png)](https://codeclimate.com/github/tpitale/simplest_view)


## Installation

Add this line to your application's Gemfile:

    gem 'simplest_view'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install simplest_view

## Usage

1. Inside of your `ApplicationController` or a specific controller: `include SimplestView`
2. Inside of any Mailers you have (inherited from ActionMailer::Base): `include SimplestView`
3. `mv app/views app/templates`
4. mkdir app/views
5. append `app/views` to the Rails `autoload_paths` inside of `application.rb`

### To Add a View ###

Inside of `app/views`, create directories for your controllers. Within each controller directory, create a view to match the actions in your controller.

For a controller named PostsController with actions :index, :show, :edit you could create app/views/posts/index_view.rb, app/views/posts/show_view.rb, app/views/posts/edit_view.rb respectively.

Then, create your view by inheriting from ActionView::Base:

```
class Posts::IndexView < ActionView::Base
end
```

Any methods defined within will be accessible from your matching templates at app/templates/posts/index.html.erb, etc.

_NOTE: If you do not create a view class, the default rails behavior will continue to work as always!_

### Handling `new` & `create` ###

If you have a `new` action in the `PostsController`, like so:

```
def new
end
```

This will implicitly render the `app/templates/posts/new.html.erb` template, and will look for the view inside `app/views/posts/new_view.rb`.

If you also have a `create` action:

```
def create
  if post.save
    redirect_to ...
  else
    render :new
  end
end
```

When this attempts to render the `new` template, it will _not_ try to look for a view inside `app/views/posts/new_view.rb` because we are only rendering the `new` template, but we are inside of the `create` action still. Put your view inside of `app/views/posts/create_view.rb`.

If the views are exactly the same, I have simply made the constants equal, like so: `Posts::CreateView = Posts::NewView`.

This will apply to any template and view that you render from another action. Another common example is `edit`/`update`.<commit_msg>add GitHub Flavored Markdown to README<commit_after># SimplestView

SimplestView splits up views and templates in a Rails 3 application to make it easier to improve the code quality therein.
This happens by replacing the anonymous class that inherits from ActionView::Base with your own view class.
This view class becomes the context within your existing rails templates.

[![Build Status](https://travis-ci.org/tpitale/simplest_view.png?branch=master)](https://travis-ci.org/tpitale/simplest_view)
[![Code Climate](https://codeclimate.com/github/tpitale/simplest_view.png)](https://codeclimate.com/github/tpitale/simplest_view)


## Installation

Add this line to your application's Gemfile:

```ruby
gem 'simplest_view'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install simplest_view

## Usage

1. Inside of your `ApplicationController` or a specific controller: `include SimplestView`
2. Inside of any Mailers you have (inherited from ActionMailer::Base): `include SimplestView`
3. `mv app/views app/templates`
4. mkdir app/views
5. append `app/views` to the Rails `autoload_paths` inside of `application.rb`

### To Add a View ###

Inside of `app/views`, create directories for your controllers. Within each controller directory, create a view to match the actions in your controller.

For a controller named PostsController with actions :index, :show, :edit you could create app/views/posts/index_view.rb, app/views/posts/show_view.rb, app/views/posts/edit_view.rb respectively.

Then, create your view by inheriting from ActionView::Base:

```ruby
class Posts::IndexView < ActionView::Base
end
```

Any methods defined within will be accessible from your matching templates at app/templates/posts/index.html.erb, etc.

_NOTE: If you do not create a view class, the default rails behavior will continue to work as always!_

### Handling `new` & `create` ###

If you have a `new` action in the `PostsController`, like so:

```ruby
def new
end
```

This will implicitly render the `app/templates/posts/new.html.erb` template, and will look for the view inside `app/views/posts/new_view.rb`.

If you also have a `create` action:

```ruby
def create
  if post.save
    redirect_to ...
  else
    render :new
  end
end
```

When this attempts to render the `new` template, it will _not_ try to look for a view inside `app/views/posts/new_view.rb` because we are only rendering the `new` template, but we are inside of the `create` action still. Put your view inside of `app/views/posts/create_view.rb`.

If the views are exactly the same, I have simply made the constants equal, like so: `Posts::CreateView = Posts::NewView`.

This will apply to any template and view that you render from another action. Another common example is `edit`/`update`.
{'fraction_non_alphanumeric': 0.09204566044573292, 'fraction_numerical': 0.0021743069396629824, 'mean_word_length': 4.575757575757576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1476764', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1577, 'n_words': 674}