Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
# frozen_string_literal: true
class ApplicationComponent < ViewComponent::Base
end
@pbstriker38
pbstriker38 / progress_circle_component.html.erb
Created December 9, 2021 19:23
Circular progress bar ViewComponent
<!-- Circle -->
<div>
<!-- Building a Progress Ring: https://css-tricks.com/building-progress-ring-quickly/ -->
<svg height="<%= @diameter %>" width="<%= @diameter %>">
<circle
class="text-gray-300"
stroke-width="<%= @stroke_width %>"
stroke="currentColor"
fill="transparent"
r="<%= normalized_radius %>"
@Stylesproline
Stylesproline / README.md
Created December 9, 2021 07:53
Awesome-Selfhosted
@KonnorRogers
KonnorRogers / flash_component.rb
Last active March 31, 2023 19:20
A view component for using Shoelace alerts
class FlashComponent < ViewComponent::Base
extend Dry::Initializer
# notice, warning, and error can be set by default in redirect_to.
# For additional flashes, you must do flash[:type] = "message"
ICONS = {
primary: "info-circle",
success: "check2-circle",
info: "gear",
warning: "exclamation-triangle",
@westonganger
westonganger / Simple Rails Form Object
Last active October 11, 2023 18:23
Simple Rails Form Objects
class Forms::BaseForm
include ActiveModel::Validations
def initialize(attrs={})
attrs ||= {}
attrs.each do |k,v|
self.send("#{k}=", v) ### Use send so that it checks that attr_accessor has already defined the method so its a valid attribute
end
end
@fuksito
fuksito / callable_service.rb
Created August 10, 2021 07:34
CallableService Concern for Rails
# Usually service classes have only one purpose and thus should have only one public method that triggers action
# This module simplifies the common approach:
#
# SomeService.new(a, b, c).call
#
# To:
#
# SomeService.call(a, b, c)
#
# Requirements for class:
@AndreaBarghigiani
AndreaBarghigiani / table_component.html.erb
Created July 30, 2021 06:04
Simple Table with ViewComponents
<table class="<%= classes %>">
<thead class='bg-gray-300 font-medium'>
<% head %>
</thead>
<tbody>
<% body %>
</tbody>
</table>
@dalezak
dalezak / cacheable.rb
Last active March 14, 2023 21:39
Rails Cacheable Concern
# Rails concern that tracks and purges cache keys to avoid using Rails.cache.delete_matched since its very costly on Redis.
#
# @countries = Country.query_cached('countries:index', "limit:#{@limit}", "offset:#{@offset}") do
# query.limit(@limit).offset(@offset).all.to_a
# end
module Cacheable
extend ActiveSupport::Concern
included do
before_save :purge_cache
@existentialmutt
existentialmutt / modal_component.html.erb
Last active March 31, 2023 19:22
Modal ViewComponent
<div class="modal fade" id="<%= dom_id %>" role="dialog" tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<% if header %>
<div class="modal-header">
<%= header %>
<%- if header_close_btn %>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="fa fa-times-circle"></i>
</button>
@amirrajan
amirrajan / main.rb
Last active March 5, 2025 22:40
Gauntlet written in DragonRuby Game Toolkit
class Game
attr_gtk
def tick
defaults
render
input
calc
end