brightcontent-core 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ff81cd24827adff2301e1c27e43bae64cf99b5c
4
- data.tar.gz: 7f28f10f9edb23e1f32a851c1e94b4cbcdb89c63
3
+ metadata.gz: 1d98fd17e22933bb39e638dd9a3b39b878eef6cc
4
+ data.tar.gz: bca0e21e04d7d73fc2dd0478332981de55001219
5
5
  SHA512:
6
- metadata.gz: d1a776c397011e888583f85ddfc12d2e77660b444e835bb10c42eec1ca096347be07a96b368f680f8358f5b9c15c5e079c6e46eccc5916c34e22367b69aafea3
7
- data.tar.gz: 875faa02c872d739780d9ff09d14b874fa06a427826cfc4563ca1a4cf2a2f6a125f4dcac561da9d5ca10f6205be8f08099e8d6d915b4feeb36dd5defeb40743e
6
+ metadata.gz: ebc862b8bde39b48d1988696dc3d044be451fe311571fd8e91d334e8fc169fe706968f8db905a3538dbcd03474fd907b929a811719b96800175d84821c8e9a76
7
+ data.tar.gz: 353c844ed0587227aaa8d7dbb78f67941c01d49a913c8e7afd728d353c94a19582bcdf80a2e530bfc6d29e00fa62258d48a3f26b22953811d3a84e633436e1af
@@ -0,0 +1 @@
1
+ <%= form.association field.to_sym %>
@@ -0,0 +1 @@
1
+ <%= form.association field.to_sym, as: :check_boxes %>
@@ -0,0 +1 @@
1
+ <%= form.association field.to_sym, as: :check_boxes %>
@@ -0,0 +1 @@
1
+ <%= item.send(field).count %>
@@ -0,0 +1 @@
1
+ <%= item.send(field).count %>
@@ -2,7 +2,7 @@ require 'active_support/inflector'
2
2
 
3
3
  module Brightcontent
4
4
  module ViewLookup
5
- class Abstract
5
+ class Base
6
6
  attr_reader :options, :view_context
7
7
 
8
8
  def initialize(view_context, options)
@@ -11,7 +11,7 @@ module Brightcontent
11
11
  end
12
12
 
13
13
  def call
14
- render_by_field_name || render_by_type || render_default
14
+ render_by_field_name || render_by_type || render_by_association_type || render_default
15
15
  end
16
16
 
17
17
  private
@@ -22,7 +22,12 @@ module Brightcontent
22
22
 
23
23
  def render_by_type
24
24
  return unless field_type
25
- render("brightcontent/base/#{name.pluralize}/#{field_type}", options)
25
+ render "brightcontent/base/#{name.pluralize}/#{field_type}", options
26
+ end
27
+
28
+ def render_by_association_type
29
+ return unless association_type
30
+ render "brightcontent/base/#{name.pluralize}/#{association_type}", options
26
31
  end
27
32
 
28
33
  def render_default
@@ -30,7 +35,11 @@ module Brightcontent
30
35
  end
31
36
 
32
37
  def field_type
33
- raise NotImplementedError
38
+ resource_class.columns_hash[options[:field].to_s].try :type
39
+ end
40
+
41
+ def association_type
42
+ association.try :macro
34
43
  end
35
44
 
36
45
  def name
@@ -41,6 +50,14 @@ module Brightcontent
41
50
  options[:item].send(options[:field])
42
51
  end
43
52
 
53
+ def association
54
+ resource_class.reflect_on_association options[:field].to_sym
55
+ end
56
+
57
+ def resource_class
58
+ view_context.send :resource_class
59
+ end
60
+
44
61
  def render(*args)
45
62
  view_context.render_if_exists(*args)
46
63
  end
@@ -1,6 +1,6 @@
1
1
  module Brightcontent
2
2
  module ViewLookup
3
- class FilterField < Abstract
3
+ class FilterField < Base
4
4
  def render_default
