bit_core 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/bit_core/content_provider.rb +54 -1
- data/app/models/bit_core/content_providers/null.rb +26 -0
- data/app/models/bit_core/content_providers/slideshow_provider.rb +32 -0
- data/app/models/bit_core/slideshow.rb +0 -1
- data/db/migrate/20140620174147_add_config_fields_to_providers.rb +9 -0
- data/lib/bit_core/version.rb +1 -1
- data/spec/dummy/log/test.log +1182 -0
- data/spec/models/bit_core/content_module_spec.rb +22 -0
- data/spec/models/bit_core/content_provider_spec.rb +46 -0
- metadata +9 -4
- data/spec/dummy/db/schema.rb +0 -70
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 78b524de8c4b376b6960150735005432b6d596b3
         | 
| 4 | 
            +
              data.tar.gz: 203d6c9d735aeae6426bc65e370e4083e178d90c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 : | 
| 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
         | 
| @@ -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
         | 
    
        data/lib/bit_core/version.rb
    CHANGED