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
varvet/pundit
https://github.com/varvet/pundit
lib/generators/test_unit/policy_generator.rb
Ruby
mit
8,500
main
388
# frozen_string_literal: true # @private module TestUnit # @private module Generators # @private class PolicyGenerator < ::Rails::Generators::NamedBase source_root File.expand_path("templates", __dir__) def create_policy_test template "policy_test.rb.tt", File.join("test/policies", cla...
github
varvet/pundit
https://github.com/varvet/pundit
spec/authorization_spec.rb
Ruby
mit
8,500
main
13,115
# frozen_string_literal: true require "spec_helper" require "action_controller" RSpec.describe Pundit::Authorization do def to_params(*args, **kwargs, &block) ActionController::Parameters.new(*args, **kwargs, &block) end let(:controller) { Controller.new(user, "update", to_params({})) } let(:user) { doub...
github
varvet/pundit
https://github.com/varvet/pundit
spec/pundit_spec.rb
Ruby
mit
8,500
main
18,418
# frozen_string_literal: true require "spec_helper" RSpec.describe Pundit do let(:user) { double } let(:post) { Post.new(user) } let(:customer_post) { Customer::Post.new(user) } let(:post_four_five_six) { PostFourFiveSix.new(user) } let(:comment) { Comment.new } let(:comment_four_five_six) { CommentFourFi...
github
varvet/pundit
https://github.com/varvet/pundit
spec/rspec_dsl_spec.rb
Ruby
mit
8,500
main
2,670
# frozen_string_literal: true require "spec_helper" RSpec.describe "Pundit RSpec DSL", type: :policy do let(:fake_rspec) do double = class_double(RSpec::Core::ExampleGroup) double.extend(::Pundit::RSpec::DSL) double end let(:block) { proc { "block content" } } let(:user) { double } let(:other_u...
github
varvet/pundit
https://github.com/varvet/pundit
spec/spec_helper.rb
Ruby
mit
8,500
main
937
# frozen_string_literal: true if ENV["COVERAGE"] require "simplecov" require "simplecov_json_formatter" SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::JSONFormatter ]) SimpleCov.start do enable_coverage :branch pr...
github
varvet/pundit
https://github.com/varvet/pundit
spec/generators_spec.rb
Ruby
mit
8,500
main
1,209
# frozen_string_literal: true require "spec_helper" require "tmpdir" require "rails/generators" require "generators/pundit/install/install_generator" require "generators/pundit/policy/policy_generator" RSpec.describe "generators" do before(:all) do @tmpdir = Dir.mktmpdir Dir.chdir(@tmpdir) do Pundit...
github
varvet/pundit
https://github.com/varvet/pundit
spec/policy_finder_spec.rb
Ruby
mit
8,500
main
5,301
# frozen_string_literal: true require "spec_helper" RSpec.describe Pundit::PolicyFinder do let(:user) { double } let(:post) { Post.new(user) } let(:comment) { CommentFourFiveSix.new } let(:article) { Article.new } describe "SUFFIX" do specify { expect(described_class::SUFFIX).to eq "Policy" } speci...
github
varvet/pundit
https://github.com/varvet/pundit
spec/policies/post_policy_spec.rb
Ruby
mit
8,500
main
1,601
# frozen_string_literal: true require "spec_helper" RSpec.describe PostPolicy do let(:user) { double } let(:own_post) { double(user: user) } let(:other_post) { double(user: double) } subject { described_class } permissions :update?, :show? do it "is successful when all permissions match" do is_ex...
github
varvet/pundit
https://github.com/varvet/pundit
spec/pundit/helper_spec.rb
Ruby
mit
8,500
main
458
# frozen_string_literal: true require "spec_helper" RSpec.describe Pundit::Helper do let(:user) { double } let(:controller) { Controller.new(user, "update", double) } let(:view) { Controller::View.new(controller) } describe "#policy_scope" do it "doesn't flip pundit_policy_scoped?" do scoped = view...
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/models/post.rb
Ruby
mit
8,500
main
224
# frozen_string_literal: true class Post def initialize(user = nil) @user = user end attr_reader :user def self.published :published end def self.read :read end def to_s "Post" end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/models/comment_scope.rb
Ruby
mit
8,500
main
233
# frozen_string_literal: true class CommentScope attr_reader :original_object def initialize(original_object) @original_object = original_object end def ==(other) original_object == other.original_object end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/lib/instance_tracking.rb
Ruby
mit
8,500
main
318
# frozen_string_literal: true module InstanceTracking module ClassMethods def instances @instances || 0 end attr_writer :instances end def self.prepended(other) other.extend(ClassMethods) end def initialize(*args, **kwargs, &block) self.class.instances += 1 super end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/lib/controller.rb
Ruby
mit
8,500
main
840
# frozen_string_literal: true class Controller attr_accessor :current_user attr_reader :action_name, :params class View def initialize(controller) @controller = controller end attr_reader :controller end class << self def helper(mod) View.include(mod) end def helper_me...
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/lib/custom_cache.rb
Ruby
mit
8,500
main
211
# frozen_string_literal: true class CustomCache def initialize @store = {} end def to_h @store end def [](key) @store[key] end def []=(key, value) @store[key] = value end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/post_policy.rb
Ruby
mit
8,500
main
701
# frozen_string_literal: true class PostPolicy < BasePolicy class Scope < BaseScope def resolve scope.published end end alias_method :post, :record def update? post.user == user end alias_method :edit?, :update? def destroy? false end def show? true end def permitte...
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/base_policy.rb
Ruby
mit
8,500
main
351
# frozen_string_literal: true class BasePolicy prepend InstanceTracking class BaseScope prepend InstanceTracking def initialize(user, scope) @user = user @scope = scope end attr_reader :user, :scope end def initialize(user, record) @user = user @record = record end ...
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/default_scope_contains_error_policy.rb
Ruby
mit
8,500
main
250
# frozen_string_literal: true class DefaultScopeContainsErrorPolicy < BasePolicy class Scope < BaseScope def resolve # deliberate wrong usage of the method raise "This is an arbitrary error that should bubble up" end end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/nil_class_policy.rb
Ruby
mit
8,500
main
212
# frozen_string_literal: true class NilClassPolicy < BasePolicy class Scope def initialize(*) raise Pundit::NotDefinedError, "Cannot scope NilClass" end end def destroy? false end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/project/comment_policy.rb
Ruby
mit
8,500
main
241
# frozen_string_literal: true module Project class CommentPolicy < BasePolicy class Scope < BaseScope def resolve scope end end def update? true end alias_method :comment, :record end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/project/post_policy.rb
Ruby
mit
8,500
main
204
# frozen_string_literal: true module Project class PostPolicy < BasePolicy class Scope < BaseScope def resolve scope.read end end alias_method :post, :record end end
github
varvet/pundit
https://github.com/varvet/pundit
spec/support/policies/project/admin/comment_policy.rb
Ruby
mit
8,500
main
201
# frozen_string_literal: true module Project module Admin class CommentPolicy < BasePolicy def update? true end def destroy? false end end end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
simple_form.gemspec
Ruby
mit
8,220
main
1,431
# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "simple_form/version" Gem::Specification.new do |s| s.name = "simple_form" s.version = SimpleForm::VERSION.dup s.platform = Gem::Platform::RUBY s.summary = "Forms made easy!" s.email = "heartcombo.oss@gmail...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
Rakefile
Ruby
mit
8,220
main
674
# encoding: UTF-8 require 'bundler/gem_tasks' require 'rake/testtask' desc 'Default: run unit tests.' task default: :test desc 'Test the simple_form plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = true end begin require 'rdoc/task' ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form.rb
Ruby
mit
8,220
main
11,300
# frozen_string_literal: true require 'action_view' require 'action_pack' require 'simple_form/action_view_extensions/form_helper' require 'simple_form/action_view_extensions/builder' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/reverse...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/helpers.rb
Ruby
mit
8,220
main
591
# frozen_string_literal: true module SimpleForm # Helpers are made of several helpers that cannot be turned on automatically. # For instance, disabled cannot be turned on automatically, it requires the # user to explicitly pass the option disabled: true so it may work. module Helpers autoload :Autofocus, '...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/wrappers.rb
Ruby
mit
8,220
main
336
# frozen_string_literal: true module SimpleForm module Wrappers autoload :Builder, 'simple_form/wrappers/builder' autoload :Many, 'simple_form/wrappers/many' autoload :Root, 'simple_form/wrappers/root' autoload :Single, 'simple_form/wrappers/single' autoload :Leaf, 'simple_form/wrappers/...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/error_notification.rb
Ruby
mit
8,220
main
1,153
# frozen_string_literal: true module SimpleForm class ErrorNotification delegate :object, :object_name, :template, to: :@builder def initialize(builder, options) @builder = builder @message = options.delete(:message) @options = options end def render if has_errors? te...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components.rb
Ruby
mit
8,220
main
782
# frozen_string_literal: true module SimpleForm # Components are a special type of helpers that can work on their own. # For example, by using a component, it will automatically change the # output under given circumstances without user input. For example, # the disabled helper always need a disabled: true opti...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/map_type.rb
Ruby
mit
8,220
main
476
# frozen_string_literal: true require 'active_support/core_ext/class/attribute' module SimpleForm module MapType def self.extended(base) base.class_attribute :mappings base.mappings = {} end def map_type(*types) map_to = types.extract_options![:to] raise ArgumentError, "You need ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/form_builder.rb
Ruby
mit
8,220
main
29,222
# frozen_string_literal: true require 'active_support/core_ext/object/deep_dup' require 'simple_form/map_type' require 'simple_form/tags' module SimpleForm class FormBuilder < ActionView::Helpers::FormBuilder attr_reader :template, :object_name, :object, :wrapper # When action is create or update, we still ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/tags.rb
Ruby
mit
8,220
main
2,369
# frozen_string_literal: true module SimpleForm module Tags module CollectionExtensions private def render_collection item_wrapper_tag = @options.fetch(:item_wrapper_tag, :span) item_wrapper_class = @options[:item_wrapper_class] @collection.map do |item| value = v...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/railtie.rb
Ruby
mit
8,220
main
611
# frozen_string_literal: true require 'rails/railtie' module SimpleForm class Railtie < Rails::Railtie config.eager_load_namespaces << SimpleForm config.after_initialize do unless SimpleForm.configured? warn '[Simple Form] Simple Form is not configured in the application and will use the defau...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs.rb
Ruby
mit
8,220
main
692
# frozen_string_literal: true module SimpleForm module Inputs extend ActiveSupport::Autoload autoload :Base autoload :BlockInput autoload :BooleanInput autoload :CollectionCheckBoxesInput autoload :CollectionInput autoload :CollectionRadioButtonsInput autoload :CollectionSelectInput ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/weekday_input.rb
Ruby
mit
8,220
main
381
# frozen_string_literal: true module SimpleForm module Inputs class WeekdayInput < CollectionSelectInput enable :placeholder def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.weekday_select(attribute_name, inpu...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/boolean_input.rb
Ruby
mit
8,220
main
3,831
# frozen_string_literal: true module SimpleForm module Inputs class BooleanInput < Base def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) if nested_boolean_style? build_hidden_field_for_checkbox + templat...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/text_input.rb
Ruby
mit
8,220
main
365
# frozen_string_literal: true module SimpleForm module Inputs class TextInput < Base enable :placeholder, :maxlength, :minlength def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.text_area(attribute_name, merge...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/base.rb
Ruby
mit
8,220
main
7,752
# frozen_string_literal: true require 'active_support/core_ext/string/output_safety' require 'action_view/helpers' module SimpleForm module Inputs class Base include ERB::Util include ActionView::Helpers::TranslationHelper include SimpleForm::Helpers::Autofocus include SimpleForm::Helper...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/file_input.rb
Ruby
mit
8,220
main
315
# frozen_string_literal: true module SimpleForm module Inputs class FileInput < Base def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.file_field(attribute_name, merged_input_options) end end end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/hidden_input.rb
Ruby
mit
8,220
main
431
# frozen_string_literal: true module SimpleForm module Inputs class HiddenInput < Base disable :label, :errors, :hint, :required def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.hidden_field(attribute_name, me...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/date_time_input.rb
Ruby
mit
8,220
main
1,038
# frozen_string_literal: true module SimpleForm module Inputs class DateTimeInput < Base def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) if use_html5_inputs? @builder.send(:"#{input_type}_field", attribute_name, me...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/block_input.rb
Ruby
mit
8,220
main
277
# frozen_string_literal: true module SimpleForm module Inputs class BlockInput < Base def initialize(*args, &block) super @block = block end def input(wrapper_options = nil) template.capture(&@block) end end end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/rich_text_area_input.rb
Ruby
mit
8,220
main
354
# frozen_string_literal: true module SimpleForm module Inputs class RichTextAreaInput < Base enable :placeholder def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.rich_text_area(attribute_name, merged_input_opt...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/grouped_collection_select_input.rb
Ruby
mit
8,220
main
1,824
# frozen_string_literal: true module SimpleForm module Inputs class GroupedCollectionSelectInput < CollectionInput def input(wrapper_options = nil) label_method, value_method = detect_collection_methods merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/color_input.rb
Ruby
mit
8,220
main
373
# frozen_string_literal: true module SimpleForm module Inputs class ColorInput < Base def input(wrapper_options = nil) input_html_options[:type] ||= "color" if html5? merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.text_field(attribute_nam...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/collection_radio_buttons_input.rb
Ruby
mit
8,220
main
1,999
# frozen_string_literal: true module SimpleForm module Inputs class CollectionRadioButtonsInput < CollectionInput def input(wrapper_options = nil) label_method, value_method = detect_collection_methods merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/numeric_input.rb
Ruby
mit
8,220
main
542
# frozen_string_literal: true module SimpleForm module Inputs class NumericInput < Base enable :placeholder, :min_max def input(wrapper_options = nil) input_html_classes.unshift("numeric") if html5? input_html_options[:type] ||= "number" input_html_options[:step] |...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/password_input.rb
Ruby
mit
8,220
main
374
# frozen_string_literal: true module SimpleForm module Inputs class PasswordInput < Base enable :placeholder, :maxlength, :minlength def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.password_field(attribute_na...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/collection_input.rb
Ruby
mit
8,220
main
4,168
# frozen_string_literal: true module SimpleForm module Inputs class CollectionInput < Base BASIC_OBJECT_CLASSES = [String, Integer, Float, NilClass, Symbol, TrueClass, FalseClass] BASIC_OBJECT_CLASSES.push(Fixnum, Bignum) unless 1.class == Integer # Default boolean collection for use with selec...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/priority_input.rb
Ruby
mit
8,220
main
1,051
# frozen_string_literal: true module SimpleForm module Inputs class PriorityInput < CollectionSelectInput def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) send(:"#{input_type}_input", merged_input_options) end de...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/range_input.rb
Ruby
mit
8,220
main
302
# frozen_string_literal: true module SimpleForm module Inputs class RangeInput < NumericInput def input(wrapper_options = nil) if html5? input_html_options[:type] ||= "range" input_html_options[:step] ||= 1 end super end end end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/collection_check_boxes_input.rb
Ruby
mit
8,220
main
572
# frozen_string_literal: true module SimpleForm module Inputs class CollectionCheckBoxesInput < CollectionRadioButtonsInput protected # Checkbox components do not use the required html tag. # More info: https://github.com/heartcombo/simple_form/issues/340#issuecomment-2871956 def has_requ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/string_input.rb
Ruby
mit
8,220
main
621
# frozen_string_literal: true module SimpleForm module Inputs class StringInput < Base enable :placeholder, :maxlength, :minlength, :pattern def input(wrapper_options = nil) unless string? input_html_classes.unshift("string") input_html_options[:type] ||= input_type if htm...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/inputs/collection_select_input.rb
Ruby
mit
8,220
main
494
# frozen_string_literal: true module SimpleForm module Inputs class CollectionSelectInput < CollectionInput def input(wrapper_options = nil) label_method, value_method = detect_collection_methods merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @bui...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/helpers/required.rb
Ruby
mit
8,220
main
827
# frozen_string_literal: true module SimpleForm module Helpers module Required private def required_field? @required end def calculate_required if !options[:required].nil? options[:required] elsif has_validators? required_by_validators? ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/helpers/readonly.rb
Ruby
mit
8,220
main
258
# frozen_string_literal: true module SimpleForm module Helpers module Readonly private def readonly_class :readonly if has_readonly? end def has_readonly? options[:readonly] == true end end end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/helpers/disabled.rb
Ruby
mit
8,220
main
258
# frozen_string_literal: true module SimpleForm module Helpers module Disabled private def has_disabled? options[:disabled] == true end def disabled_class :disabled if has_disabled? end end end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/helpers/validators.rb
Ruby
mit
8,220
main
1,717
# frozen_string_literal: true module SimpleForm module Helpers module Validators def has_validators? @has_validators ||= attribute_name && object.class.respond_to?(:validators_on) end private def attribute_validators object.class.validators_on(attribute_name) end ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/action_view_extensions/builder.rb
Ruby
mit
8,220
main
1,222
# frozen_string_literal: true module SimpleForm module ActionViewExtensions # A collection of methods required by simple_form but added to rails default form. # This means that you can use such methods outside simple_form context. module Builder # Wrapper for using SimpleForm inside a default rails...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/action_view_extensions/form_helper.rb
Ruby
mit
8,220
main
2,345
# frozen_string_literal: true module SimpleForm module ActionViewExtensions # This module creates SimpleForm wrappers around default form_for and fields_for. # # Example: # # simple_form_for @user do |f| # f.input :name, hint: 'My hint' # end # module FormHelper def ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/wrappers/single.rb
Ruby
mit
8,220
main
684
# frozen_string_literal: true module SimpleForm module Wrappers # `Single` is an optimization for a wrapper that has only one component. class Single < Many def initialize(name, wrapper_options = {}, options = {}) @component = Leaf.new(name, options) super(name, [@component], wrapper_op...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/wrappers/leaf.rb
Ruby
mit
8,220
main
601
# frozen_string_literal: true module SimpleForm module Wrappers class Leaf attr_reader :namespace def initialize(namespace, options = {}) @namespace = namespace @options = options end def render(input) method = input.method(@namespace) if method.arity.zer...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/wrappers/root.rb
Ruby
mit
8,220
main
1,318
# frozen_string_literal: true module SimpleForm module Wrappers # `Root` is the root wrapper for all components. It is special cased to # always have a namespace and to add special html classes. class Root < Many attr_reader :options def initialize(*args) super(:wrapper, *args) ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/wrappers/many.rb
Ruby
mit
8,220
main
2,243
# frozen_string_literal: true module SimpleForm module Wrappers # A wrapper is an object that holds several components and render them. # A component may be any object that responds to `render`. # This API allows inputs/components to be easily wrapped, removing the # need to modify the code only to wr...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/wrappers/builder.rb
Ruby
mit
8,220
main
2,684
# frozen_string_literal: true module SimpleForm module Wrappers # Provides the builder syntax for components. The builder provides # three methods `use`, `optional` and `wrapper` and they allow the following invocations: # # config.wrappers do |b| # # Use a single component # b...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/errors.rb
Ruby
mit
8,220
main
1,829
# frozen_string_literal: true module SimpleForm module Components module Errors def error(wrapper_options = nil) error_text if has_errors? end def full_error(wrapper_options = nil) full_error_text if options[:error] != false && has_errors? end def has_errors? ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/label_input.rb
Ruby
mit
8,220
main
837
# frozen_string_literal: true module SimpleForm module Components module LabelInput extend ActiveSupport::Concern included do include SimpleForm::Components::Labels end def label_input(wrapper_options = nil) if options[:label] == false deprecated_component(:inpu...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/min_max.rb
Ruby
mit
8,220
main
1,176
# frozen_string_literal: true module SimpleForm module Components module MinMax def min_max(wrapper_options = nil) if numeric_validator = find_numericality_validator validator_options = numeric_validator.options input_html_options[:min] ||= minimum_value(validator_options) ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/readonly.rb
Ruby
mit
8,220
main
600
# frozen_string_literal: true module SimpleForm module Components # Needs to be enabled in order to do automatic lookups. module Readonly def readonly(wrapper_options = nil) if readonly_attribute? && !has_readonly? input_html_options[:readonly] ||= true input_html_classes << ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/minlength.rb
Ruby
mit
8,220
main
933
# frozen_string_literal: true module SimpleForm module Components # Needs to be enabled in order to do automatic lookups. module Minlength def minlength(wrapper_options = nil) input_html_options[:minlength] ||= minimum_length_from_validation nil end private def minimu...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/hints.rb
Ruby
mit
8,220
main
547
# frozen_string_literal: true module SimpleForm module Components # Needs to be enabled in order to do automatic lookups. module Hints def hint(wrapper_options = nil) @hint ||= begin hint = options[:hint] if hint.is_a?(String) html_escape(hint) else ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/html5.rb
Ruby
mit
8,220
main
783
# frozen_string_literal: true module SimpleForm module Components module HTML5 def initialize(*) @html5 = false end def html5(wrapper_options = nil) @html5 = true input_html_options[:required] = input_html_required_option input_html_options[:'aria-invalid...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/labels.rb
Ruby
mit
8,220
main
2,605
# frozen_string_literal: true module SimpleForm module Components module Labels extend ActiveSupport::Concern module ClassMethods #:nodoc: def translate_required_html I18n.t(:"required.html", scope: i18n_scope, default: %(<abbr title="#{translate_required_text}">#{transl...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/maxlength.rb
Ruby
mit
8,220
main
942
# frozen_string_literal: true module SimpleForm module Components # Needs to be enabled in order to do automatic lookups. module Maxlength def maxlength(wrapper_options = nil) input_html_options[:maxlength] ||= maximum_length_from_validation || limit nil end private d...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/pattern.rb
Ruby
mit
8,220
main
661
# frozen_string_literal: true module SimpleForm module Components # Needs to be enabled in order to do automatic lookups. module Pattern def pattern(wrapper_options = nil) input_html_options[:pattern] ||= pattern_source nil end private def pattern_source patte...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/simple_form/components/placeholders.rb
Ruby
mit
8,220
main
494
# frozen_string_literal: true module SimpleForm module Components # Needs to be enabled in order to do automatic lookups. module Placeholders def placeholder(wrapper_options = nil) input_html_options[:placeholder] ||= placeholder_text nil end def placeholder_text(wrapper_opt...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/generators/simple_form/install_generator.rb
Ruby
mit
8,220
main
1,573
# frozen_string_literal: true module SimpleForm module Generators class InstallGenerator < Rails::Generators::Base desc "Copy SimpleForm default files" source_root File.expand_path('../templates', __FILE__) class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb
Ruby
mit
8,220
main
4,339
# frozen_string_literal: true # # Uncomment this and change the path if necessary to include your own # components. # See https://github.com/heartcombo/simple_form#custom-components to know # more about custom components. # Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f } # # Use this setup block t...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
Ruby
mit
8,220
main
14,068
# frozen_string_literal: true # These defaults are defined and maintained by the community at # https://github.com/heartcombo/simple_form-bootstrap # Please submit feedback, changes and tests only there. # Uncomment this and change the path if necessary to include your own # components. # See https://github.com/heart...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
lib/generators/simple_form/templates/config/initializers/simple_form.rb
Ruby
mit
8,220
main
6,905
# frozen_string_literal: true # # Uncomment this and change the path if necessary to include your own # components. # See https://github.com/heartcombo/simple_form#custom-components to know # more about custom components. # Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f } # # Use this setup block t...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/test_helper.rb
Ruby
mit
8,220
main
2,141
# frozen_string_literal: true require 'minitest/autorun' require 'active_model' require 'action_controller' require 'action_view' ActionView::RoutingUrlFor.include ActionDispatch::Routing::UrlFor require 'action_view/template' require 'action_view/test_case' module Rails def self.env ActiveSupport::StringInqu...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/simple_form_test.rb
Ruby
mit
8,220
main
404
# frozen_string_literal: true require 'test_helper' class SimpleFormTest < ActiveSupport::TestCase test 'setup block yields self' do SimpleForm.setup do |config| assert_equal SimpleForm, config end end test 'setup block configure Simple Form' do SimpleForm.setup do |config| assert_equal ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/generators/simple_form_generator_test.rb
Ruby
mit
8,220
main
1,715
# frozen_string_literal: true require 'test_helper' class SimpleFormGeneratorTest < Rails::Generators::TestCase tests SimpleForm::Generators::InstallGenerator destination File.expand_path('../../tmp', __FILE__) setup :prepare_destination teardown { rm_rf(destination_root) } test 'generates example locale fi...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/support/discovery_inputs.rb
Ruby
mit
8,220
main
1,432
# frozen_string_literal: true class StringInput < SimpleForm::Inputs::StringInput def input(wrapper_options = nil) "<section>#{super}</section>".html_safe end end class NumericInput < SimpleForm::Inputs::NumericInput def input(wrapper_options = nil) "<section>#{super}</section>".html_safe end end clas...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/support/misc_helpers.rb
Ruby
mit
8,220
main
7,767
# frozen_string_literal: true module MiscHelpers def store_translations(locale, translations, &block) I18n.backend.store_translations locale, translations yield ensure I18n.reload! I18n.backend.send :init_translations end def assert_no_select(selector, value = nil) assert_select(selector, t...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/support/models.rb
Ruby
mit
8,220
main
9,747
# frozen_string_literal: true Association = Struct.new(:klass, :name, :macro, :scope, :options) Column = Struct.new(:name, :type, :limit) do end Relation = Struct.new(:records) do delegate :each, to: :records def where(conditions = nil) self.class.new conditions ? [records.first] : records end def order...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/support/mock_controller.rb
Ruby
mit
8,220
main
476
# frozen_string_literal: true class MockController attr_writer :action_name def _routes self end def action_name defined?(@action_name) ? @action_name : "edit" end def url_for(*) "http://example.com" end def url_options {} end def polymorphic_mappings(*); {}; end def hash_for...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/action_view_extensions/form_helper_test.rb
Ruby
mit
8,220
main
5,529
# frozen_string_literal: true require 'test_helper' class FormHelperTest < ActionView::TestCase test 'SimpleForm for yields an instance of FormBuilder' do simple_form_for :user do |f| assert f.instance_of?(SimpleForm::FormBuilder) end end test 'SimpleForm adds default class to form' do with_c...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/action_view_extensions/builder_test.rb
Ruby
mit
8,220
main
26,151
# frozen_string_literal: true require 'test_helper' class BuilderTest < ActionView::TestCase def with_custom_form_for(object, *args, &block) with_concat_custom_form_for(object) do |f| assert f.instance_of?(CustomFormBuilder) yield f end end def with_collection_radio_buttons(object, attribute...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/general_test.rb
Ruby
mit
8,220
main
19,327
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class FormBuilderTest < ActionView::TestCase def with_custom_form_for(object, *args, &block) with_concat_custom_form_for(object) do |f| f.input(*args, &block) end end test 'nested simple fields yields an instance of FormBuilder'...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/error_notification_test.rb
Ruby
mit
8,220
main
3,083
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' # Tests for f.error_notification class ErrorNotificationTest < ActionView::TestCase def with_error_notification_for(object, options = {}, &block) with_concat_form_for(object) do |f| f.error_notification(options) end end test 'er...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/input_field_test.rb
Ruby
mit
8,220
main
6,330
# frozen_string_literal: true require 'test_helper' # Tests for f.input_field class InputFieldTest < ActionView::TestCase test "builder input_field only renders the input tag, nothing else" do with_input_field_for @user, :name assert_select 'form > input.required.string' assert_no_select 'div.string' ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/error_test.rb
Ruby
mit
8,220
main
11,677
# frozen_string_literal: true require 'test_helper' # Tests for f.error and f.full_error class ErrorTest < ActionView::TestCase def with_error_for(object, *args) with_concat_form_for(object) do |f| f.error(*args) end end def with_full_error_for(object, *args) with_concat_form_for(object) do |f...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/association_test.rb
Ruby
mit
8,220
main
9,764
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class AssociationTest < ActionView::TestCase def with_association_for(object, *args) with_concat_form_for(object) do |f| f.association(*args) end end test 'builder does not allow creating an association input when no object exis...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/label_test.rb
Ruby
mit
8,220
main
4,892
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class LabelTest < ActionView::TestCase def with_label_for(object, *args, &block) with_concat_form_for(object) do |f| f.label(*args, &block) end end test 'builder generates a label for the attribute' do with_label_for @user, ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/wrapper_test.rb
Ruby
mit
8,220
main
13,274
# frozen_string_literal: true require 'test_helper' class WrapperTest < ActionView::TestCase test 'wrapper does not have error class for attribute without errors' do with_form_for @user, :active assert_no_select 'div.field_with_errors' end test 'wrapper does not have error class when object is not prese...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/button_test.rb
Ruby
mit
8,220
main
1,503
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class ButtonTest < ActionView::TestCase def with_button_for(object, *args) with_concat_form_for(object) do |f| f.button(*args) end end test 'builder creates buttons' do with_button_for :post, :submit assert_select 'form ...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/form_builder/hint_test.rb
Ruby
mit
8,220
main
4,828
# frozen_string_literal: true require 'test_helper' # Tests for f.hint class HintTest < ActionView::TestCase def with_hint_for(object, *args) with_concat_form_for(object) do |f| f.hint(*args) end end test 'hint does not be generated by default' do with_hint_for @user, :name assert_no_selec...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/time_zone_input_test.rb
Ruby
mit
8,220
main
1,140
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class TimeZoneInputTest < ActionView::TestCase test 'input generates a time zone select field' do with_input_for @user, :time_zone, :time_zone assert_select 'select#user_time_zone' assert_select 'select option[value=Brasilia]', '(GMT-0...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/country_input_test.rb
Ruby
mit
8,220
main
1,324
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class CountryInputTest < ActionView::TestCase COUNTRY_SELECT_SEPARATOR = if Gem::Version.new(CountrySelect::VERSION) >= Gem::Version.new("11.0.0") "hr" else 'option[value="---------------"][disabled=disabled]' end test '...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/hidden_input_test.rb
Ruby
mit
8,220
main
951
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class HiddenInputTest < ActionView::TestCase test 'input generates a hidden field' do with_input_for @user, :name, :hidden assert_no_select 'input[type=text]' assert_select 'input#user_name[type=hidden]' end test 'hint does not be...