5
5
  raise "invalid filter field: #{options[:field]}" unless field_name
6
6
  [
@@ -9,10 +9,6 @@ module Brightcontent
9
9
  ].join(" ").html_safe
10
10
  end
11
11
 
12
- def field_type
13
- resource_class.columns_hash[options[:field]].try :type
14
- end
15
-
16
12
  private
17
13
 
18
14
  def field?
@@ -44,14 +40,6 @@ module Brightcontent
44
40
  def raw_options
45
41
  resource_class.uniq.pluck(field_name)
46
42
  end
47
-
48
- def association
49
- resource_class.reflect_on_association options[:field].to_sym
50
- end
51
-
52
- def resource_class
53
- view_context.send :resource_class
54
- end
55
43
  end
56
44
  end
57
45
  end
@@ -1,6 +1,6 @@
1
1
  module Brightcontent
2
2
  module ViewLookup
3
- class FormField < Abstract
3
+ class FormField < Base
4
4
  def render_default
5
5
  options[:form].input(options[:field].to_sym)
6
6
  end
@@ -1,13 +1,9 @@
1
1
  module Brightcontent
2
2
  module ViewLookup
3
- class ListField < Abstract
3
+ class ListField < Base
4
4
  def render_default
5
5
  view_context.strip_tags(field_value.to_s).truncate(50)
6
6
  end
7
-
8
- def field_type
9
- options[:item].column_for_attribute(options[:field]).try(:type)
10
- end
11
7
  end
12
8
  end
13
9
  end
@@ -1,6 +1,6 @@
1
1
  module Brightcontent
2
2
  module ViewLookup
3
- autoload :Abstract, 'brightcontent/view_lookup/abstract'
3
+ autoload :Base, 'brightcontent/view_lookup/base'
4
4
  autoload :FormField, 'brightcontent/view_lookup/form_field'
5
5
  autoload :ListField, 'brightcontent/view_lookup/list_field'
6
6
  autoload :FilterField, 'brightcontent/view_lookup/filter_field'
@@ -23,4 +23,8 @@ Brightcontent.setup do |config|
23
23
  # It has to implement an authenticate method.
24
24
  # config.user_model = "Brightcontent::AdminUser"
25
25
 
26
+ # brightcontent-pages provides a Brightcontent::Page model which is used
27
+ # by default. If you want to user another model for pages (eg. to avoid
28
+ # the namespace) you can specify it as a string or class.
29
+ # config.page_model = "Brightcontent::Page"
26
30
  end
@@ -1,19 +1,20 @@
1
- require 'brightcontent/view_lookup/abstract'
1
+ require 'brightcontent/view_lookup/base'
2
2
 
3
3
  module Brightcontent::ViewLookup
4
- describe Abstract do
5
- class FakeFormField < Abstract
4
+ describe Base do
5
+ class FakeFormField < Base
6
6
  def field_type
7
7
  :string
8
8
  end
9
9
  end
10
10
 
11
- let(:view_context) { double(:view_context) }
11
+ let(:resource_class) { double(:resource_class, reflect_on_association: nil) }
12
+ let(:view_context) { double(:view_context, resource_class: resource_class) }
12
13
  let(:item) { double(:item, name: 'Item name') }
13
14
  let(:fake_form_field) { FakeFormField.new(view_context, field: 'name', item: item) }
14
15
 
15
16
  context 'with specific field partial' do
16
- it 'renders the parial' do
17
+ it 'renders the partial' do
17
18
  expect(view_context).to receive(:render_if_exists)
18
19
  .with("fake_form_field_name", {field: 'name', item: item}) { "Result" }
19
20
  fake_form_field.call
@@ -21,7 +22,7 @@ module Brightcontent::ViewLookup
21
22
  end
22
23
 
23
24
  context 'with specific field type partial' do
