trailblazer-cells 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CHANGES.md +3 -0
- data/Gemfile +4 -0
- data/README.md +97 -0
- data/Rakefile +10 -0
- data/lib/trailblazer/cell.rb +57 -0
- data/lib/trailblazer/cells.rb +2 -0
- data/lib/trailblazer/cells/version.rb +5 -0
- data/trailblazer-cells.gemspec +26 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f74c352ddf9ca8356a47e8221dbe027368bc8e2
|
4
|
+
data.tar.gz: fee008432f153662265edaad10620d5a9e739d68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d762fade172599396e964ac0fe92c8359a6b97c8e02f9d08966e76722ea34fc21d08c56cb45bdee6eb1bcc120f6a13cdbd6c12c2e80650980145140d77cbf586
|
7
|
+
data.tar.gz: be2c4a01b0bcd87b4fa9c1426fd24becf4cac15b2e694cb193625cba04418cd820f2e9333dae0f737ed2ef94ada365b572a8126ce2fa7b7a26c929b905b7faaf
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Trailblazer::Cells
|
2
|
+
|
3
|
+
_Trailblazer's file layout for Cells._
|
4
|
+
|
5
|
+
## View Prefixes
|
6
|
+
|
7
|
+
In Trailblazer, class structures as the following are very common, let's say for a `post` concept, here are the class headers, and where the view directory gets resolved to.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
module Post
|
11
|
+
module Cell
|
12
|
+
class New < Trailblazer::Cell # => app/concepts/post/views
|
13
|
+
class Show < Trailblazer::Cell # => app/concepts/post/views
|
14
|
+
class SideBar < Trailblazer::Cell # => app/concepts/post/views
|
15
|
+
```
|
16
|
+
|
17
|
+
## Automatic `show`
|
18
|
+
|
19
|
+
You don't have to define a `show` method, `Trailblazer::Cell` will have one that looks as follows.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class Trailblazer::Cell
|
23
|
+
def show
|
24
|
+
render
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
## View Name
|
29
|
+
|
30
|
+
When calling `render`, the view name is inferred from the class name.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
module Post
|
34
|
+
module Cell
|
35
|
+
class New < Trailblazer::Cell # => new.erb
|
36
|
+
class Show < Trailblazer::Cell # => show.erb
|
37
|
+
class SideBar < Trailblazer::Cell # => side_bar.erb
|
38
|
+
```
|
39
|
+
|
40
|
+
You can still override using `render view: :name`.
|
41
|
+
|
42
|
+
## Layout
|
43
|
+
|
44
|
+
You can pass a layout cell into every `Trailblazer::Cell` which will render the layout.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Post::Cell::Show.new(post, layout: Gemgem::Cell::Layout).()
|
48
|
+
```
|
49
|
+
|
50
|
+
The `:layout` option has to refer to a cell class. When invoked, the layout cell will receive the content of the actual cell under `:content`, resulting in a call as follows.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Gemgem::Cell::Layout.new(post,
|
54
|
+
content: Post::Cell::Show.new(post)
|
55
|
+
)
|
56
|
+
```
|
57
|
+
|
58
|
+
The layout cell's `show` view can sit in any directory, for example `gemgem/view/layout.rb`.
|
59
|
+
|
60
|
+
```erb
|
61
|
+
<html>
|
62
|
+
Yay, I'm the layout!
|
63
|
+
|
64
|
+
<%= content %>
|
65
|
+
</html>
|
66
|
+
```
|
67
|
+
|
68
|
+
It's up to you what you do with the `:content` option. Here's the Trailblazer way.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
class Gemgem::Cell::Layout < Trailblazer::Cell
|
72
|
+
self.view_paths = ["gemgem"]
|
73
|
+
def content
|
74
|
+
@options[:content]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Cells with layout cells allow replacing a frameworks entire view stack, e.g. `ActionView`.
|
80
|
+
|
81
|
+
## Namespaces
|
82
|
+
|
83
|
+
It works identical with namespaces.
|
84
|
+
|
85
|
+
## View Paths
|
86
|
+
|
87
|
+
Some projects do not use the `app/concept` view path. This can be changed as follows.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Trailblazer::Cell.view_paths = ["concepts"]
|
91
|
+
```
|
92
|
+
|
93
|
+
Note that this will change for all cells, including bundled in gems. Introduce an `Application::Cell` if you don't like that.
|
94
|
+
|
95
|
+
## Dependencies
|
96
|
+
|
97
|
+
This gem has only one dependency: `cells`. Note that it does *not need* `trailblazer`.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "cells"
|
2
|
+
|
3
|
+
module Trailblazer
|
4
|
+
class Cell < ::Cell::ViewModel
|
5
|
+
abstract!
|
6
|
+
self.view_paths = ["app/concepts"]
|
7
|
+
|
8
|
+
# TODO: this should be in Helper or something. this should be the only entry point from controller/view.
|
9
|
+
class << self
|
10
|
+
def class_from_cell_name(name)
|
11
|
+
name.camelize.constantize
|
12
|
+
end
|
13
|
+
|
14
|
+
def controller_path
|
15
|
+
@controller_path ||= File.join(util.underscore(name.sub(/(::Cell.+)/, '')), views_dir)
|
16
|
+
end
|
17
|
+
|
18
|
+
def views_dir
|
19
|
+
"view"
|
20
|
+
end
|
21
|
+
|
22
|
+
def view_name
|
23
|
+
@view_name ||= _view_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def _view_name
|
27
|
+
class_name = to_s.split("::").last
|
28
|
+
util.underscore(class_name).downcase
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def state_for_implicit_render(options)
|
33
|
+
self.class.view_name
|
34
|
+
end
|
35
|
+
|
36
|
+
# Automatic #show so you don't need to define it. Still overridable.
|
37
|
+
module Show
|
38
|
+
def show
|
39
|
+
render
|
40
|
+
end
|
41
|
+
end
|
42
|
+
include Show
|
43
|
+
|
44
|
+
module Layout
|
45
|
+
def render(options={})
|
46
|
+
options[:layout] = @options[:layout] if @options[:layout]
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_layout(options, content)
|
51
|
+
return content unless layout = options[:layout]
|
52
|
+
layout.new(model, parent_controller: parent_controller, content: content) # TODO: test parent_controller.
|
53
|
+
end
|
54
|
+
end
|
55
|
+
include Layout
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'trailblazer/cells/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "trailblazer-cells"
|
7
|
+
spec.version = Trailblazer::Cells::VERSION
|
8
|
+
spec.authors = ["Nick Sutterer"]
|
9
|
+
spec.email = ["apotonick@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Trailblazer's file layout with Cells.}
|
12
|
+
spec.description = %q{Cells that integrate with Trailblazer's file layout.}
|
13
|
+
spec.homepage = "http://trailblazer.to/gems/cells"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest"
|
23
|
+
spec.add_development_dependency "cells-erb"
|
24
|
+
|
25
|
+
spec.add_dependency "cells", ">= 4.0.3", "< 5.0.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trailblazer-cells
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Sutterer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cells-erb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cells
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.0.3
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 5.0.0
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 4.0.3
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 5.0.0
|
89
|
+
description: Cells that integrate with Trailblazer's file layout.
|
90
|
+
email:
|
91
|
+
- apotonick@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
98
|
+
- CHANGES.md
|
99
|
+
- Gemfile
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- lib/trailblazer/cell.rb
|
103
|
+
- lib/trailblazer/cells.rb
|
104
|
+
- lib/trailblazer/cells/version.rb
|
105
|
+
- trailblazer-cells.gemspec
|
106
|
+
homepage: http://trailblazer.to/gems/cells
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.8
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Trailblazer's file layout with Cells.
|
129
|
+
test_files: []
|