Skip to content

Instantly share code, notes, and snippets.

View pootsbook's full-sized avatar

Philip Poots pootsbook

  • ClubCollect
  • Alphen aan den Rijn, NL
View GitHub Profile
@pootsbook
pootsbook / generic_form_field_rendering.rb
Last active April 15, 2021 21:35
An attempt at rendering form fields in a generic way from a form representation as data.
require "scrivener"
require "hypertext"
require "hypertext/dsl"
class RegistrationForm < Scrivener
attr_accessor :name
attr_accessor :email
attr_accessor :message
def validate
@pootsbook
pootsbook / _footer.ht.rb
Last active April 8, 2021 20:13
Sew with Hypertext DSL (.rb extension on templates only for syntax highlighting)
require "hypertext"
require "hypertext/dsl"
class Hypertext
def append(fragment)
@dom << fragment
end
class DSL
def append(fragment)
@pootsbook
pootsbook / html_document.rb
Created March 18, 2021 03:41
Fusion of HTMLDocument and Hypertext
class HTMLDocument
ENTITIES = {
"'" => '&#39;',
'&' => '&amp;',
'"' => '&quot;',
'<' => '&lt;',
'>' => '&gt;',
}
def initialize(indent = " ", level = 0)
class HTMLDocument
VOID_ELEMENTS = %i[
area base br col embed hr img input
link meta param source track wbr
]
def initialize
@doc = ""
yield self if block_given?
class HTMLDocument
def initialize
@doc = ""
yield self if block_given?
end
def el(type, attrs={})
case type
when :text
class HTMLDoc
def initialize
@node_id = 0
@parent_id = 0
@doc = []
yield self if block_given?
end
def el(type, attributes = {})
@pootsbook
pootsbook / assets.js.app.js
Last active October 23, 2020 18:34
LiveView Chat
// We need to import the CSS so that webpack will load it.
// The MiniCssExtractPlugin is used to separate it out into
// its own CSS file.
import "../css/app.scss"
// webpack automatically bundles all modules in your
// entry points. Those entry points can be configured
// in "webpack.config.js".
//
// Import deps with the dep name or local files with a relative path, for example:
@pootsbook
pootsbook / url.rb
Created October 12, 2013 19:14
URL
class Url
attr_reader :url
def initialize(url)
raise(ArgumentError, "url not specified") unless url
@url = url
end
def to_uri
URI.parse(url)