24
- it 'renders the parial' do
25
+ it 'renders the partial' do
25
26
  expect(view_context).to receive(:render_if_exists).once
26
27
  expect(view_context).to receive(:render_if_exists)
27
28
  .with("brightcontent/base/fake_form_fields/string", {field: 'name', item: item}) { "Result" }
@@ -29,6 +30,16 @@ module Brightcontent::ViewLookup
29
30
  end
30
31
  end
31
32
 
33
+ context 'with association type' do
34
+ it 'renders the partial' do
35
+ allow(resource_class).to receive(:reflect_on_association).with(:name) { double(macro: "has_one") }
36
+ expect(view_context).to receive(:render_if_exists).twice
37
+ expect(view_context).to receive(:render_if_exists)
38
+ .with("brightcontent/base/fake_form_fields/has_one", {field: 'name', item: item}) { "Result" }
39
+ fake_form_field.call
40
+ end
41
+ end
42
+
32
43
  context 'without partial' do
33
44
  it 'renders the default value' do
34
45
  expect(view_context).to receive(:render_if_exists).once
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightcontent-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Developers at Brightin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -311,10 +311,15 @@ files:
311
311
  - app/views/brightcontent/base/_list_header.html.erb
312
312
  - app/views/brightcontent/base/_list_item.html.erb
313
313
  - app/views/brightcontent/base/edit.html.erb
314
+ - app/views/brightcontent/base/form_fields/_belongs_to.html.erb
314
315
  - app/views/brightcontent/base/form_fields/_file.html.erb
316
+ - app/views/brightcontent/base/form_fields/_has_and_belongs_to_many.html.erb
317
+ - app/views/brightcontent/base/form_fields/_has_many.html.erb
315
318
  - app/views/brightcontent/base/index.csv.erb
316
319
  - app/views/brightcontent/base/index.html.erb
317
320
  - app/views/brightcontent/base/list_fields/_boolean.html.erb
321
+ - app/views/brightcontent/base/list_fields/_has_and_belongs_to_many.html.erb
322
+ - app/views/brightcontent/base/list_fields/_has_many.html.erb
318
323
  - app/views/brightcontent/base/new.html.erb
319
324
  - app/views/brightcontent/sessions/new.html.erb
320
325
  - app/views/layouts/brightcontent/application.html.erb
@@ -341,7 +346,7 @@ files:
341
346
  - lib/brightcontent/resources.rb
342
347
  - lib/brightcontent/routes_parser.rb
343
348
  - lib/brightcontent/view_lookup.rb
344
- - lib/brightcontent/view_lookup/abstract.rb
349
+ - lib/brightcontent/view_lookup/base.rb
345
350
  - lib/brightcontent/view_lookup/filter_field.rb
346
351
  - lib/brightcontent/view_lookup/form_field.rb
347
352
  - lib/brightcontent/view_lookup/list_field.rb
@@ -411,7 +416,7 @@ files:
411
416
  - spec/lib/brightcontent/resource_spec.rb
412
417
  - spec/lib/brightcontent/resources_spec.rb
413
418
  - spec/lib/brightcontent/routes_parser_spec.rb
414
- - spec/lib/brightcontent/view_lookup/abstract_spec.rb
419
+ - spec/lib/brightcontent/view_lookup/base_spec.rb
415
420
  - spec/spec_helper.rb
416
421
  - spec/support/acceptance_helper.rb
417
422
  homepage: http://brightin.nl
@@ -499,6 +504,6 @@ test_files:
499
504
  - spec/lib/brightcontent/resource_spec.rb
500
505
  - spec/lib/brightcontent/resources_spec.rb
501
506
  - spec/lib/brightcontent/routes_parser_spec.rb
502
- - spec/lib/brightcontent/view_lookup/abstract_spec.rb
507
+ - spec/lib/brightcontent/view_lookup/base_spec.rb
503
508
  - spec/spec_helper.rb
504
509
  - spec/support/acceptance_helper.rb