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 characters
require 'opal' | |
require 'clearwater' | |
require 'profile_page' | |
class Layout | |
include Clearwater::Component | |
def render | |
ProfilePage.new('yoxtb') |
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 characters
require 'opal' | |
require 'clearwater' | |
require 'routing' | |
class Layout | |
include Clearwater::Component | |
include Routing | |
def render | |
div([ |
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 characters
require 'clearwater/component' | |
# Renderable is just a component factory that makes heavy | |
# use of Ruby metaprogramming | |
module Renderable | |
include Clearwater::Component | |
# Return a Struct-like component class. It isn't an Enumerable like Structs | |
# are, but arguments to the factory methods become methods on instances of | |
# the component. |
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 characters
require 'primalize' | |
# Because TicketOwnerSerializer is a constant, it is available | |
# anywhere in the app. We could nest it inside of TicketSerializer, | |
# but it has to exist before TicketSerializer's attributes declaration, | |
# so it would push that down. | |
class TicketOwnerSerializer < Primalize::Single | |
attributes( | |
id: string, | |
name: string, |
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 characters
require 'authentication' | |
class MyApp < Roda | |
include Authentication | |
plugin :json | |
route do |r| | |
r.on('docs') { r.run Docs } |
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 characters
class ProcessThings | |
include Sidekiq::Worker | |
def perform(ids: Thing.ids) | |
ids.each(&Individual.method(:perform_async)) | |
end | |
class Individual | |
include Sidekiq::Worker | |
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 characters
class MasterDetailComponent | |
include Clearwater::Component | |
def initialize master, detail | |
@master = master | |
@detail = detail | |
end | |
def render | |
div([ |
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 characters
class GanttChart | |
include Clearwater::Component | |
include Clearwater::CachedRender | |
attr_reader :tasks | |
def initialize(tasks) | |
@tasks = tasks | |
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 characters
require 'clearwater/black_box_node' | |
require 'clearwater/component' | |
require 'clearwater/application' | |
class RenderPromise | |
include Clearwater::BlackBoxNode | |
DEFAULT = proc { Clearwater::Component.span } | |
Wrapper = Struct.new(:render).include(Clearwater::Component) |
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 characters
module Hooks | |
def self.component *attrs, &render | |
Class.new(Component) do | |
attr_reader *attrs | |
define_method :initialize do |**props| | |
super() | |
attrs.each { |attr| `self[#{attr}] = #{props[attr]}` } | |
end |