2. SERVER SIDE VIEW RENDERING
PAST AND PRESENT
▸ Controllers
▸ Helpers
▸ Templates
3. SERVER SIDE VIEW RENDERING
PAST AND PRESENT
▸ Controllers
(Too many responsibilities)
▸ Helpers
▸ Templates
4. SERVER SIDE VIEW RENDERING
PAST AND PRESENT
▸ Controllers
(Too many responsibilities)
▸ Helpers
(Disorganised, mostly gross)
▸ Templates
5. SERVER SIDE VIEW RENDERING
PAST AND PRESENT
▸ Controllers
(Too many responsibilities)
▸ Helpers
(Disorganised, mostly gross)
▸ Templates
(Cluttered, too much logic)
6. SERVER SIDE VIEW RENDERING
PAST AND PRESENT
▸ Controllers
(Too many responsibilities)
▸ Helpers
(Disorganised, mostly gross)
▸ Templates
(Cluttered, too much logic)
▸ Decorators?
7. SERVER SIDE VIEW RENDERING
PAST AND PRESENT
▸ Controllers
(Too many responsibilities)
▸ Helpers
(Disorganised, mostly gross)
▸ Templates
(Cluttered, too much logic)
▸ Decorators?
(Friction, limited)
11. class Show < Dry::View
attr_reader :article_repo
def initialize(article_repo:)
@article_repo = article_repo
end
end
view = Show.new(article_repo: repo)
12. SERVER SIDE VIEW RENDERING
DRY-VIEW
▸ Views as objects
▸ Explicit template locals
13. class Show < Dry::View
config.template = “articles/show”
expose :article do |slug:|
article_repo.find_by_slug(slug)
end
end
view = Show.new(article_repo: repo)
14. SERVER SIDE VIEW RENDERING
DRY-VIEW
▸ Views as objects
▸ Explicit template locals
▸ Templates
28. class Scopes::RelatedArticle < Dry::View::Scope
def show_author?
locales.fetch(:show_author, false)
end
def link_text
prexif = locals.fetch(:link_prefix, “Related:”)
“#{prefix} #{article.title}”
end
end