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 Sanitizable | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| # Usage | |
| # sanitizes :content # strips content by default | |
| # sanitizes :content, with: :squish | |
| # sanitizes :content, with: :presence | |
| # Chain multiple sanitizer methods, they are executed in the order they are defined |
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 Archivable | |
| extend ActiveSupport::Concern | |
| included do | |
| default_scope -> { where(archived_at: nil) } | |
| scope :archived, -> { where.not(archived_at: nil) } | |
| end | |
| def archived? | |
| !archived_at.nil? |
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 Object | |
| def to_b | |
| self.in?(ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) | |
| end | |
| alias_method :to_bool, :to_b | |
| 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
| class Presenter | |
| class_attribute :presenter_options, instance_accessor: false | |
| self.presenter_options ||= {} | |
| attr_reader :object, :template, :options | |
| def initialize(object, template, options = {}) | |
| @object = object | |
| @template = template | |
| @options = options.reverse_merge(self.class.presenter_options) |
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 Enumerable | |
| def group_by_first | |
| inject({}) do |hash, element| | |
| key = yield(element) | |
| hash[key] ||= element | |
| hash | |
| end | |
| end | |
| def group_by_last(&block) |
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 Gravatar | |
| DEFAULTS = { | |
| default: :not_found, | |
| force_default: false, | |
| size: 100, | |
| secure: false | |
| }.freeze | |
| INSECURE_URL = 'http://www.gravatar.com/avatar/%{hash}' | |
| SECURE_URL = 'https://secure.gravatar.com/avatar/%{hash}' | |
| VALID_OPTIONS = :size, :default, :rating, :secure, :force_default |
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 FontAwesome::Icon < FontAwesome::Iconish | |
| VALID_OPTIONS = :shape, :direction, :outline, :spin, :size, :rotate, :flip, :inverse, :border, :fixed_width | |
| attr_reader :name | |
| def initialize(name, options = {}) | |
| @name = name | |
| @html_options = options.except(*VALID_OPTIONS) | |
| @options = options.slice(*VALID_OPTIONS).reverse_merge( | |
| border: false, |
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
| # Usage: | |
| # | |
| # object = MyObject.new | |
| # object.label = "Some content here..." | |
| # | |
| # object.try_first([:name, :label, :caption]) # => "Some content here..." | |
| # object.try_first(:description) # => nil | |
| class Object | |
| def try_first(method_names, *args, &block) |
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
| window.I18n ||= {} | |
| VALID_OPTIONS = ['scope', 'locale', 'default', 'fallbacks'] | |
| humanizeKeypath = (keypath) -> | |
| console.warn "I18n: no translation found for #{keypath}" | |
| _(keypath.split('.')).chain().last().humanize().value() | |
| sanitizeKeypath = (keypath) -> | |
| str = "" |
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 Object | |
| def is_one_of?(*classes) | |
| classes.any? { |klass| self.is_a?(klass) } | |
| end | |
| end |
OlderNewer