Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
43084ec7
Commit
43084ec7
authored
May 14, 2020
by
Ray Paik
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'patch-67' into 'master'
Proof Read README.md See merge request gitlab-org/gitlab!31977
parents
ec22983e
4daf0c76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
app/presenters/README.md
app/presenters/README.md
+8
-8
No files found.
app/presenters/README.md
View file @
43084ec7
...
...
@@ -8,7 +8,7 @@ methods from models to presenters.
### When your view is full of logic
When your view is full of logic (
`if`
,
`else`
,
`select`
on arrays etc.), it's
When your view is full of logic (
`if`
,
`else`
,
`select`
on arrays
,
etc.), it's
time to create a presenter!
### When your model has a lot of view-related logic/data methods
...
...
@@ -27,11 +27,11 @@ Presenters should be used for:
https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/7073/diffs.
-
Data and logic methods that can be pulled from models.
-
Simple text output methods: it's ok if the method returns a string, but not a
whole DOM element for which we'd need HAML, a view context, helpers etc.
whole DOM element for which we'd need HAML, a view context, helpers
,
etc.
## Why use presenters instead of model concerns?
We should strive to follow the single-responsibility principle
,
and view-related
We should strive to follow the single-responsibility principle and view-related
logic/data methods are definitely not the responsibility of models!
Another reason is as follows:
...
...
@@ -52,22 +52,22 @@ we gain the following benefits:
-
rules are more explicit and centralized in the presenter => improves security
-
testing is easier and faster as presenters are Plain Old Ruby Object (PORO)
-
views are more readable and maintainable
-
decreases number of CE -> EE merge conflicts since code is in separate files
-
decreases
the
number of CE -> EE merge conflicts since code is in separate files
-
moves the conflicts from views (not always obvious) to presenters (a lot easier to resolve)
## What not to do with presenters?
-
Don't use helpers in presenters. Presenters are not aware of the view context.
-
Don't generate complex DOM elements, forms etc. with presenters. Presenters
can return simple data
as
texts, and URLs using URL helpers from
`Gitlab::Routing`
but nothing much
more fancy
.
-
Don't generate complex DOM elements, forms
,
etc. with presenters. Presenters
can return simple data
like
texts, and URLs using URL helpers from
`Gitlab::Routing`
but nothing much
fancier
.
## Implementation
### Presenter definition
Every presenter should inherit from
`Gitlab::View::Presenter::Simple`
, which
provides a
`.presents`
method which allows you to define an accessor for the
provides a
`.presents`
the
method which allows you to define an accessor for the
presented object. It also includes common helpers like
`Gitlab::Routing`
and
`Gitlab::Allowable`
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment