Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

of

Server side view rendering - dry-view Slide 1 Server side view rendering - dry-view Slide 2 Server side view rendering - dry-view Slide 3 Server side view rendering - dry-view Slide 4 Server side view rendering - dry-view Slide 5 Server side view rendering - dry-view Slide 6 Server side view rendering - dry-view Slide 7 Server side view rendering - dry-view Slide 8 Server side view rendering - dry-view Slide 9 Server side view rendering - dry-view Slide 10 Server side view rendering - dry-view Slide 11 Server side view rendering - dry-view Slide 12 Server side view rendering - dry-view Slide 13 Server side view rendering - dry-view Slide 14 Server side view rendering - dry-view Slide 15 Server side view rendering - dry-view Slide 16 Server side view rendering - dry-view Slide 17 Server side view rendering - dry-view Slide 18 Server side view rendering - dry-view Slide 19 Server side view rendering - dry-view Slide 20 Server side view rendering - dry-view Slide 21 Server side view rendering - dry-view Slide 22 Server side view rendering - dry-view Slide 23 Server side view rendering - dry-view Slide 24 Server side view rendering - dry-view Slide 25 Server side view rendering - dry-view Slide 26 Server side view rendering - dry-view Slide 27 Server side view rendering - dry-view Slide 28 Server side view rendering - dry-view Slide 29 Server side view rendering - dry-view Slide 30 Server side view rendering - dry-view Slide 31 Server side view rendering - dry-view Slide 32 Server side view rendering - dry-view Slide 33 Server side view rendering - dry-view Slide 34 Server side view rendering - dry-view Slide 35 Server side view rendering - dry-view Slide 36 Server side view rendering - dry-view Slide 37 Server side view rendering - dry-view Slide 38 Server side view rendering - dry-view Slide 39 Server side view rendering - dry-view Slide 40 Server side view rendering - dry-view Slide 41
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

Download to read offline

Server side view rendering - dry-view

Download to read offline

