simplest_view 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/lib/simplest_view/version.rb +3 -0
- data/lib/simplest_view.rb +38 -0
- data/simplest_view.gemspec +19 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tony Pitale
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# SimplestView
|
2
|
+
|
3
|
+
SimplestView splits up views and templates in a Rails 3 application to make it easier to improve the code quality therein.
|
4
|
+
This happens by replacing the anonymous class that inherits from ActionView::Base with your own view class.
|
5
|
+
This view class becomes the context within your existing rails templates.
|
6
|
+
|
7
|
+
_CAVEAT EMPTOR: Works with rails 3, but lacking specs._
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'simplest_view'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install simplest_view
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
1. Inside of your `ApplicationController` or a specific controller: `include SimplestView`
|
26
|
+
2. `mv app/views app/templates`
|
27
|
+
3. mkdir app/views
|
28
|
+
|
29
|
+
Inside of app/views, created directories for each of your controllers. Within each controller directory, create a view to match the actions in your controller.
|
30
|
+
|
31
|
+
For a controller named PostsController with actions :index, :show, :edit you would create app/views/posts/index_view.rb, app/views/posts/show_view.rb, app/views/posts/edit_view.rb respectively.
|
32
|
+
|
33
|
+
Then, create your view by inheriting from ActionView::Base:
|
34
|
+
|
35
|
+
```
|
36
|
+
class IndexView < ActionView::Base
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Any methods defined within will be accessible from your matching templates at app/templates/posts/index.html.erb, etc.
|
41
|
+
|
42
|
+
_NOTE: If you do not create a view class, the default rails behavior will continue to work as always!_
|
43
|
+
|
44
|
+
## TODO
|
45
|
+
|
46
|
+
1. figure out how to test the integration with rails
|
47
|
+
2. generate to move new template generation into app/templates, and to generate view clases as needed.
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "simplest_view/version"
|
2
|
+
|
3
|
+
module SimplestView
|
4
|
+
def self.included(controller)
|
5
|
+
controller.view_paths = ['app/templates']
|
6
|
+
end
|
7
|
+
|
8
|
+
def view_context_class_name
|
9
|
+
controller = self.class.name.sub(/Controller$/, "").underscore
|
10
|
+
action = action_name + "_view"
|
11
|
+
|
12
|
+
File.join(controller, action).camelize
|
13
|
+
end
|
14
|
+
|
15
|
+
# Rails 3/4
|
16
|
+
def view_context_class
|
17
|
+
begin
|
18
|
+
klass = view_context_class_name.constantize
|
19
|
+
|
20
|
+
routes = respond_to?(:_routes) && _routes
|
21
|
+
helpers = respond_to?(:_helpers) && _helpers
|
22
|
+
|
23
|
+
Class.new(klass) do
|
24
|
+
if routes
|
25
|
+
include routes.url_helpers
|
26
|
+
include routes.mounted_helpers
|
27
|
+
end
|
28
|
+
|
29
|
+
if helpers
|
30
|
+
include helpers
|
31
|
+
end
|
32
|
+
end
|
33
|
+
rescue NameError => e
|
34
|
+
Rails.logger.warn "No View defined for #{klass_name}"
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simplest_view/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "simplest_view"
|
8
|
+
gem.version = SimplestView::VERSION
|
9
|
+
gem.authors = ["Tony Pitale"]
|
10
|
+
gem.email = ["tpitale@gmail.com"]
|
11
|
+
gem.description = %q{SimplestView splits up views and templates in a Rails 3 application to make it easier to improve the code quality therein.}
|
12
|
+
gem.summary = %q{SimplestView splits up views and templates in a Rails 3 application to make it easier to improve the code quality therein.}
|
13
|
+
gem.homepage = "http://github.com/tpitale/simplest_view"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplest_view
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tony Pitale
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: SimplestView splits up views and templates in a Rails 3 application to
|
15
|
+
make it easier to improve the code quality therein.
|
16
|
+
email:
|
17
|
+
- tpitale@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/simplest_view.rb
|
28
|
+
- lib/simplest_view/version.rb
|
29
|
+
- simplest_view.gemspec
|
30
|
+
homepage: http://github.com/tpitale/simplest_view
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.23
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: SimplestView splits up views and templates in a Rails 3 application to make
|
54
|
+
it easier to improve the code quality therein.
|
55
|
+
test_files: []
|