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
/* | |
* Wrap file input like this. | |
* <span class="file-wrapper"> | |
* <span class="class-for-your-custom-button">Choose a Photo</span> | |
* <input type="file" name="photo" id="photo" /> | |
* </span> | |
*/ | |
.file-wrapper { | |
cursor: pointer; | |
overflow: hidden; |
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
$(function(){ | |
$(document).on('change', '[data-checkbox-all]', function(){ | |
var $self = $(this); | |
var target = $self.data('checkbox-all'); | |
$('[data-checkbox=' + target + '],[data-checkbox-all=' + target + ']').prop('checked', $self.prop('checked')); | |
}); | |
$(document).on('change', '[data-checkbox]', function(){ | |
var $self = $(this); | |
var target = $self.data('checkbox'); | |
var $checkboxes = $('[data-checkbox=' + target + ']'); |
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 MultiIO | |
def initialize(*targets) | |
@targets = targets.map{ |t|t.is_a?(String) ? open(t, 'a') : t } | |
end | |
def write(*args) | |
@targets.each{ |t| t.write(*args) } | |
end | |
def close |
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
def do_if_updated(tag, *sources, &block) | |
to = (latest_revision rescue nil) | |
from = (current_revision rescue nil) | |
doit = if !from || !to || !fetch(:smart_assets_precompile, true) | |
true | |
else | |
run_locally("#{source.local.log(from, to)} #{sources.join(' ')} | wc -l").to_i > 0 | |
end | |
if doit | |
block.call |
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 'net/http' | |
class UriValidator < ActiveModel::EachValidator | |
def validate_each(object, attribute, value) | |
raise(ArgumentError, "A regular expression must be supplied as the :format option of the options hash") unless options[:format].nil? or options[:format].is_a?(Regexp) | |
#configuration = { message: "is invalid or not responding", format: URI::regexp(%w(http https)) } | |
configuration = { check_response: true, format: /(\A\z)|(\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?([\/].*)?\z)/ix} | |
configuration.update(options) | |
if value =~ configuration[:format] | |
if configuration[:check_response] | |
begin # check header response |
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 'mail' | |
class EmailValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
begin | |
m = Mail::Address.new(value) | |
# We must check that value contains a domain and that value is an email address | |
r = m.domain && m.address == value | |
t = m.__send__(:tree) | |
# We need to dig into treetop | |
# A valid domain must have dot_atom_text elements size > 1 |
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 TimeValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
flg = true | |
if de = options[:before] | |
de = Time.now if de == :now | |
flg &&= value <= de | |
end | |
if de = options[:after] | |
de = Time.now if de == :now | |
flg &&= de <= value |
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 ByteSizeValidator < ActiveModel::Validations::LengthValidator | |
def validate_each(record, attribute, value) | |
value_length = value.respond_to?(:bytesize) ? value.bytesize : value.to_s.bytesize | |
CHECKS.each do |key, validity_check| | |
next unless check_value = options[key] | |
next if value_length.send(validity_check, check_value) | |
errors_options = options.except(*RESERVED_OPTIONS) | |
errors_options[:count] = check_value |
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
if Settings.mailer && Settings.mailer.interceptors | |
class SandboxEmailInterceptor | |
def self.delivering_email(message) | |
whitelist = [Settings.mailer.whitelist].flatten.compact | |
blacklist = [Settings.mailer.blacklist].flatten.compact | |
allowed = [message.to].flatten.all?{|t| whitelist.any?{|r| r.is_a?(Regexp) ? r =~ t : r == t } } | |
prohibited = [message.to].flatten.all?{|t| blacklist.any?{|r| r.is_a?(Regexp) ? r =~ t : r == t } } | |
if prohibited || !allowed | |
Rails.logger.debug "Intercept email for #{message.to.inspect}" | |
message.to = [Settings.mailer.interceptors].flatten |
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
case class BatchTriggerTick() |
OlderNewer