bit_core 1.1.1 → 1.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: 5c312d299908674ded0b913cf0bb19c58e7077fa
4
- data.tar.gz: 4f75e2099cc24f380dce043e2f5f393c948b5099
3
+ metadata.gz: 78b524de8c4b376b6960150735005432b6d596b3
4
+ data.tar.gz: 203d6c9d735aeae6426bc65e370e4083e178d90c
5
5
  SHA512:
6
- metadata.gz: 4962013ce991082834db7c7c94a8931482bd363b4926dcb60109b1f7ef5a2e5c9ae308b3345ca30d06034b30df1c6b8482de58284ae85542820347612e12c591
7
- data.tar.gz: bfd07022e2aee3431b5d9bb3a3814eecdd7253135c43317bcecd88542c4ab2248115cbf9260a70ac9ed559af0c0b84393cc1f3a5b70cdbc591818d3013d531e4
6
+ metadata.gz: 49d4f1dc3b8da5363bd30dae38174b990574786db0f0afd59af754a0a2318eea2fe82baf9c9ab65f40204a5cab16dfc57068446aeba2aef4bd0fd8aa5b73d369
7
+ data.tar.gz: eea094b1b05d35d5f4237d16af7370776e2d5e1e5eb670e4f1be5c03aaf52c631f67d4180cab2cd714109bb1bc60648749cebccfdf1b6b203bf152b405900cf0
@@ -5,10 +5,63 @@ module BitCore
5
5
  class_name: "BitCore::ContentModule",
6
6
  foreign_key: :bit_core_content_module_id,
7
7
  inverse_of: :content_providers
8
+ belongs_to :source_content, polymorphic: true
8
9
 
9
- validates :type, :bit_core_content_module_id, :position, presence: true
10
+ validates :content_module,
11
+ :type,
12
+ :bit_core_content_module_id,
13
+ :position,
14
+ presence: true
10
15
  validates :position,
11
16
  numericality: { greater_than_or_equal_to: 1 },
12
17
  uniqueness: { scope: :bit_core_content_module_id }
18
+ validates :show_next_nav, inclusion: { in: [true, false] }
19
+ validate :template_path_exists
20
+ validate :data_class_exists
21
+ validate :data_attributes_exist
22
+
23
+ serialize :data_attributes
24
+ serialize :locals
25
+
26
+ delegate :context, to: :content_module, prefix: false
27
+
28
+ def exists?(_position)
29
+ false
30
+ end
31
+
32
+ def data_class
33
+ data_class_name.constantize
34
+ rescue NameError
35
+ nil
36
+ end
37
+
38
+ # compatibility method
39
+ def show_nav_link?
40
+ show_next_nav
41
+ end
42
+
43
+ private
44
+
45
+ def template_path_exists
46
+ path = File.join(Rails.root, "app", "views", template_path || "")
47
+ return if Dir.exist?(path)
48
+
49
+ errors.add(:template_path, "not found at #{ path }")
50
+ end
51
+
52
+ def data_class_exists
53
+ return unless data_class_name && !data_class
54
+
55
+ errors.add(:data_class_name,
56
+ "unable to find class '#{ data_class_name }'")
57
+ end
58
+
59
+ def data_attributes_exist
60
+ return unless data_attributes
61
+ attribute_names = data_class.try(:attribute_names) || []
62
+ return if data_attributes.all? { |a| attribute_names.include?(a.to_str) }
63
+
64
+ errors.add(:data_attributes, "must be attributes on the model class")
65
+ end
13
66
  end
14
67
  end
@@ -0,0 +1,26 @@
1
+ module BitCore
2
+ module ContentProviders
3
+ # The default provider.
4
+ class Null
5
+ attr_reader :position
6
+
7
+ def initialize(content_module, position)
8
+ @content_module = content_module
9
+ @position = position
10
+ end
11
+
12
+ def render_current(_options)
13
+ "Content Module #{ @content_module.title }: Oops, did you expect a
14
+ content provider here?"
15
+ end
16
+
17
+ def show_nav_link?
18
+ false
19
+ end
20
+
21
+ def exists?(_position)
22
+ false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module BitCore
2
+ module ContentProviders
3
+ # Defines presentation logic for a Slideshow.
4
+ class SlideshowProvider < BitCore::ContentProvider
5
+ def slideshow
6
+ source_content
7
+ end
8
+
9
+ def render_current(options)
10
+ options.view_context.render(
11
+ template: "slides/show",
12
+ locals: {
13
+ slide: slide(options.position)
14
+ }
15
+ )
16
+ end
17
+
18
+ def slide(position)
19
+ slideshow.slides.where(position: position).first ||
20
+ BitCore::Slide.new(body: "no slides")
21
+ end
22
+
23
+ def exists?(position)
24
+ slideshow.slides.exists?(position: position)
25
+ end
26
+
27
+ def show_nav_link?
28
+ true
29
+ end
30
+ end
31
+ end
32
+ end
@@ -9,7 +9,6 @@ module BitCore
9
9
  inverse_of: :slideshow
10
10
  has_one :content_provider,
11
11
  as: :source_content,
12
- inverse_of: :source_content,
13
12
  dependent: :nullify
14
13
 
15
14
  validates :title, presence: true
@@ -0,0 +1,9 @@
1
+ class AddConfigFieldsToProviders < ActiveRecord::Migration
2
+ def change
3
+ add_column :bit_core_content_providers, :template_path, :string
4
+ add_column :bit_core_content_providers, :data_class_name, :string
5
+ add_column :bit_core_content_providers, :data_attributes, :text
6
+ add_column :bit_core_content_providers, :show_next_nav, :boolean
7
+ add_column :bit_core_content_providers, :locals, :text
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
1
  # nodoc
2
2
  module BitCore
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end