Last active
January 24, 2025 17:28
-
-
Save maxim/1e5c6816e97ecbe7e15eb3d364b0c9ea to your computer and use it in GitHub Desktop.
Revisions
-
maxim revised this gist
Jan 24, 2025 . 2 changed files with 10 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,11 @@ class WelcomePage attr_reader :greeting, :recent_activity, :support_email def self.from_user(user) new \ greeting: "Good #{user.time_of_day}, #{user.name}", recent_activity: ActivityItem.from_user(user), support_email: Rails.configuration.app.support_email end def initialize(greeting:, recent_activity:, support_email:) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,11 @@ # In this one I also do an example definition of ActivityItem class. class WelcomePage < ApplicationStruct def self.from_user(user) new \ greeting: "Good #{user.time_of_day}, #{user.name}", recent_activity: ActivityItem.from_user(user), support_email: Rails.configuration.app.support_email end keyword :greeting -
maxim revised this gist
Jan 24, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ <h2><%= @page.greeting %></h2> <ul> <%= @page.recent_activity.each do |item| %> -
maxim revised this gist
Jan 24, 2025 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ <h2><%= @page.greeting %></2> <ul> <%= @page.recent_activity.each do |item| %> <li> <strong><%= item.name %></strong>: <%= item.description %> </li> <% end %> </ul> <p>Get help: <%= mail_to @page.support_email %></p> -
maxim created this gist
Jan 24, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ class WelcomePage attr_reader :greeting, :recent_activity, :support_email class << self def from_user(user) new \ greeting: "Good #{user.time_of_day}, #{user.name}", recent_activity: ActivityItem.from_user(user), support_email: Rails.configuration.app.support_email end end def initialize(greeting:, recent_activity:, support_email:) @greeting = greeting @recent_activity = recent_activity @support_email = support_email end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ def show @page = WelcomePage.from_user(current_user) end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <h2><%= @page.greeting %></2> <ul> <li> <%= @page.recent_activity.each do |item| %> <strong><%= item.name %></strong>: <%= item.description %> <% end %> </li> </ul> <p>Get help: <%= mail_to @page.support_email %></p> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ # This is an alternative example of welcome_page.rb using https://github.com/maxim/portrayal # Assuming that ApplicationStruct has `extend Portrayal`. # In this one I also do an example definition of ActivityItem class. class WelcomePage < ApplicationStruct class << self def from_user(user) new \ greeting: "Good #{user.time_of_day}, #{user.name}", recent_activity: ActivityItem.from_user(user), support_email: Rails.configuration.app.support_email end end keyword :greeting keyword :support_email keyword :recent_activity, defines: 'ActivityItem' do def self.from_user(user) user.events.last(3).map { |event| new(name: event.name, description: event.description) } end keyword :name keyword :description end end