Based on Tim Riley talk about new changes in dry-view 0.6

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Server side view rendering - dry-view

  1. 1. VIEW RENDERING OSKAR SZRAJER - @GOTAR
  2. 2. SERVER SIDE VIEW RENDERING PAST AND PRESENT ▸ Controllers ▸ Helpers ▸ Templates
  3. 3. SERVER SIDE VIEW RENDERING PAST AND PRESENT ▸ Controllers
 (Too many responsibilities) ▸ Helpers ▸ Templates

  4. 4. SERVER SIDE VIEW RENDERING PAST AND PRESENT ▸ Controllers
 (Too many responsibilities) ▸ Helpers
 (Disorganised, mostly gross) ▸ Templates

  5. 5. SERVER SIDE VIEW RENDERING PAST AND PRESENT ▸ Controllers
 (Too many responsibilities) ▸ Helpers
 (Disorganised, mostly gross) ▸ Templates
 (Cluttered, too much logic)
  6. 6. SERVER SIDE VIEW RENDERING PAST AND PRESENT ▸ Controllers
 (Too many responsibilities) ▸ Helpers
 (Disorganised, mostly gross) ▸ Templates
 (Cluttered, too much logic) ▸ Decorators?

  7. 7. SERVER SIDE VIEW RENDERING PAST AND PRESENT ▸ Controllers
 (Too many responsibilities) ▸ Helpers
 (Disorganised, mostly gross) ▸ Templates
 (Cluttered, too much logic) ▸ Decorators?
 (Friction, limited)

  8. 8. DRY-VIEW
  9. 9. SERVER SIDE VIEW RENDERING DRY-VIEW ▸ Views as objects
  10. 10. class Show < Dry::View end view = Show.new
  11. 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. 12. SERVER SIDE VIEW RENDERING DRY-VIEW ▸ Views as objects ▸ Explicit template locals
  13. 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. 14. SERVER SIDE VIEW RENDERING DRY-VIEW ▸ Views as objects ▸ Explicit template locals ▸ Templates
  15. 15. / Template written in Slim h1 = article.title
  16. 16. view = Show.new(article_repo: repo) view.call( slug: “together-breakfast”, ).to_s #=> “<h1>Together breakfast</h1>”
  17. 17. h1 = article.title == markdown(article.body)
  18. 18. h1 = article.title == article.body_html
  19. 19. SERVER SIDE VIEW RENDERING DRY-VIEW ▸ Views as objects ▸ Explicit template locals ▸ Templates ▸ View logic on decorated values
  20. 20. class Parts::Article < Dry::View::Part def body_html render_markdown(body) end private def render_markdown(str) # … end end
  21. 21. class Show < Dry::View config.template = “articles/show” config.part_namespace = Parts expose :article # => Parts::Article end
  22. 22. h1 = article.title == article.body_html .share-widget[ data-share-url=article.url data-share-title=article.title data-share-body=article.body_preview_text ]
  23. 23. h1 = article.title == article.body_html == render(:share_widget, url: article.url, title: article.title, preview_text: article.body_preview_text)
  24. 24. class Parts::Article < Dry::View::Part def share_widget render( :share_widget, url: article.url, title: article.title, preview_text: article.body_preview_text) end end
  25. 25. h1 = article.title == article.body_html == article.share_widget
  26. 26. == render(:related_article, article: article)
  27. 27. - show_author = defined?(show_autor) ? show_author : false - link_prefix = defined?(link_prefix) ? link_prefix : “Related: ” .related-article a href=article.url = “#{link_prefix} #{article.title}” - if show_author .author …
  28. 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
  29. 29. .related-article a href=article.url = link_text - if show_author? .author …
  30. 30. == scope(:related_article, article: article).render
  31. 31. class Context < Dry::View::Context def initialize(assets:, **) @assets = assets super end def asset_path(asset_name) @assets[asset_name] end end
  32. 32. img src=asset_path(“header.png”) h1 = article.title == article.body_html == article.share_widget
  33. 33. class Parts::Article < Dry::View::Part def feature_image_url url = value.future_image_url url || asset_path(“article.png”) end end
  34. 34. SERVER SIDE VIEW RENDERING VIEW CONCEPTS ▸ View
 (config, dependencies, exposures)
  35. 35. SERVER SIDE VIEW RENDERING VIEW CONCEPTS ▸ View
 (config, dependencies, exposures) ▸ Exposures
 (prepare values)
  36. 36. SERVER SIDE VIEW RENDERING VIEW CONCEPTS ▸ View
 (config, dependencies, exposures) ▸ Exposures
 (prepare values) ▸ Template & partials
 (markup)
  37. 37. SERVER SIDE VIEW RENDERING VIEW CONCEPTS ▸ View
 (config, dependencies, exposures) ▸ Exposures
 (prepare values) ▸ Template & partials
 (markup) ▸ Parts
 (behaviour on values)
  38. 38. SERVER SIDE VIEW RENDERING VIEW CONCEPTS ▸ View
 (config, dependencies, exposures) ▸ Exposures
 (prepare values) ▸ Template & partials
 (markup) ▸ Parts
 (behaviour on values) ▸ Scopes
 (behaviour for templates)
  39. 39. SERVER SIDE VIEW RENDERING VIEW CONCEPTS ▸ View
 (config, dependencies, exposures) ▸ Exposures
 (prepare values) ▸ Template & partials
 (markup) ▸ Parts
 (behaviour on values) ▸ Scopes
 (behaviour for templates) ▸ Context
 (baseline rendering environment)
  40. 40. SERVER SIDE VIEW RENDERING WHAT HAVE WE LEARNT (GAIN)? ▸ Separation of concerns ▸ Encapsulation ▸ Immutability ▸ Testability
  41. 41. DRY-VIEW! OSKAR SZRAJER - @GOTAR

Based on Tim Riley talk about new changes in dry-view 0.6

Views

Total views

100

On Slideshare

0

From embeds

0

Number of embeds

0

Actions

Downloads

0

Shares

0

Comments

0

Likes

0

×