{"id":16726869,"url":"https://github.com/tpitale/simplest_view","last_synced_at":"2025-03-21T21:31:06.596Z","repository":{"id":6750428,"uuid":"7996846","full_name":"tpitale/simplest_view","owner":"tpitale","description":"SimplestView gives us the power to split Rails Views out from our Templates","archived":false,"fork":false,"pushed_at":"2015-11-03T15:02:32.000Z","size":283,"stargazers_count":41,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T05:13:06.880Z","etag":null,"topics":["actionview","erb","rails","ruby","templates"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tpitale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-03T21:23:13.000Z","updated_at":"2020-04-14T19:47:21.000Z","dependencies_parsed_at":"2022-09-13T20:11:02.957Z","dependency_job_id":null,"html_url":"https://github.com/tpitale/simplest_view","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fsimplest_view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fsimplest_view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fsimplest_view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fsimplest_view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpitale","download_url":"https://codeload.github.com/tpitale/simplest_view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874154,"owners_count":20524576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actionview","erb","rails","ruby","templates"],"created_at":"2024-10-12T22:54:46.756Z","updated_at":"2025-03-21T21:31:06.198Z","avatar_url":"https://github.com/tpitale.png","language":"Ruby","readme":"# SimplestView\n\nSimplestView 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.\n\nThis is accomplished by replacing the *anonymous* class that inherits from ActionView::Base with your own view class.\nThis view class becomes the context within your existing Rails Templates.\n\n[![Build Status](https://travis-ci.org/tpitale/simplest_view.png?branch=master)](https://travis-ci.org/tpitale/simplest_view)\n[![Code Climate](https://codeclimate.com/github/tpitale/simplest_view.png)](https://codeclimate.com/github/tpitale/simplest_view)\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'simplest_view'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install simplest_view\n\n## Usage\n\n1. Inside of your `ApplicationController` or a specific controller: `include SimplestView`\n2. Inside of any Mailers you have (inherited from ActionMailer::Base): `include SimplestView`\n3. `mv app/views app/templates`\n4. mkdir app/views\n5. append `app/views` to the Rails `autoload_paths` inside of `application.rb`\n\n### To Add a View ###\n\nInside of `app/views`, create directories for your controllers. Within each controller directory, create a view to match the actions in your controller.\n\nFor 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.\n\nThen, create your view by inheriting from ActionView::Base:\n\n```ruby\nclass Posts::IndexView \u003c ActionView::Base\nend\n```\n\nAny methods defined within will be accessible from your matching templates at app/templates/posts/index.html.erb, etc.\n\n_NOTE: If you do not create a view class, the default rails behavior will continue to work as always!_\n\n### Handling `new` \u0026 `create` ###\n\nIf you have a `new` action in the `PostsController`, like so:\n\n```ruby\ndef new\nend\n```\n\nThis will implicitly render the `app/templates/posts/new.html.erb` template, and will look for the view inside `app/views/posts/new_view.rb`.\n\nIf you also have a `create` action:\n\n```ruby\ndef create\n  if post.save\n    redirect_to ...\n  else\n    render :new\n  end\nend\n```\n\nWhen 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`.\n\nIf the views are exactly the same, I have simply made the constants equal, like so: `Posts::CreateView = Posts::NewView`.\n\nThis will apply to any template and view that you render from another action. Another common example is `edit`/`update`.\n\n## TODO\n\n1. figure out how to test the integration with rails\n2. generate to move new template generation into app/templates, and to generate view clases as needed.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpitale%2Fsimplest_view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpitale%2Fsimplest_view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpitale%2Fsimplest_view/lists"}