source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/meta_tags.rb | Ruby | bsd-3-clause | 99 | main | 2,007 | # frozen_string_literal: true
# Use this setup block to configure all options available in MetaTags.
MetaTags.configure do |config|
# How many characters should the title meta tag have at most. Default is 70.
# Set to nil or 0 to remove limits.
# config.title_limit = 70
# When true, site title will be truncat... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/rails_admin.rb | Ruby | bsd-3-clause | 99 | main | 1,017 | RailsAdmin.config do |config|
config.asset_source = :vite
### Popular gems integration
## == Devise ==
# config.authenticate_with do
# warden.authenticate! scope: :user
# end
config.current_user_method(&:current_user)
## == CancanCan ==
# config.authorize_with :cancancan
## == Pundit ==
# co... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/repository.rb | Ruby | bsd-3-clause | 99 | main | 398 | RepositoryCheck = Class.new(StandardError)
message = <<~MSG
Repository check failed!
The application cannot find the git repository at #{ENV.fetch("REPOSITORY_ROOT", ".")}
Please set the REPOSITORY_ROOT environment variable to the path of the git repository.
MSG
Dir.chdir(ENV.fetch("REPOSITORY_ROOT", ".")) do
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/markdown.rb | Ruby | bsd-3-clause | 99 | main | 436 | ActionView::Template.register_template_handler :md, ->(template, source) {
Markdown::Application.new(source).call
}
ActionView::Template.register_template_handler :mdrb, ->(template, source) {
Markdown::AllowsErb::Handler.new(Markdown::Article).call(template, source)
}
ActionView::Template.register_template_handl... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/schema_dumper.rb | Ruby | bsd-3-clause | 99 | main | 318 | ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
# Ignore tables managed by the sqlite-vec extension
# matches tables like: page_embeddings_chunks, page_embeddings_chunks00, and
# page_embeddings_rowids
ignore_tables += [/_chunks\d*$/] + [/_rowids$/]
ActiveRecord::SchemaDumper.ignore_tables = ignore_tables |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/vapid.rb | Ruby | bsd-3-clause | 99 | main | 993 | Rails.application.configure do
# The VAPID public key is used to identify the server that is sending the web push notification.
# To regenerate the VAPID keys, run the following command:
# bin/rails runner "puts WebPush.generate_key.to_h.to_yaml"
#
# The Ruby WebPush library can produce a padded public key un... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/filter_parameter_logging.rb | Ruby | bsd-3-clause | 99 | main | 512 | # Be sure to restart your server when you modify this file.
# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
# Use this to limit dissemination of sensitive information.
# See the ActiveSupport::ParameterFilter documentation for supported notations and behavio... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/environments/test.rb | Ruby | bsd-3-clause | 99 | main | 2,965 | require "active_support/core_ext/integer/time"
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data the... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/environments/production.rb | Ruby | bsd-3-clause | 99 | main | 4,636 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot. This eager loads most of Rails and
# your app... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/environments/development.rb | Ruby | bsd-3-clause | 99 | main | 3,616 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for developme... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/clients/application_client.rb | Ruby | bsd-3-clause | 99 | main | 10,763 | require "ostruct"
class ApplicationClient
# A basic API client with HTTP methods
#
# The Authorization Bearer token header for authentication is included by default
# You can override the `authorization_header` method to change this
#
# Content Type is application/json by default
# You can override the `... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/clients/postmark_client.rb | Ruby | bsd-3-clause | 99 | main | 296 | class PostmarkClient
def self.deliver_messages(messages)
new.deliver_messages(messages)
end
def deliver_messages(messages)
api_client.deliver_messages(messages)
end
def api_client
@api_client ||= Postmark::ApiClient.new(Rails.configuration.x.postmark.api_token)
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/clients/plausible_client.rb | Ruby | bsd-3-clause | 99 | main | 890 | # frozen_string_literal: true
# https://plausible.io/docs/events-api#endpoints
#
# curl -i -X POST https://plausible.io/api/event \
# -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284' \
# -H 'X-Forwarded-For:... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/notifications/event_job.rb | Ruby | bsd-3-clause | 99 | main | 366 | class Notifications::EventJob < ApplicationJob
queue_as :default
def perform(event)
event.deliver_notifications_in_bulk
# Enqueue individual deliveries
event.notifications.each do |notification|
notification.transaction do
event.deliver_notification(notification)
notification.tou... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/pwa/web_push_job.rb | Ruby | bsd-3-clause | 99 | main | 866 | class Pwa::WebPushJob < ApplicationJob
queue_as :default
def perform(title:, message:, subscription:)
message_json = {
title: title,
body: message,
icon: icon_url
}.to_json
response = WebPush.payload_send(
message: message_json,
endpoint: subscription["endpoint"],
p... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/analytics/plausible_event_job.rb | Ruby | bsd-3-clause | 99 | main | 400 | class Analytics::PlausibleEventJob < ApplicationJob
def perform(name:, url:, referrer: nil, props: nil, headers: {})
result = PlausibleClient.new.post_event(name:, url:, referrer:, props:, headers: headers)
Rails.logger.info("[#{self.class}] Plausible event posted: #{result.code} #{result.body}")
Honeyba... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/pages/refresh_search_index_job.rb | Ruby | bsd-3-clause | 99 | main | 366 | module Pages
class RefreshSearchIndexJob < ApplicationJob
class Batch < ApplicationJob
queue_as :default
def perform
Page.published.find_each do |page|
Pages::RefreshSearchIndexJob.perform_later(page)
end
end
end
queue_as :default
def perform(page)
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/pages/analyze_topics_job.rb | Ruby | bsd-3-clause | 99 | main | 5,240 | # Credit for this topics analysis job logic and OpenAI prompt goes to
# rubyvideo.dev. Please support their platform!
module Pages
class AnalyzeTopicsJob < ApplicationJob
class Batch < ApplicationJob
queue_as :default
def perform
Page.published.where.missing(:topics).find_each do |page|
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/pages/batch_upsert_pages_job.rb | Ruby | bsd-3-clause | 99 | main | 341 | module Pages
class BatchUpsertPagesJob < ApplicationJob
queue_as :default
def perform(limit: nil)
Page.upsert_collection_from_sitepress!(limit: limit)
Pages::RefreshSearchIndexJob::Batch.perform_later
Pages::AnalyzeTopicsJob::Batch.perform_later
Pages::EmbeddingJob::Batch.perform_lat... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/pages/embedding_job.rb | Ruby | bsd-3-clause | 99 | main | 719 | module Pages
class EmbeddingJob < ApplicationJob
class Batch < ApplicationJob
queue_as :default
def perform
Page.published.where.missing(:page_embedding).find_each do |page|
Pages::EmbeddingJob.perform_later(page)
end
end
end
queue_as :default
def perform... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/jobs/channels/heartbeat_job.rb | Ruby | bsd-3-clause | 99 | main | 285 | class Channels::HeartbeatJob < ApplicationJob
queue_as :default
def perform
AdminUser.find_each do |admin_user|
HeartbeatChannel.broadcast_to \
admin_user,
title: "It’s alive!",
body: "The Action Cable connection is working!"
end
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/helpers/application_helper.rb | Ruby | bsd-3-clause | 99 | main | 1,427 | module ApplicationHelper
def seo_meta_tags
favicon_path = Rails.env.local? ? asset_path("app-icons/favicon-local.ico") : asset_path("app-icons/favicon.ico")
favicon_svg_path = Rails.env.local? ? asset_path("app-icons/icon-local.svg") : asset_path("app-icons/icon.svg")
apple_touch_icon_path = Rails.env.loc... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/newsletter.rb | Ruby | bsd-3-clause | 99 | main | 537 | # == Schema Information
#
# Table name: newsletters
#
# id :string not null, primary key
# content :text not null
# sent_at :datetime
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_n... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page_embedding.rb | Ruby | bsd-3-clause | 99 | main | 914 | # frozen_string_literal: true
class PageEmbedding < ApplicationRecord
OPENAI_EMBEDDING_LENGTH = 1536
attribute :embedding, Types::Vector.new
belongs_to :page, inverse_of: :page_embedding, foreign_key: :id, primary_key: :id, touch: true
scope :similar_to, ->(page) do
select(:id, :distance)
.where("... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/notification.rb | Ruby | bsd-3-clause | 99 | main | 1,076 | # == Schema Information
#
# Table name: notifications
#
# id :integer not null, primary key
# processed_at :datetime
# read_at :datetime
# recipient_type :string not null
# seen_at :datetime
# type :string
# create... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/application_event.rb | Ruby | bsd-3-clause | 99 | main | 484 | # == Schema Information
#
# Table name: application_events
#
# id :string not null, primary key
# data :text not null
# metadata :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# inde... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/color_scheme.rb | Ruby | bsd-3-clause | 99 | main | 3,881 | # frozen_string_literal: true
# == Schema Information
#
# Table name: color_schemes
#
# id :string not null, primary key
# name :string not null
# weight_100 :string not null
# weight_200 :string not null
# weight_300 :string not null
# weight_400 :... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/settings.rb | Ruby | bsd-3-clause | 99 | main | 332 | class Settings
include ActiveModel::Model
attr_accessor :color_scheme, :syntax_highlight
def initialize(color_scheme: nil, syntax_highlight: nil)
@color_scheme = color_scheme
@syntax_highlight = syntax_highlight
end
def color_scheme_id = color_scheme.id
def syntax_highlight_name = syntax_highlig... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/user.rb | Ruby | bsd-3-clause | 99 | main | 3,035 | # == Schema Information
#
# Table name: users
#
# id :string not null, primary key
# confirmed_at :datetime
# email :string not null
# last_sign_in_at :datetime
# name :string
# password_digest :string
# created_at :datetime not null
# update... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page_topic.rb | Ruby | bsd-3-clause | 99 | main | 754 | # == Schema Information
#
# Table name: page_topics
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# page_id :string not null
# topic_id :integer not null
#
# Indexes
#
# index_page_topics_on_page_id ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/notification_event.rb | Ruby | bsd-3-clause | 99 | main | 2,498 | # == Schema Information
#
# Table name: notification_events
#
# id :integer not null, primary key
# notifications_count :integer default(0)
# params :json
# type :string
# created_at :datetime not null
# updated_at :datetime ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/poll.rb | Ruby | bsd-3-clause | 99 | main | 1,823 | # == Schema Information
#
# Table name: polls
#
# id :string not null, primary key
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
# author_id :string not null
#
# Indexes
#
# index_polls_on_author_id (author_id)... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/admin_user.rb | Ruby | bsd-3-clause | 99 | main | 664 | # == Schema Information
#
# Table name: admin_users
#
# id :integer not null, primary key
# email :string
# password_digest :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_admin_users_on_emai... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/email_exchange.rb | Ruby | bsd-3-clause | 99 | main | 896 | # == Schema Information
#
# Table name: email_exchanges
#
# id :integer not null, primary key
# email :string not null
# status :string default("pending"), not null
# created_at :datetime not null
# updated_at :datetime not null
# user_id :string ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/color.rb | Ruby | bsd-3-clause | 99 | main | 707 | require "color_conversion"
class Color
def self.load(value)
return nil if value.nil?
new(value)
end
def self.dump(value)
case value
when Color
value.hex
else
value
end
end
def initialize(value)
@_color = ColorConversion::Color.new(value)
end
def ==(other)
re... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/gravatar.rb | Ruby | bsd-3-clause | 99 | main | 1,843 | # frozen_string_literal: true
require "addressable/template"
class Gravatar
# Gravatar URI template
#
# digest = MD5 hash of the email address
#
# s = size, an integer, default is 80
#
# d = default image when none found, can be one of the following:
# - an encoded URL
# - 404: do not load any image... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/newsletter_subscription.rb | Ruby | bsd-3-clause | 99 | main | 615 | # == Schema Information
#
# Table name: newsletter_subscriptions
#
# id :string not null, primary key
# subscriber_type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# subscriber_id :string not null
#
# Indexe... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/topic.rb | Ruby | bsd-3-clause | 99 | main | 1,320 | # == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# description :text
# name :string
# pages_count :integer default(0), not null
# slug :string not null
# status :string default("pending"), not null
# created_at ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/snippet.rb | Ruby | bsd-3-clause | 99 | main | 1,871 | # == Schema Information
#
# Table name: snippets
#
# id :string not null, primary key
# author_type :string not null
# description :text
# filename :string
# language :string
# source :text not null
# title :string
# created_at :datetime not nul... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page.rb | Ruby | bsd-3-clause | 99 | main | 2,038 | # frozen_string_literal: true
# ActiveRecord model to represent a static page in the database.
# == Schema Information
#
# Table name: pages
#
# id :string not null, primary key
# indexed_at :datetime
# published_at :datetime
# request_path :string not null
# revised_at :datetime... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page_poll.rb | Ruby | bsd-3-clause | 99 | main | 628 | # == Schema Information
#
# Table name: page_polls
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# page_id :string not null
# poll_id :string not null
#
# Indexes
#
# index_page_polls_on_page_id ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/repo.rb | Ruby | bsd-3-clause | 99 | main | 698 | # We take advantage of the fact that our deployment tool is Hatchbox which uses
# git on the server as part of the deploy process. We abstract git commands so callers
# don’t need to be aware of the fact that the git repository is in a different location.
class Repo
def root = ENV.fetch("REPOSITORY_ROOT", ".")
def... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/settings/syntax_highlight.rb | Ruby | bsd-3-clause | 99 | main | 1,214 | class Settings::SyntaxHighlight
include ActiveModel::Model
def self.default
find("dracula")
end
def self.find(name)
instance = curated.find { |obj| obj.name == name }
instance.presence or raise ActiveRecord::RecordNotFound, "Couldn't find SyntaxHighlight with name '#{name}'"
end
# This method... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/validators/schema_validator.rb | Ruby | bsd-3-clause | 99 | main | 404 | require "json-schema"
module Validators
class SchemaValidator < ActiveModel::Validator
def validate(record)
schema = options.fetch(:schema)
field_name = options.fetch(:field)
value = record.send(field_name)
unless JSON::Validator.validate(schema, value)
record.errors.add(field_nam... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/types/vector.rb | Ruby | bsd-3-clause | 99 | main | 1,191 | # Custom type for ActiveRecord to deserialize vectors from vector columns
# enabled by sqlite-vec extensions which provides vec0 virtual tables.
module Types
class Vector < ActiveModel::Type::Value
include ActiveModel::Type::SerializeCastValue
def type
:vector
end
def deserialize(value)
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/polls/question.rb | Ruby | bsd-3-clause | 99 | main | 802 | # == Schema Information
#
# Table name: polls_questions
#
# id :integer not null, primary key
# body :string not null
# position :integer default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# poll_id :string ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/polls/vote.rb | Ruby | bsd-3-clause | 99 | main | 677 | # == Schema Information
#
# Table name: polls_votes
#
# id :integer not null, primary key
# device_uuid :string
# created_at :datetime not null
# updated_at :datetime not null
# answer_id :integer not null
# user_id :string
#
# Indexes
#
# index_polls_votes_on_a... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/polls/answer.rb | Ruby | bsd-3-clause | 99 | main | 788 | # == Schema Information
#
# Table name: polls_answers
#
# id :integer not null, primary key
# body :string not null
# position :integer default(0), not null
# votes_count :integer default(0), not null
# created_at :datetime not null
# updated_at :d... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/application_events/deploy.rb | Ruby | bsd-3-clause | 99 | main | 919 | # == Schema Information
#
# Table name: application_events
#
# id :string not null, primary key
# data :text not null
# metadata :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# inde... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/searches/query_transformer.rb | Ruby | bsd-3-clause | 99 | main | 505 | module Searches
class QueryTransformer < Parslet::Transform
rule(term: simple(:term)) { Term.new(term.to_s) }
rule(phrase: sequence(:phrase)) { Phrase.new(phrase) }
rule(condition: {left: simple(:left), operator: simple(:operator), right: subtree(:right)}) do
Condition.new(left, Operator.new(operato... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/searches/query_parser.rb | Ruby | bsd-3-clause | 99 | main | 943 | module Searches
class QueryParser < Parslet::Parser
rule(:dquote) { str(%(")) }
rule(:squote) { str(%(')) }
rule(:lparen) { str("(") }
rule(:rparen) { str(")") }
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
rule(:operator) { (str("+") | str("-") | str("|")).as(:op... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/searches/condition.rb | Ruby | bsd-3-clause | 99 | main | 264 | module Searches
class Condition
attr_accessor :left, :operator, :right
def initialize(left, operator, right)
@left = left
@operator = operator
@right = right
end
def to_s
"#{left} #{operator} #{right}"
end
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/searches/query.rb | Ruby | bsd-3-clause | 99 | main | 531 | module Searches
class Query
attr_accessor :expressions
def self.parse!(query)
ast = Searches::QueryParser.new.parse(query)
Searches::QueryTransformer.new.apply(ast)
rescue Parslet::ParseFailed => error
raise Searches::ParseFailed, error.message
end
def self.parse(query)
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/searches/operator.rb | Ruby | bsd-3-clause | 99 | main | 417 | module Searches
class Operator
def self.symbol(str)
case str
when "+"
:and
when "-"
:not
when "|"
:or
else
raise "Unknown operator: #{str}"
end
end
def initialize(operator)
@operator = self.class.symbol(operator)
end
def t... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/examples/app_file.rb | Ruby | bsd-3-clause | 99 | main | 1,819 | # frozen_string_literal: true
module Examples
class AppFile
class << self
def glob(pattern)
Dir[pattern].map { |path| new(path) }
end
alias_method :[], :glob
def find(path)
raise ActiveRecord::RecordNotFound unless File.exist?(path)
new(path)
end
def... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/examples/post.rb | Ruby | bsd-3-clause | 99 | main | 1,943 | # == Schema Information
#
# Table name: examples_posts
#
# id :integer not null, primary key
# postable_type :string not null
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
# postable_id :integer ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/examples/posts/link.rb | Ruby | bsd-3-clause | 99 | main | 294 | # == Schema Information
#
# Table name: examples_posts_links
#
# id :integer not null, primary key
# url :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Examples::Posts::Link < ApplicationRecord
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/examples/posts/markdown.rb | Ruby | bsd-3-clause | 99 | main | 302 | # == Schema Information
#
# Table name: examples_posts_markdowns
#
# id :integer not null, primary key
# body :text not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Examples::Posts::Markdown < ApplicationRecord
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/examples/posts/image.rb | Ruby | bsd-3-clause | 99 | main | 296 | # == Schema Information
#
# Table name: examples_posts_images
#
# id :integer not null, primary key
# url :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Examples::Posts::Image < ApplicationRecord
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/concerns/sluggable.rb | Ruby | bsd-3-clause | 99 | main | 491 | module Sluggable
extend ActiveSupport::Concern
included do
before_validation :set_slug
validates :slug, presence: true
validates :slug, uniqueness: true
end
def to_param
slug
end
private
def set_slug
self.slug = slug.presence || send(slug_source).parameterize
end
def slug_sour... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page/searchable.rb | Ruby | bsd-3-clause | 99 | main | 3,025 | class Page
module Searchable
extend ActiveSupport::Concern
Error = Class.new(StandardError)
ConfigurationError = Class.new(Error)
included do
after_destroy_commit :remove_from_search_index
scope :search, ->(query) do
join_search_index.where("pages_search_index MATCH ?", query)
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page/sitepressed.rb | Ruby | bsd-3-clause | 99 | main | 4,112 | class Page
module Sitepressed
extend ActiveSupport::Concern
Resource = Data.define(
:request_path,
:body,
:title,
:description,
:image,
:meta_image,
:toc,
:enable_twitter_widgets,
:uuid,
:author,
:published_on,
:updated_on
) do
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/page/similarity.rb | Ruby | bsd-3-clause | 99 | main | 2,030 | class Page
module Similarity
extend ActiveSupport::Concern
included do
has_one :page_embedding, inverse_of: :page, foreign_key: :id, primary_key: :id
# We unscope(:where) because we want to disable the default association
# behavior of scoping where(id: page.id) for querying related pages ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/pwa/named_installation_instructions.rb | Ruby | bsd-3-clause | 99 | main | 1,527 | module Pwa
class NamedInstallationInstructions
def self.user_agent_glob
Dir[Rails.root.join("app", "views", "pwa", "installation_instructions", "user_agents", "*.html.erb")]
end
def self.user_agent_nicknames
@user_agent_nicknames ||= user_agent_glob.map do |path|
File.basename(path, "... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/models/pwa/user_agent_installation_instructions.rb | Ruby | bsd-3-clause | 99 | main | 1,341 | module Pwa
class UserAgentInstallationInstructions
delegate :full_version, to: :@device_detector
def initialize(user_agent)
@device_detector = DeviceDetector.new(user_agent)
end
def user_agent_nickname
"#{installation_os}_#{installation_browser}"
end
def partial_name
retur... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/content/models/sitepress_article.rb | Ruby | bsd-3-clause | 99 | main | 1,165 | class SitepressArticle < Sitepress::Model
extend ActiveModel::Naming
include ActiveModel::Conversion
data :title, :published, :updated, :summary, :description, :tags, :image
delegate :resource_path, :mime_type, :handler, to: :page
def self.all = glob("articles/*.html*")
def self.published(params = {})
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/content/helpers/poll_helper.rb | Ruby | bsd-3-clause | 99 | main | 315 | module PollHelper
def render_lazy_page_poll(title)
@data ||= YAML.load_file(Rails.root.join("app", "models", "polls", "lazy.yml"))
question_data = @data.dig("polls", title)
return "foogats" unless question_data
render Share::Polls::LazyPagePoll.new(@current_page, title, question_data)
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/content/helpers/page_helper.rb | Ruby | bsd-3-clause | 99 | main | 1,220 | # frozen_string_literal: true
module PageHelper
DEFAULT_TITLE_KEY = "title"
# Creates a hyperlink to a page using the `title` key. Change the default in the args
# below if you use a different key for page titles.
def link_to_page(page, *, title_key: DEFAULT_TITLE_KEY, **, &block)
if block
link_to(p... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/welcome_notifier.rb | Ruby | bsd-3-clause | 99 | main | 826 | class WelcomeNotifier < NotificationEvent
def self.deliver_to(user, **)
new(params: {user: user}).deliver(user, **)
end
def deliver_notification(notification)
user = notification.recipient
unsubscribe_token = user&.newsletter_subscription&.generate_token_for(:unsubscribe) || :no_token
if !delive... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/newsletter_notifier.rb | Ruby | bsd-3-clause | 99 | main | 1,550 | class NewsletterNotifier < NotificationEvent
Error = Class.new(StandardError)
def self.deliver_to(users, newsletter:, live: false, **)
new(params: {newsletter_id: newsletter.id, live:}).deliver(users, **)
end
def deliver_notifications_in_bulk
newsletter = Newsletter.find(params[:newsletter_id])
me... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/password_reset_notifier.rb | Ruby | bsd-3-clause | 99 | main | 368 | class PasswordResetNotifier < NotificationEvent
def self.deliver_to(user, **)
new(params: {user: user}).deliver(user, **)
end
def deliver_notification(notification)
user = notification.recipient
password_reset_token = user.generate_token_for(:password_reset)
Emails::UserMailer.password_reset(user... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/new_user_notifier.rb | Ruby | bsd-3-clause | 99 | main | 372 | class NewUserNotifier < NotificationEvent
def self.deliver_to(admin_user, user:, **)
new(params: {user_id: user.id}).deliver(admin_user, **)
end
def deliver_notification(notification)
admin_user = notification.recipient
user = User.find(params[:user_id])
Emails::AdminUserMailer.new_user(admin_us... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/magic_session_failed_notifier.rb | Ruby | bsd-3-clause | 99 | main | 369 | class MagicSessionFailedNotifier < NotificationEvent
def self.deliver_to(user, **)
new(params: {user: user}).deliver(user, **)
end
def deliver_notification(notification)
user = notification.recipient
magic_session_token = user.generate_token_for(:magic_session)
Emails::UserMailer.magic_session(us... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/email_confirmation_notifier.rb | Ruby | bsd-3-clause | 99 | main | 365 | class EmailConfirmationNotifier < NotificationEvent
def self.deliver_to(user, **)
new(params: {user: user}).deliver(user, **)
end
def deliver_notification(notification)
user = notification.recipient
confirmation_token = user.generate_token_for(:confirmation)
Emails::UserMailer.confirmation(user,... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/notifiers/magic_session_token_notifier.rb | Ruby | bsd-3-clause | 99 | main | 375 | class MagicSessionTokenNotifier < NotificationEvent
def self.deliver_to(user, **)
new(params: {user: user}).deliver(user, **)
end
def deliver_notification(notification)
user = notification.recipient
magic_session_token = user.generate_token_for(:magic_session)
Emails::MagicSessionMailer.sign_in_l... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/application_view.rb | Ruby | bsd-3-clause | 99 | main | 306 | # frozen_string_literal: true
class ApplicationView < ApplicationComponent
# The ApplicationView is an abstract class for all your views.
# By default, it inherits from `ApplicationComponent`, but you
# can change that to `Phlex::HTML` if you want to keep views and
# components independent.
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/clipboard_copy.rb | Ruby | bsd-3-clause | 99 | main | 1,257 | class ClipboardCopy < Phlex::HTML
include PhlexConcerns::SvgTag
attr_accessor :text
def initialize(text:)
@text = text
end
def view_template
div(
data_controller: "clipboard-copy",
class: "clipboard-copy-container"
) do
whitespace
button(
aria_label: "Copy to cli... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/application_component.rb | Ruby | bsd-3-clause | 99 | main | 339 | # frozen_string_literal: true
class ApplicationComponent < Phlex::HTML
include Phlex::Rails::Helpers::Routes
include PhlexConcerns::Links
if Rails.env.development?
def before_template
comment { "Before #{self.class.name}" }
super
end
end
def markdown
render Markdown::Application.ne... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/demo/ruby_enumeration.rb | Ruby | bsd-3-clause | 99 | main | 1,242 | module Demo
class RubyEnumeration < ApplicationComponent
attr_reader :demo_type
def initialize(demo_type = "default")
@demo_type = demo_type.to_s
end
def view_template
iframe(
id: [:ruby, :enumeration, demo_type].join("-"),
data: {
"controller" => "demo-ruby-enu... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/pwa/web_push_demo.rb | Ruby | bsd-3-clause | 99 | main | 1,741 | class Pwa::WebPushDemo < Phlex::HTML
include Phlex::Rails::Helpers::FormFor
include Phlex::Rails::Helpers::Routes
def view_template
div(
data: {
controller: "pwa-web-push-demo",
action: "pwa-web-push-subscription:subscription-changed->pwa-web-push-demo#onSubscriptionChanged" \
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/pwa/web_push_subscription.rb | Ruby | bsd-3-clause | 99 | main | 904 | class Pwa::WebPushSubscription < Phlex::HTML
include Phlex::Rails::Helpers::ButtonTag
def view_template
div(
data: {
controller: "pwa-web-push-subscription"
},
class: "pwa-web-push-subscription flex gap-2"
) do
div do
button(
data: {
action: "pw... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/front_door/form.rb | Ruby | bsd-3-clause | 99 | main | 1,927 | class FrontDoor::Form < ApplicationComponent
include Phlex::Rails::Helpers::FormWith
include Phlex::Rails::Helpers::FieldsFor
include Phlex::Rails::Helpers::Label
include Phlex::Rails::Helpers::Object
include Phlex::Rails::Helpers::Routes
include PhlexConcerns::SvgTag
def initialize(title:)
@title = ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/content/image.rb | Ruby | bsd-3-clause | 99 | main | 1,219 | module Content
class Image < ApplicationComponent
attr_reader :src, :alt, :title, :attributes
def initialize(src, alt: "", title: "", **attributes)
@src = src
@alt = alt.presence || File.basename(src, ".*").humanize
@title = title
@attributes = attributes
end
def view_templat... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/color_schemes/swatches.rb | Ruby | bsd-3-clause | 99 | main | 633 | # frozen_string_literal: true
class ColorSchemes::Swatches < ApplicationComponent
attr_reader :color_scheme
def initialize(color_scheme:)
@color_scheme = color_scheme
end
def view_template
div(class: "color-scheme color-scheme__#{color_scheme.name.parameterize} grid-cols-12") do
color_scheme.we... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/color_schemes/css.rb | Ruby | bsd-3-clause | 99 | main | 974 | # frozen_string_literal: true
class ColorSchemes::Css < Phlex::HTML
attr_reader :color_scheme
def initialize(color_scheme:, my_theme_enabled: false)
@color_scheme = color_scheme
@my_theme = my_theme_enabled
end
def view_template
raw safe(css_variables)
if my_theme?
raw safe(my_css_varia... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/site_header/header.rb | Ruby | bsd-3-clause | 99 | main | 739 | module SiteHeader
class Header < ApplicationComponent
include Phlex::Rails::Helpers::Routes
include Phlex::Rails::Helpers::TurboFrameTag
include PhlexConcerns::SvgTag
def view_template
header aria: {label: "header"} do
div(class: "site-header container") do
nav do
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/site_header/nav.rb | Ruby | bsd-3-clause | 99 | main | 310 | module SiteHeader
class Nav < ApplicationComponent
def view_template
nav(class: "flex items-stretch px-1 col-gap-3xs") do
# = header_navigation_link_to "Articles", "/articles"
yield
render Searches::Button.new
render DarkMode::Switch.new
end
end
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/forms/stack.rb | Ruby | bsd-3-clause | 99 | main | 1,459 | module Forms
class Stack < ApplicationComponent
include Phlex::Rails::Helpers::FormWith
include Phlex::Rails::Helpers::EmailField
include Phlex::Rails::Helpers::FieldsFor
include Phlex::Rails::Helpers::Label
include Phlex::Rails::Helpers::Object
include Phlex::Rails::Helpers::Routes
def v... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/app_file_run.rb | Ruby | bsd-3-clause | 99 | main | 1,688 | class CodeBlock::AppFileRun < ApplicationComponent
prepend CodeBlock::AtomAware
attr_reader :app_file, :lines, :language
# @param filename [String] the file path or an Examples::AppFile.
# @param file [String] the file path or an Examples::AppFile.
def initialize(filename, lines: nil, revision: "HEAD", lang... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/atom_aware.rb | Ruby | bsd-3-clause | 99 | main | 594 | # Prepend this module to the CodeBlock::Component class to render the basic code block when rendering within an Atom feed.
module CodeBlock::AtomAware
def view_template
# When a code block renders within an Atom feed, we want to render the basic code block
if content_type?("application/atom+xml")
render... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/snippet.rb | Ruby | bsd-3-clause | 99 | main | 939 | class CodeBlock::Snippet < ApplicationComponent
include Phlex::Rails::Helpers::DOMID
prepend CodeBlock::AtomAware
attr_reader :snippet, :options
delegate :language, :filename, to: :snippet
def initialize(snippet, screenshot: false, **options)
@snippet = snippet
@screenshot = screenshot
@options... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/article.rb | Ruby | bsd-3-clause | 99 | main | 782 | class CodeBlock::Article < ApplicationComponent
prepend CodeBlock::AtomAware
attr_reader :source, :language, :filename, :options
def initialize(source = "", language: nil, filename: nil, header: true, **options)
@source = source
@language = language
@filename = filename
@header = header
@opt... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/header.rb | Ruby | bsd-3-clause | 99 | main | 238 | class CodeBlock::Header < ApplicationComponent
include PhlexConcerns::SvgTag
def view_template(&)
div(class: "code-header") do
svg_tag("app-dots.svg", class: "app-dots")
span(class: "code-title", &)
end
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/app_file.rb | Ruby | bsd-3-clause | 99 | main | 1,010 | class CodeBlock::AppFile < ApplicationComponent
prepend CodeBlock::AtomAware
attr_reader :app_file, :lines, :attributes, :language, :highlight_lines
# @param filename [String] the file path or an Examples::AppFile.
# @param file [String] the file path or an Examples::AppFile.
def initialize(filename, langua... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/container.rb | Ruby | bsd-3-clause | 99 | main | 418 | class CodeBlock::Container < ApplicationComponent
include Phlex::Rails::Helpers::ClassNames
attr_reader :language, :classes, :options
def initialize(language: "plain", **options)
@language = language
@classes = options.delete(:class)
@options = options
end
def view_template(&)
div(class: cl... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/app_file_header.rb | Ruby | bsd-3-clause | 99 | main | 446 | class CodeBlock::AppFileHeader < ApplicationComponent
include PhlexConcerns::SvgTag
attr_reader :app_file
def initialize(app_file)
@app_file = app_file
end
def view_template
render CodeBlock::Header.new do
link(app_file.repo_url, "Source code on Github", class: "nc") do
plain app_file... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/code_block/code.rb | Ruby | bsd-3-clause | 99 | main | 1,606 | # frozen_string_literal: true
class CodeBlock::Code < ApplicationComponent
class << self
def code_formatter
@code_formatter ||= Rouge::Formatters::HTML.new
end
end
attr_reader :source, :language, :data
def initialize(source = "", language: nil, data: {}, highlight_lines: [], **)
@source = s... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/dialog/layout.rb | Ruby | bsd-3-clause | 99 | main | 1,042 | module Dialog
class Layout < ApplicationComponent
include PhlexConcerns::SvgTag
attr_reader :attributes
def initialize(**attributes)
@attributes = attributes
end
def view_template(&)
dialog(**mix(attributes, class: "rounded-lg drop-shadow-xl")) do
div(class: "flex min-h-full... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/markdown/application.rb | Ruby | bsd-3-clause | 99 | main | 743 | class Markdown::Application < Markdown::Base
include Phlex::Rails::Helpers::ImageTag
include ActionView::Helpers::AssetUrlHelper
include PhlexConcerns::Links
# Options for CommonMarker
def default_commonmarker_options
{
render: {
unsafe: true
}
}
end
def code_block(source, me... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | app/views/components/markdown/base.rb | Ruby | bsd-3-clause | 99 | main | 2,946 | # frozen_string_literal: true
require "phlex"
require "commonmarker"
class Markdown::Base < Phlex::HTML
def initialize(content, **options)
@content = content
@options = default_commonmarker_options.merge(options)
end
def view_template
visit(doc)
end
protected
def doc
Commonmarker.parse(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.