All Projects → tpitale → simplest_view

tpitale / simplest_view

Licence: MIT license
SimplestView gives us the power to split Rails Views out from our Templates

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to simplest view

ProvToolbox
Java library to create and convert W3C PROV data model representations
Stars: ✭ 62 (+51.22%)
Mutual labels:  templates
qd-templates
基于开源新版签到框架站发布的公共har模板库,整理自用 qiandao 框架可用的各种网站和App的 Har 模板,仅供学习参考。
Stars: ✭ 77 (+87.8%)
Mutual labels:  templates
flutter getx template
🍻🍀 This is source base for getx flutter. Optimize by lambiengcode
Stars: ✭ 43 (+4.88%)
Mutual labels:  templates
Static-Sort
A simple C++ header-only library for fastest sorting of small arrays. Generates sorting networks on compile time via templates.
Stars: ✭ 30 (-26.83%)
Mutual labels:  templates
smart-github
A chrome extension to further upgrade github's template
Stars: ✭ 17 (-58.54%)
Mutual labels:  templates
templates
Collection of Conan recipe + CI templates
Stars: ✭ 71 (+73.17%)
Mutual labels:  templates
macaw
🦜 Scalable email templates for Node.js applications.
Stars: ✭ 24 (-41.46%)
Mutual labels:  templates
pyLODE
An OWL ontology documentation tool using Python and templating, based on LODE
Stars: ✭ 116 (+182.93%)
Mutual labels:  templates
laravel-email-templates
Laravel 5 database driven email templates
Stars: ✭ 23 (-43.9%)
Mutual labels:  templates
embed view
Embed ERB files inside another ERB files for faster performance (5-20% BOOST!!!)
Stars: ✭ 20 (-51.22%)
Mutual labels:  erb
dotfiles
These are my dotfiles. All the config stuff that I use is here.
Stars: ✭ 16 (-60.98%)
Mutual labels:  templates
section-matter
Like front-matter, but allows multiple sections in a single document.
Stars: ✭ 18 (-56.1%)
Mutual labels:  templates
ConvNet-OOP
ConvNet Implementation: An Object Oriented Approach using Keras API.
Stars: ✭ 20 (-51.22%)
Mutual labels:  templates
machine-learning-templates
Template codes and examples for Python machine learning concepts
Stars: ✭ 40 (-2.44%)
Mutual labels:  templates
global-typelist
How to build and maintain a "global" type-list
Stars: ✭ 22 (-46.34%)
Mutual labels:  templates
dotnet-new-nunit
Project is being maintained by the .NET Team now
Stars: ✭ 33 (-19.51%)
Mutual labels:  templates
CPTH
🌟 Competitive Programming Template Headers | With documentation, CI tests and Codecov
Stars: ✭ 23 (-43.9%)
Mutual labels:  templates
zsh-launchpad
🚀 Simple, educational dotfiles template to get started with Zsh and learn about its features
Stars: ✭ 141 (+243.9%)
Mutual labels:  templates
django-apptemplates
Django template loader that allows you to load and override a template from a specific Django application.
Stars: ✭ 43 (+4.88%)
Mutual labels:  templates
hypertag
HTML templates with Python-like concise syntax, code reuse & modularity. The Pythonic way to web templating.
Stars: ✭ 27 (-34.15%)
Mutual labels:  templates

SimplestView

SimplestView splits up Views and Templates (erb/haml/etc) in a Rails 3/4 application to make it easier to improve the code quality of our controllers, and remove code from helper modules.

This is accomplished 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 Code Climate

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.

TODO

  1. figure out how to test the integration with rails
  2. generate to move new template generation into app/templates, and to generate view clases as needed.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].