Skip to content

Commit

Permalink
fix(partial): update path names
Browse files Browse the repository at this point in the history
  • Loading branch information
Marten Klitzke committed Dec 1, 2018
1 parent 324bbd1 commit 55b86ae
Show file tree
Hide file tree
Showing 37 changed files with 928 additions and 69 deletions.
87 changes: 87 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
AllCops:
Exclude:
- 'node_modules/**/*'
- 'db/**/*'
- 'tmp/**/*'
- 'vendor/**/*'
- 'bin/**/*'
- 'log/**/*'
- 'Brewfile'
- 'Rakefile'

Rails:
Enabled: true

Style/Documentation:
Enabled: false # for now

Style/Lambda:
Enabled: false

Style/RaiseArgs:
Enabled: false

Naming/FileName:
Enabled: false

# User.all.map do |user|
# [user.name, user.children.map(&:names)]
# end.flatten.map do |name|
# name.capitalize
# end.join(", ")
Style/MultilineBlockChain:
Enabled: false

# [
# "foo",
# "bar",
# ]
Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false

Layout/RescueEnsureAlignment:
Enabled: false

Style/AccessModifierDeclarations:
EnforcedStyle: inline

Metrics/LineLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/MethodLength:
Max: 40

Metrics/BlockLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Metrics/CyclomaticComplexity:
Max: 10

# `fail` is seldom/never seen in Ruby code.
# https://github.com/bbatsov/ruby-style-guide/issues/233
Style/SignalException:
EnforcedStyle: only_raise

# Would complain about `new_record?` otherwise
Style/TrivialAccessors:
ExactNameMatch: true

Rails/Delegate:
Exclude:
- lib/**/*
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.5.1
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in dynamic_fields_for_rails.gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/setup'
Bundler::GemHelper.install_tasks

Expand Down
23 changes: 14 additions & 9 deletions app/helpers/dynamic_fields_for_helper.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# encoding: utf-8
# frozen_string_literal: true

module DynamicFieldsForHelper
def link_to_add_fields(form, association, options = {}, &block)
partial = options[:partial] || nil
name = options[:name] || nil
css_classes = options[:class] || nil
target = options[:target] || nil

new_object = form.object.send(association).klass.new
id = new_object.object_id

fields = form.fields_for(association, new_object, child_index: id) do |builder|
if partial
render("#{form.object.class.name.downcase.pluralize}/#{partial}", fields: builder)
render("#{form.object.class.name.underscore.pluralize}/#{partial}", fields: builder)
else
render("#{form.object.class.name.downcase.pluralize}/#{association.to_s.singularize}_fields", fields: builder)
render("#{form.object.class.name.underscore.pluralize}/#{association.to_s.singularize}_fields", fields: builder)
end
end

css_classes = css_classes(DynamicFieldsForRails.add_css_classes, css_classes)

if block_given?
link_to('#', class: css_classes, data: { id: id, fields: fields.delete("\n"), target: target }, &block)
else
Expand All @@ -30,20 +33,22 @@ def link_to_delete_fields(fields, options = {}, &block)
link = []
link << fields.hidden_field(:_destroy) unless fields.object.new_record?
css_classes = css_classes(DynamicFieldsForRails.delete_css_classes, css_classes)

link << if block_given?
link_to('#', class: css_classes, title: name, &block)
else
link_to(name, '#', class: css_classes)
end

# rubocop:disable Rails/OutputSafety
link.join('').html_safe
# rubocop:enable Rails/OutputSafety
end

protected

def css_classes(default, css_class)
protected def css_classes(default, css_class)
style_class = []
style_class << default unless default.blank?
style_class << css_class unless css_class.blank?
style_class << default if default.present?
style_class << css_class if css_class.present?
style_class.join(' ')
end
end
27 changes: 14 additions & 13 deletions dynamic_fields_for_rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'dynamic_fields_for_rails/version'

Gem::Specification.new do |spec|
spec.name = "dynamic_fields_for_rails"
spec.name = 'dynamic_fields_for_rails'
spec.version = DynamicFieldsForRails::VERSION
spec.authors = ["Marten Klitzke"]
spec.email = ["[email protected]"]
spec.authors = ['Marten Klitzke']
spec.email = ['[email protected]']
spec.description = 'Dynamic fields helper for Rails.'
spec.summary = 'Helper for nested forms with dynamic fields.'
spec.homepage = "https://github.com/mortik/dynamic_fields_for_rails"
spec.license = "MIT"
spec.homepage = 'https://github.com/mortik/dynamic_fields_for_rails'
spec.license = 'MIT'

spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake", '~> 0'
spec.add_development_dependency "mocha", '~> 0'
spec.add_development_dependency "sqlite3", '~> 0'
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'mocha', '~> 1'
spec.add_development_dependency 'rake', '~> 12'
spec.add_development_dependency 'sqlite3', '~> 1'

spec.add_dependency "rails", '>= 3.0.0', '< 6.0.0'
spec.add_dependency 'rails', '>= 3.0.0', '< 6.0.0'
end
10 changes: 7 additions & 3 deletions lib/dynamic_fields_for_rails.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
require "dynamic_fields_for_rails/version"
# frozen_string_literal: true

require 'dynamic_fields_for_rails/version'

# rubocop:disable Style/ClassVars
module DynamicFieldsForRails
class Engine < Rails::Engine
end

mattr_accessor :add_css_classes
@@add_css_classes = "add_fields"
@@add_css_classes = 'add_fields'

mattr_accessor :delete_css_classes
@@delete_css_classes = "remove_fields"
@@delete_css_classes = 'remove_fields'

def self.setup
yield self
end
end
# rubocop:enable Style/ClassVars
4 changes: 3 additions & 1 deletion lib/dynamic_fields_for_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module DynamicFieldsForRails
VERSION = "0.7.0".freeze
VERSION = '0.7.0'
end
5 changes: 5 additions & 0 deletions test/config/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

# rubocop:disable ClassAndModuleChildren
# rubocop:disable Style/ClassVars
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
Expand All @@ -7,4 +10,6 @@ def self.connection
@@shared_connection || retrieve_connection
end
end
# rubocop:enable Style/ClassVars
# rubocop:enable ClassAndModuleChildren
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
4 changes: 3 additions & 1 deletion test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require File.expand_path('config/application', __dir__)
require 'rake'

Dummy::Application.load_tasks
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
protect_from_forgery
end
2 changes: 2 additions & 0 deletions test/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
5 changes: 5 additions & 0 deletions test/dummy/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
4 changes: 3 additions & 1 deletion test/dummy/app/models/child.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class Child < ActiveRecord::Base
# frozen_string_literal: true

class Child < ApplicationRecord
end
4 changes: 3 additions & 1 deletion test/dummy/app/models/parent.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Parent < ActiveRecord::Base
# frozen_string_literal: true

class Parent < ApplicationRecord
has_many :children
accepts_nested_attributes_for :children, allow_destroy: true
end
2 changes: 2 additions & 0 deletions test/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
Expand Down
12 changes: 8 additions & 4 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require File.expand_path('../boot', __FILE__)
# frozen_string_literal: true

require "rails/all"
require File.expand_path('boot', __dir__)

require 'rails/all'

Bundler.require
require "dynamic_fields_for_rails"
require 'dynamic_fields_for_rails'

module Dummy
class Application < Rails::Application
Expand Down Expand Up @@ -33,9 +35,11 @@ class Application < Rails::Application
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)

# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
config.encoding = 'utf-8'

# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]

config.active_record.sqlite3.represent_boolean_as_integer = true
end
end
6 changes: 4 additions & 2 deletions test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require 'rubygems'
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
gemfile = File.expand_path('../../../Gemfile', __dir__)

if File.exist?(gemfile)
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
end

$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
4 changes: 3 additions & 1 deletion test/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# Load the rails application
require File.expand_path('../application', __FILE__)
require File.expand_path('application', __dir__)

# Initialize the rails application
Dummy::Application.initialize!
2 changes: 2 additions & 0 deletions test/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

Expand Down
4 changes: 3 additions & 1 deletion test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

Expand All @@ -11,7 +13,7 @@
config.action_controller.perform_caching = true

# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
config.action_dispatch.x_sendfile_header = 'X-Sendfile'

# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new mime types for use in respond_to blocks:
Expand Down
Loading

0 comments on commit 55b86ae

Please sign in to comment.