rails-views 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +101 -12
- data/lib/rails/view.rb +17 -0
- data/lib/rails/views.rb +2 -0
- data/lib/rails/views/version.rb +1 -1
- data/rails-views.gemspec +7 -11
- metadata +48 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43d95d67a1de149edea1976ccfa7b7ea92d07536
|
4
|
+
data.tar.gz: f1451d23405a5c7f3ed13dbb81e2be8f75a290a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465fd157e02dd032305a8de09724b0473b699698ab863710b541263cabb80db1787ee21ae19ab5352b4422b427d595a051332d3597b43e7923da4936895014b7
|
7
|
+
data.tar.gz: 1a2a284a8bbab8ce663b77bac9a70283411f1e4df96bbda9c785c5f1cf63ff46ceb02c9f48c5aac62c5833750c174999deea66d7b68a6d53882c158dd437fdfe
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,127 @@
|
|
1
|
-
#
|
1
|
+
# Rails::Views
|
2
2
|
|
3
|
-
|
3
|
+
*View Components for Ruby and Rails.*
|
4
4
|
|
5
|
-
|
5
|
+
The gem provides view models for Ruby web applications. View models are plain objects that represent a part of the web page. View models can also render views, and be nested.
|
6
|
+
|
7
|
+
This gem bases on [cells](https://github.com/trailblazer/cells).
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
10
12
|
|
11
13
|
```ruby
|
12
|
-
gem '
|
14
|
+
gem 'rails-views'
|
13
15
|
```
|
14
16
|
|
15
17
|
And then execute:
|
16
18
|
|
17
19
|
$ bundle
|
18
20
|
|
19
|
-
|
21
|
+
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
This gem bases on [cells](https://github.com/trailblazer/cells), but includes only `Concept` logic.
|
22
24
|
|
23
|
-
|
25
|
+
A view is a light-weight class with `show.slim` temlate with base view logic.
|
24
26
|
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
class Comment::Cell < Rails::View
|
26
29
|
|
27
|
-
|
30
|
+
private
|
28
31
|
|
29
|
-
|
32
|
+
property :body, :author
|
30
33
|
|
31
|
-
|
34
|
+
def author_link
|
35
|
+
link_to "#{author.email}", author
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Rendering
|
41
|
+
|
42
|
+
Gem provides logic for rendering cells instead of ActionView templates.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
def CommentsController < ApplicationController
|
46
|
+
def index
|
47
|
+
render cell: true # will render Comments::Cell
|
48
|
+
end
|
49
|
+
|
50
|
+
def show
|
51
|
+
@comment = Comment.find(params[:id])
|
52
|
+
render cell: :show, model: @comment # will render Comments::Show::Cell with @comment as model
|
53
|
+
end
|
54
|
+
|
55
|
+
def new
|
56
|
+
@comment = Comment.new
|
57
|
+
@user = User.find(params[:user_id])
|
58
|
+
render cell: 'user/comment', model: @comment, options: {user: @user} # will render User::Comment::Cell with @comment as model and user options
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Helpers
|
64
|
+
|
65
|
+
Also gem provides new helpers for rails.
|
66
|
+
|
67
|
+
### Flash
|
68
|
+
|
69
|
+
Provide method for working with flash.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
= flash[:notice]
|
73
|
+
```
|
74
|
+
|
75
|
+
### Render partials array
|
76
|
+
|
77
|
+
Method `render_each_and_join` can render array of templates and join it in one string.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class User::Info::Cell < Rails::View
|
81
|
+
private
|
82
|
+
|
83
|
+
def parts_of_info
|
84
|
+
%w(contact_information about jobs transactions_list)
|
85
|
+
end
|
86
|
+
|
87
|
+
def info_body
|
88
|
+
render_each_and_join(parts_of_info)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class User::ShortInfo::Cell < User::Info::Cell
|
93
|
+
private
|
94
|
+
|
95
|
+
def parts_of_info
|
96
|
+
%w(contact_information about)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
### Options
|
102
|
+
|
103
|
+
Provide `options` reader. You can have automatic readers to the options's fields by using `::option`
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
class User::Comment::Cell < Rails::View
|
107
|
+
private
|
108
|
+
options :user # delegate to options[:user]
|
109
|
+
|
110
|
+
delegate :email, to: :user, prefix: true
|
111
|
+
end
|
112
|
+
```
|
32
113
|
|
33
114
|
## Contributing
|
34
115
|
|
35
|
-
|
116
|
+
1. Fork it
|
117
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
118
|
+
3. Run the test suite and check the output (`rake`)
|
119
|
+
4. Add tests for your feature or fix (please)
|
120
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
121
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
122
|
+
7. Create new Pull Request
|
123
|
+
|
124
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/datarockets/rails-views
|
36
125
|
|
37
126
|
|
38
127
|
## License
|
data/lib/rails/view.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rails
|
2
|
+
class View < Cell::Concept
|
3
|
+
include ::Cell::Slim
|
4
|
+
include ::Cell::Builder
|
5
|
+
include ::Rails.application.routes.url_helpers
|
6
|
+
include Rails::Views::ViewHelpers
|
7
|
+
|
8
|
+
include ActionView::Helpers
|
9
|
+
include AbstractController::Helpers
|
10
|
+
include ActionDispatch::Http::Cache::Request
|
11
|
+
include ActionView::RecordIdentifier
|
12
|
+
|
13
|
+
def show
|
14
|
+
render
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rails/views.rb
CHANGED
data/lib/rails/views/version.rb
CHANGED
data/rails-views.gemspec
CHANGED
@@ -7,24 +7,20 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'rails-views'
|
8
8
|
spec.version = Rails::Views::VERSION
|
9
9
|
spec.authors = ['Roman Dubrovsky']
|
10
|
-
spec.email = ['
|
10
|
+
spec.email = ['hello@datarockets.com']
|
11
11
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
12
|
+
spec.summary = 'Real view objects for Rails'
|
13
|
+
spec.description = 'Real view objects for Rails'
|
14
14
|
spec.homepage = 'https://github.com/datarockets/rails-views'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
-
# end
|
24
|
-
|
25
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
18
|
spec.require_paths = ['lib']
|
27
19
|
|
20
|
+
spec.add_dependency 'cells'
|
21
|
+
spec.add_dependency 'cells-rails'
|
22
|
+
spec.add_dependency 'cells-slim'
|
23
|
+
|
28
24
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
29
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
30
26
|
spec.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Dubrovsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cells
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cells-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cells-slim
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: bundler
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,9 +122,9 @@ dependencies:
|
|
80
122
|
- - ">="
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
|
-
description:
|
125
|
+
description: Real view objects for Rails
|
84
126
|
email:
|
85
|
-
-
|
127
|
+
- hello@datarockets.com
|
86
128
|
executables: []
|
87
129
|
extensions: []
|
88
130
|
extra_rdoc_files: []
|
@@ -95,6 +137,7 @@ files:
|
|
95
137
|
- Rakefile
|
96
138
|
- bin/console
|
97
139
|
- bin/setup
|
140
|
+
- lib/rails/view.rb
|
98
141
|
- lib/rails/views.rb
|
99
142
|
- lib/rails/views/controller_helpers.rb
|
100
143
|
- lib/rails/views/railtie.rb
|
@@ -124,5 +167,5 @@ rubyforge_project:
|
|
124
167
|
rubygems_version: 2.4.5.1
|
125
168
|
signing_key:
|
126
169
|
specification_version: 4
|
127
|
-
summary:
|
170
|
+
summary: Real view objects for Rails
|
128
171
|
test_files: []
|