cocooned 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +178 -0
- data/README.md +244 -172
- data/app/assets/javascripts/cocoon.js +1 -13
- data/app/assets/javascripts/cocooned.js +929 -399
- data/app/assets/stylesheets/cocooned.css +1 -9
- data/cocooned.gemspec +27 -18
- data/lib/cocooned/association/builder.rb +66 -0
- data/lib/cocooned/association/renderer.rb +53 -0
- data/lib/cocooned/association.rb +8 -0
- data/lib/cocooned/deprecation.rb +105 -0
- data/lib/cocooned/helpers/containers.rb +72 -0
- data/lib/cocooned/helpers/tags/add.rb +136 -0
- data/lib/cocooned/helpers/tags/down.rb +76 -0
- data/lib/cocooned/helpers/tags/remove.rb +78 -0
- data/lib/cocooned/helpers/tags/up.rb +76 -0
- data/lib/cocooned/helpers/tags.rb +60 -0
- data/lib/cocooned/helpers.rb +3 -329
- data/lib/cocooned/railtie.rb +7 -2
- data/lib/cocooned/tags/add.rb +61 -0
- data/lib/cocooned/tags/base.rb +61 -0
- data/lib/cocooned/tags/down.rb +19 -0
- data/lib/cocooned/tags/remove.rb +35 -0
- data/lib/cocooned/tags/up.rb +19 -0
- data/lib/cocooned/tags.rb +12 -0
- data/lib/cocooned/tags_helper.rb +83 -0
- data/lib/cocooned/version.rb +1 -1
- data/lib/cocooned.rb +6 -1
- metadata +51 -86
- data/History.md +0 -283
- data/Rakefile +0 -113
- data/lib/cocooned/association_builder.rb +0 -68
- data/lib/cocooned/helpers/cocoon_compatibility.rb +0 -27
- data/lib/cocooned/helpers/deprecate.rb +0 -47
data/Rakefile
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
## Test suites
|
4
|
-
|
5
|
-
# Ruby
|
6
|
-
require 'rspec/core/rake_task'
|
7
|
-
RSpec::Core::RakeTask.new
|
8
|
-
task default: :spec
|
9
|
-
|
10
|
-
# JavaScript
|
11
|
-
require 'jasmine'
|
12
|
-
load 'jasmine/tasks/jasmine.rake'
|
13
|
-
|
14
|
-
## Linters
|
15
|
-
|
16
|
-
# Ruby
|
17
|
-
require 'rubocop/rake_task'
|
18
|
-
RuboCop::RakeTask.new do |task|
|
19
|
-
task.options = ['--config', 'config/linters/ruby.yml']
|
20
|
-
end
|
21
|
-
|
22
|
-
# JavaScript
|
23
|
-
# rubocop:disable Rails/RakeEnvironment
|
24
|
-
# eslint related tasks does not need to load Rails environment
|
25
|
-
eslint_args = ['--no-eslintrc', '--config config/linters/js.json']
|
26
|
-
eslint_path = ['app/assets/**/*.js', 'spec/javascripts/**/*.js', 'spec/dummy/app/assets/**/*.js']
|
27
|
-
|
28
|
-
namespace :eslint do
|
29
|
-
desc 'Auto-correct eslint offenses'
|
30
|
-
task :auto_correct do
|
31
|
-
system("yarnpkg run eslint #{(eslint_args + ['--fix']).join(' ')} #{eslint_path.join(' ')}")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
desc 'Run eslint'
|
36
|
-
task :eslint do
|
37
|
-
system("yarnpkg run eslint #{eslint_args.join(' ')} #{eslint_path.join(' ')}")
|
38
|
-
end
|
39
|
-
# rubocop:enable Rails/RakeEnvironment
|
40
|
-
|
41
|
-
# Both
|
42
|
-
namespace :linters do
|
43
|
-
desc 'Auto-correct Rubocop and eslint offenses'
|
44
|
-
task auto_correct: ['rubocop:auto_correct', 'eslint:auto_correct']
|
45
|
-
end
|
46
|
-
|
47
|
-
desc 'Run Rubocop and eslint'
|
48
|
-
task linters: %i[rubocop eslint]
|
49
|
-
|
50
|
-
## Packaging
|
51
|
-
|
52
|
-
# Ruby
|
53
|
-
require 'bundler/gem_tasks'
|
54
|
-
|
55
|
-
# JavaScript
|
56
|
-
require 'json'
|
57
|
-
|
58
|
-
spec = Bundler.load_gemspec('./cocooned.gemspec')
|
59
|
-
npm_scope = 'notus.sh'
|
60
|
-
|
61
|
-
npm_src_dir = './npm'
|
62
|
-
npm_dest_dir = './dist'
|
63
|
-
CLOBBER.include 'dist'
|
64
|
-
|
65
|
-
assets_dir = './app/assets/'
|
66
|
-
|
67
|
-
npm_files = {
|
68
|
-
File.join(npm_dest_dir, 'cocooned.js') => File.join(assets_dir, 'javascripts', 'cocooned.js'),
|
69
|
-
File.join(npm_dest_dir, 'cocooned.css') => File.join(assets_dir, 'stylesheets', 'cocooned.css'),
|
70
|
-
File.join(npm_dest_dir, 'README.md') => File.join(npm_src_dir, 'README.md'),
|
71
|
-
File.join(npm_dest_dir, 'LICENSE') => './LICENSE'
|
72
|
-
}
|
73
|
-
|
74
|
-
namespace :npm do
|
75
|
-
# rubocop:disable Rails/RakeEnvironment
|
76
|
-
# npm related tasks does not need to load Rails environment
|
77
|
-
npm_files.each do |dest, src|
|
78
|
-
file dest => src do
|
79
|
-
cp src, dest
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
task :'package-json' do
|
84
|
-
contributors = []
|
85
|
-
spec.authors.each_with_index do |name, i|
|
86
|
-
next if spec.email[i].nil?
|
87
|
-
|
88
|
-
contributors << {
|
89
|
-
name: name.dup.force_encoding('UTF-8'),
|
90
|
-
email: spec.email[i].dup.force_encoding('UTF-8')
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
template = ERB.new(File.read(File.join(npm_src_dir, 'package.json.erb')))
|
95
|
-
content = template.result_with_hash(scope: npm_scope, spec: spec, contributors: contributors)
|
96
|
-
File.write(File.join(npm_dest_dir, 'package.json'),
|
97
|
-
JSON.pretty_generate(JSON.parse(content)))
|
98
|
-
end
|
99
|
-
|
100
|
-
desc "Build #{npm_scope}-#{spec.name}-#{spec.version}.tgz into the pkg directory"
|
101
|
-
task build: (%i[package-json] + npm_files.keys) do
|
102
|
-
system("cd #{npm_dest_dir} && npm pack && mv ./#{npm_scope}-#{spec.name}-#{spec.version}.tgz ../pkg/")
|
103
|
-
end
|
104
|
-
|
105
|
-
desc "Build and push #{npm_scope}-#{spec.name}-#{spec.version}.tgz to https://npmjs.org"
|
106
|
-
task release: %i[build] do
|
107
|
-
system("npm publish ./pkg/#{npm_scope}-#{spec.name}-#{spec.version}.tgz --access public")
|
108
|
-
end
|
109
|
-
# rubocop:enable Rails/RakeEnvironment
|
110
|
-
end
|
111
|
-
|
112
|
-
desc 'Build packages and push them to their respective repository'
|
113
|
-
task releases: [:release, 'npm:release']
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Cocooned
|
4
|
-
class AssociationBuilder
|
5
|
-
attr_accessor :association, :form, :options
|
6
|
-
|
7
|
-
def initialize(form, association, options = {})
|
8
|
-
self.form = form
|
9
|
-
self.association = association
|
10
|
-
self.options = options.reverse_merge(force_non_association_create: false, wrap_object: false)
|
11
|
-
end
|
12
|
-
|
13
|
-
def build_object
|
14
|
-
model = reflection ? build_with_reflection : build_without_reflection
|
15
|
-
model = @options[:wrap_object].call(model) if @options[:wrap_object].respond_to?(:call)
|
16
|
-
model
|
17
|
-
end
|
18
|
-
|
19
|
-
def singular_name
|
20
|
-
association.to_s.singularize
|
21
|
-
end
|
22
|
-
|
23
|
-
def plural_name
|
24
|
-
association.to_s.pluralize
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def reflection
|
30
|
-
@reflection ||= begin
|
31
|
-
klass = form.object.class
|
32
|
-
klass.respond_to?(:reflect_on_association) ? klass.reflect_on_association(association) : nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def build_with_reflection
|
37
|
-
return build_with_conditions if should_use_conditions?
|
38
|
-
|
39
|
-
# Assume ActiveRecord or compatible
|
40
|
-
# We use a clone of the current form object to not link
|
41
|
-
# object together (even if unsaved)
|
42
|
-
dummy = form.object.dup
|
43
|
-
model = if reflection.collection?
|
44
|
-
dummy.send(association).build
|
45
|
-
else
|
46
|
-
dummy.send("build_#{association}")
|
47
|
-
end
|
48
|
-
model = model.dup if model.frozen?
|
49
|
-
model
|
50
|
-
end
|
51
|
-
|
52
|
-
def build_without_reflection
|
53
|
-
methods = %W[build_#{plural_name} build_#{singular_name}].select { |m| form.object.respond_to?(m) }
|
54
|
-
raise "Association #{association} doesn't exist on #{form.object.class}" unless methods.any?
|
55
|
-
|
56
|
-
form.object.send(methods.first)
|
57
|
-
end
|
58
|
-
|
59
|
-
def should_use_conditions?
|
60
|
-
reflection.class.name.starts_with?('Mongoid::') || @options[:force_non_association_create]
|
61
|
-
end
|
62
|
-
|
63
|
-
def build_with_conditions
|
64
|
-
conditions = reflection.respond_to?(:conditions) ? reflection.conditions.flatten : []
|
65
|
-
reflection.klass.new(*conditions)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'cocooned/helpers/deprecate'
|
4
|
-
|
5
|
-
module Cocooned
|
6
|
-
module Helpers
|
7
|
-
# Provide aliases to old Cocoon method for backward compatibility.
|
8
|
-
# Cocoon methods are deprecated and will be removed in next major release.
|
9
|
-
#
|
10
|
-
# TODO: Remove in 3.0
|
11
|
-
module CocoonCompatibility
|
12
|
-
extend Cocooned::Helpers::Deprecate
|
13
|
-
|
14
|
-
# @deprecated: Please use {#cocooned_add_item_link} instead
|
15
|
-
def link_to_add_association(*args, &block)
|
16
|
-
cocooned_add_item_link(*args, &block)
|
17
|
-
end
|
18
|
-
deprecate_release :link_to_add_association, :cocooned_add_item_link
|
19
|
-
|
20
|
-
# @deprecated: Please use {#cocooned_remove_item_link} instead
|
21
|
-
def link_to_remove_association(*args, &block)
|
22
|
-
cocooned_remove_item_link(*args, &block)
|
23
|
-
end
|
24
|
-
deprecate_release :link_to_remove_association, :cocooned_remove_item_link
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubygems/deprecate'
|
4
|
-
|
5
|
-
module Cocooned
|
6
|
-
module Helpers
|
7
|
-
# Extend the standard Gem::Deprecation module to add a deprecation
|
8
|
-
# method that specify the gem release where methods will disappear
|
9
|
-
# instead of a date.
|
10
|
-
module Deprecate
|
11
|
-
extend Gem::Deprecate
|
12
|
-
|
13
|
-
module_function
|
14
|
-
|
15
|
-
def deprecate_release_message(target_and_name, replacement, release = '3.0', location = nil)
|
16
|
-
[
|
17
|
-
"NOTE: #{target_and_name} is deprecated",
|
18
|
-
replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
|
19
|
-
format('. It will dissapear in %<release>s.', release: release),
|
20
|
-
location.nil? ? '' : "\n#{target_and_name} called from #{location}"
|
21
|
-
].join.strip
|
22
|
-
end
|
23
|
-
|
24
|
-
def deprecate_release(name, replacement, release = '3.0')
|
25
|
-
class_eval do
|
26
|
-
old = "_deprecated_#{name}"
|
27
|
-
alias_method old, name
|
28
|
-
define_method name do |*args, &block|
|
29
|
-
klass = is_a? Module
|
30
|
-
target = klass ? "#{self}." : "#{self.class}#"
|
31
|
-
|
32
|
-
unless Gem::Deprecate.skip
|
33
|
-
warn(deprecate_release_message(
|
34
|
-
"#{target}#{name}",
|
35
|
-
replacement,
|
36
|
-
release,
|
37
|
-
Gem.location_of_caller.join(':')
|
38
|
-
))
|
39
|
-
end
|
40
|
-
|
41
|
-
send old, *args, &block
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|