bit_player 0.1.3 → 0.1.4
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/README.md +4 -0
- data/Rakefile +4 -1
- data/app/models/bit_player/content_module.rb +7 -6
- data/app/models/bit_player/content_provider.rb +5 -4
- data/app/models/bit_player/content_providers/form_view_provider.rb +20 -14
- data/app/models/bit_player/content_providers/null.rb +16 -9
- data/app/models/bit_player/content_providers/slideshow_provider.rb +24 -20
- data/app/models/bit_player/content_providers/view_provider.rb +20 -14
- data/app/models/bit_player/navigator.rb +10 -5
- data/app/models/bit_player/participant_status.rb +12 -13
- data/app/models/bit_player/slide.rb +19 -23
- data/app/models/bit_player/slideshow.rb +6 -5
- data/app/models/bit_player/video_slide.rb +1 -0
- data/db/migrate/20140305234327_create_bit_player_slides.rb +2 -4
- data/lib/bit_player/version.rb +1 -1
- data/spec/dummy/db/migrate/20140306000537_create_bit_player_slides.bit_player.rb +2 -4
- data/spec/dummy/db/schema.rb +1 -2
- data/spec/dummy/log/development.log +334 -0
- data/spec/dummy/log/test.log +2278 -149
- data/spec/fixtures/bit_player/content_modules.yml +9 -0
- data/spec/fixtures/bit_player/content_providers.yml +11 -0
- data/spec/fixtures/bit_player/slides.yml +17 -0
- data/spec/fixtures/bit_player/slideshows.yml +2 -0
- data/spec/models/bit_player/content_module_spec.rb +19 -0
- data/spec/models/bit_player/slide_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- metadata +12 -4
- data/app/helpers/bit_player/application_helper.rb +0 -4
- data/lib/tasks/bit_player_tasks.rake +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35768c8e530397c5ff3197cdc50628a902056616
|
4
|
+
data.tar.gz: 493cf2180856d1cdfa73cb7ccb04f9cbdc532846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3b3909f4daa68f27a38a7253931dd13f6ec4d3513b030a5ca513f83d2a0990420af15c0b9dba3904dc5d1dfc1fd5e2829dcadb2462667f4b1fb9e88ae55e6ca
|
7
|
+
data.tar.gz: 076f6f351e4f597ba668b53cb55969efec36c9cf9a9d3e17ed6fbb52a8e31a0b368cb3ae1cfa3e6a8a6fe555fcadc490a1cb9c2dc62d5511a7d27af910de8083
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -18,8 +18,11 @@ require 'rspec/core/rake_task'
|
|
18
18
|
|
19
19
|
RSpec::Core::RakeTask.new(:spec)
|
20
20
|
|
21
|
-
task :
|
21
|
+
task default: :spec
|
22
22
|
|
23
|
+
task :test do
|
24
|
+
puts `cd spec/dummy; RAILS_ENV=test rake db:drop db:create db:migrate; cd ../..; rspec`
|
25
|
+
end
|
23
26
|
|
24
27
|
Bundler::GemHelper.install_tasks
|
25
28
|
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module BitPlayer
|
2
|
+
# A logical unit of content, possibly containing mixed provider types.
|
2
3
|
class ContentModule < ActiveRecord::Base
|
3
4
|
has_many :content_providers,
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
class_name: "BitPlayer::ContentProvider",
|
6
|
+
foreign_key: :bit_player_content_module_id,
|
7
|
+
inverse_of: :content_module
|
7
8
|
|
8
9
|
validates :title, :context, :position, presence: true
|
9
|
-
|
10
|
-
|
10
|
+
validates :position, numericality: { greater_than_or_equal_to: 1 }
|
11
|
+
validates :position, uniqueness: { scope: :context }
|
11
12
|
|
12
13
|
def provider(position)
|
13
14
|
content_providers.where(position: position).first ||
|
14
|
-
BitPlayer::ContentProviders::Null.new(self)
|
15
|
+
BitPlayer::ContentProviders::Null.new(self, position)
|
15
16
|
end
|
16
17
|
|
17
18
|
def provider_exists?(position)
|
@@ -1,15 +1,16 @@
|
|
1
1
|
module BitPlayer
|
2
|
+
# Modeled after the presenter pattern. Ties data layer to view layer.
|
2
3
|
class ContentProvider < ActiveRecord::Base
|
3
4
|
include BitPlayer::ContentProviders::ViewProvider
|
4
5
|
|
5
6
|
belongs_to :content_module,
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
class_name: "BitPlayer::ContentModule",
|
8
|
+
foreign_key: :bit_player_content_module_id,
|
9
|
+
inverse_of: :content_providers
|
9
10
|
belongs_to :source_content, polymorphic: true
|
10
11
|
|
11
12
|
validates :content_module, :position, presence: true
|
12
|
-
|
13
|
+
validates :position, numericality: { greater_than_or_equal_to: 1 }
|
13
14
|
|
14
15
|
delegate :context, to: :content_module, prefix: false
|
15
16
|
|
@@ -1,13 +1,19 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
1
3
|
module BitPlayer
|
2
|
-
module ContentProviders
|
3
|
-
|
4
|
-
|
4
|
+
module ContentProviders
|
5
|
+
# Presentation logic for a "new" or "edit" view on a data model.
|
6
|
+
module FormViewProvider
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
5
10
|
def self.data_class(klass)
|
6
11
|
@source_class = klass
|
7
12
|
end
|
8
13
|
|
9
14
|
def self.source_class
|
10
|
-
@source_class || fail("Classes inheriting from #{ self } must define
|
15
|
+
@source_class || fail("Classes inheriting from #{ self } must define
|
16
|
+
a source classwith `data_class <class>`")
|
11
17
|
end
|
12
18
|
|
13
19
|
def self.show_nav_link
|
@@ -33,20 +39,20 @@ module BitPlayer
|
|
33
39
|
@view_type
|
34
40
|
end
|
35
41
|
end
|
36
|
-
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
def show_nav_link?
|
44
|
+
self.class.show_nav_link?
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
def template
|
48
|
+
"#{ plural_name }/#{ self.class.get_view_type }"
|
49
|
+
end
|
45
50
|
|
46
|
-
|
51
|
+
private
|
47
52
|
|
48
|
-
|
49
|
-
|
53
|
+
def plural_name
|
54
|
+
self.class.source_class.to_s.underscore.pluralize
|
55
|
+
end
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
module BitPlayer
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module ContentProviders
|
3
|
+
# The default provider.
|
4
|
+
class Null
|
5
|
+
attr_reader :position
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
def show_nav_link?
|
18
|
+
true
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
@@ -1,28 +1,32 @@
|
|
1
1
|
module BitPlayer
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module ContentProviders
|
3
|
+
# Defines presentation logic for a Slideshow.
|
4
|
+
class SlideshowProvider < ContentProvider
|
5
|
+
def slideshow
|
6
|
+
source_content
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
def slide(position)
|
19
|
+
slideshow.slides.where(position: position).first ||
|
20
|
+
BitPlayer::Slide.new(body: "no slides")
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
def exists?(position)
|
24
|
+
slideshow.slides.exists?(position: position)
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
def show_nav_link?
|
28
|
+
true
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -1,13 +1,19 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
1
3
|
module BitPlayer
|
2
|
-
module ContentProviders
|
3
|
-
|
4
|
-
|
4
|
+
module ContentProviders
|
5
|
+
# Presentation logic for a "show" or "index" view on a data model.
|
6
|
+
module ViewProvider
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
5
10
|
def self.data_class(klass)
|
6
11
|
@source_class = klass
|
7
12
|
end
|
8
13
|
|
9
14
|
def self.source_class
|
10
|
-
@source_class || fail("Classes inheriting from #{ self } must define
|
15
|
+
@source_class || fail("Classes inheriting from #{ self } must define
|
16
|
+
a source class with `data_class <class>`")
|
11
17
|
end
|
12
18
|
|
13
19
|
def self.show_nav_link
|
@@ -33,20 +39,20 @@ module BitPlayer
|
|
33
39
|
@view_type
|
34
40
|
end
|
35
41
|
end
|
36
|
-
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
def show_nav_link?
|
44
|
+
self.class.show_nav_link?
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
def template
|
48
|
+
"#{ plural_name }/#{ self.class.get_view_type }"
|
49
|
+
end
|
45
50
|
|
46
|
-
|
51
|
+
private
|
47
52
|
|
48
|
-
|
49
|
-
|
53
|
+
def plural_name
|
54
|
+
self.class.source_class.to_s.underscore.pluralize
|
55
|
+
end
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module BitPlayer
|
2
|
+
# Business rules for proceeding statefully through an application.
|
2
3
|
class Navigator
|
3
|
-
RenderOptions = Struct.new(
|
4
|
+
RenderOptions = Struct.new(
|
5
|
+
:view_context, :app_context, :position, :participant
|
6
|
+
)
|
4
7
|
|
5
8
|
def initialize(participant)
|
6
9
|
@participant = participant
|
@@ -24,7 +27,9 @@ module BitPlayer
|
|
24
27
|
end
|
25
28
|
|
26
29
|
def render_current_content(view_context)
|
27
|
-
options = RenderOptions.new(
|
30
|
+
options = RenderOptions.new(
|
31
|
+
view_context, context, content_position, @participant
|
32
|
+
)
|
28
33
|
|
29
34
|
current_content_provider.render_current(options)
|
30
35
|
end
|
@@ -55,10 +60,10 @@ module BitPlayer
|
|
55
60
|
content_module = ContentModule.find(options[:module_id])
|
56
61
|
@status.context = content_module.context
|
57
62
|
@status.module_position = content_module.position
|
63
|
+
@status.provider_position = 1
|
58
64
|
if options[:provider_id]
|
59
|
-
@status.provider_position = content_module.content_providers
|
60
|
-
|
61
|
-
@status.provider_position = 1
|
65
|
+
@status.provider_position = content_module.content_providers
|
66
|
+
.find(options[:provider_id]).position
|
62
67
|
end
|
63
68
|
@status.content_position = [options[:content_position].to_i, 1].max
|
64
69
|
@status.save
|
@@ -1,27 +1,26 @@
|
|
1
1
|
module BitPlayer
|
2
|
+
# Persistent data representing the Participant's navigation state.
|
2
3
|
class ParticipantStatus < ActiveRecord::Base
|
3
4
|
belongs_to :participant
|
4
5
|
|
5
6
|
def initialize_context(name)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
update(
|
8
|
+
context: name,
|
9
|
+
module_position: 1,
|
10
|
+
provider_position: 1,
|
11
|
+
content_position: 1
|
12
|
+
)
|
12
13
|
end
|
13
14
|
|
14
15
|
def increment_content_position
|
15
|
-
|
16
|
-
|
17
|
-
save
|
16
|
+
update(content_position: content_position + 1)
|
18
17
|
end
|
19
18
|
|
20
19
|
def increment_provider_position
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
update(
|
21
|
+
provider_position: provider_position + 1,
|
22
|
+
content_position: 1
|
23
|
+
)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -1,40 +1,36 @@
|
|
1
1
|
require "redcarpet"
|
2
2
|
|
3
3
|
module BitPlayer
|
4
|
+
# A page of "static" or presentational content (as opposed to data capture).
|
4
5
|
class Slide < ActiveRecord::Base
|
5
6
|
belongs_to :slideshow,
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
class_name: "BitPlayer::Slideshow",
|
8
|
+
foreign_key: :bit_player_slideshow_id,
|
9
|
+
inverse_of: :slides
|
9
10
|
|
10
11
|
validates :title, :body, :position, presence: true
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def render_body
|
15
|
-
rendered = ""
|
16
|
-
|
17
|
-
if !body.nil?
|
18
|
-
markdown = Redcarpet::Markdown.new(
|
19
|
-
Redcarpet::Render::HTML.new(
|
20
|
-
filter_html: true,
|
21
|
-
safe_links_only: true
|
22
|
-
),
|
23
|
-
space_after_headers: true,
|
24
|
-
)
|
25
|
-
rendered += markdown.render(body)
|
26
|
-
end
|
27
|
-
|
28
|
-
rendered.html_safe
|
29
|
-
end
|
12
|
+
validates :position, numericality: { greater_than_or_equal_to: 1 }
|
13
|
+
validates :position, uniqueness: { scope: :bit_player_slideshow_id }
|
30
14
|
|
31
15
|
def self.update_positions(ids)
|
32
16
|
transaction do
|
33
|
-
connection.execute "SET CONSTRAINTS
|
17
|
+
connection.execute "SET CONSTRAINTS bit_player_slide_position DEFERRED"
|
34
18
|
ids.each_with_index do |id, index|
|
35
19
|
where(id: id).update_all(position: index + 1)
|
36
20
|
end
|
37
21
|
end
|
38
22
|
end
|
23
|
+
|
24
|
+
def render_body
|
25
|
+
return "" if body.nil?
|
26
|
+
|
27
|
+
Redcarpet::Markdown.new(
|
28
|
+
Redcarpet::Render::HTML.new(
|
29
|
+
filter_html: true,
|
30
|
+
safe_links_only: true
|
31
|
+
),
|
32
|
+
space_after_headers: true
|
33
|
+
).render(body).html_safe
|
34
|
+
end
|
39
35
|
end
|
40
36
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module BitPlayer
|
2
|
+
# A collection of ordered Slides.
|
2
3
|
class Slideshow < ActiveRecord::Base
|
3
4
|
has_many :slides,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
-> { order "position" },
|
6
|
+
class_name: "BitPlayer::Slide",
|
7
|
+
foreign_key: :bit_player_slideshow_id,
|
8
|
+
dependent: :destroy,
|
9
|
+
inverse_of: :slideshow
|
9
10
|
has_one :content_provider, as: :source_content, inverse_of: :source_content
|
10
11
|
|
11
12
|
validates :title, presence: true
|
@@ -12,8 +12,6 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
|
|
12
12
|
t.timestamps
|
13
13
|
end
|
14
14
|
|
15
|
-
add_index :bit_player_slides, [:position, :bit_player_slideshow_id]
|
16
|
-
|
17
15
|
reversible do |dir|
|
18
16
|
dir.up do
|
19
17
|
execute <<-SQL
|
@@ -27,7 +25,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
|
|
27
25
|
# updated
|
28
26
|
execute <<-SQL
|
29
27
|
ALTER TABLE bit_player_slides
|
30
|
-
ADD CONSTRAINT
|
28
|
+
ADD CONSTRAINT bit_player_slide_position UNIQUE (bit_player_slideshow_id, position)
|
31
29
|
DEFERRABLE INITIALLY IMMEDIATE
|
32
30
|
SQL
|
33
31
|
end
|
@@ -40,7 +38,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
|
|
40
38
|
|
41
39
|
execute <<-SQL
|
42
40
|
ALTER TABLE bit_player_slides
|
43
|
-
DROP CONSTRAINT IF EXISTS
|
41
|
+
DROP CONSTRAINT IF EXISTS bit_player_slide_position
|
44
42
|
SQL
|
45
43
|
end
|
46
44
|
end
|
data/lib/bit_player/version.rb
CHANGED
@@ -13,8 +13,6 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
|
|
13
13
|
t.timestamps
|
14
14
|
end
|
15
15
|
|
16
|
-
add_index :bit_player_slides, [:position, :bit_player_slideshow_id]
|
17
|
-
|
18
16
|
reversible do |dir|
|
19
17
|
dir.up do
|
20
18
|
execute <<-SQL
|
@@ -28,7 +26,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
|
|
28
26
|
# updated
|
29
27
|
execute <<-SQL
|
30
28
|
ALTER TABLE bit_player_slides
|
31
|
-
ADD CONSTRAINT
|
29
|
+
ADD CONSTRAINT bit_player_slide_position UNIQUE (bit_player_slideshow_id, position)
|
32
30
|
DEFERRABLE INITIALLY IMMEDIATE
|
33
31
|
SQL
|
34
32
|
end
|
@@ -41,7 +39,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
|
|
41
39
|
|
42
40
|
execute <<-SQL
|
43
41
|
ALTER TABLE bit_player_slides
|
44
|
-
DROP CONSTRAINT IF EXISTS
|
42
|
+
DROP CONSTRAINT IF EXISTS bit_player_slide_position
|
45
43
|
SQL
|
46
44
|
end
|
47
45
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -60,9 +60,8 @@ ActiveRecord::Schema.define(version: 20140306000537) do
|
|
60
60
|
t.datetime "updated_at"
|
61
61
|
end
|
62
62
|
|
63
|
-
add_index "bit_player_slides", ["bit_player_slideshow_id", "position"], name: "
|
63
|
+
add_index "bit_player_slides", ["bit_player_slideshow_id", "position"], name: "bit_player_slide_position", unique: true, using: :btree
|
64
64
|
add_index "bit_player_slides", ["bit_player_slideshow_id"], name: "index_bit_player_slides_on_bit_player_slideshow_id", using: :btree
|
65
|
-
add_index "bit_player_slides", ["position", "bit_player_slideshow_id"], name: "index_bit_player_slides_on_position_and_bit_player_slideshow_id", using: :btree
|
66
65
|
|
67
66
|
create_table "bit_player_slideshows", force: true do |t|
|
68
67
|
t.string "title", null: false
|