cubism 0.1.0.pre10 → 0.1.0.pre13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +16 -0
- data/Appraisals~ +16 -0
- data/CHANGELOG.md +87 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +220 -0
- data/Gemfile~ +9 -0
- data/README.md +35 -14
- data/README.md~ +191 -0
- data/app/assets/javascripts/cubism.js +141 -0
- data/app/assets/javascripts/cubism.min.js +2 -0
- data/app/assets/javascripts/cubism.min.js.map +1 -0
- data/app/assets/javascripts/cubism.umd.js +149 -0
- data/app/assets/javascripts/cubism.umd.min.js +2 -0
- data/app/assets/javascripts/cubism.umd.min.js.map +1 -0
- data/app/channels/cubism/presence_channel.rb +14 -5
- data/app/helpers/cubism_helper.rb +15 -17
- data/app/models/concerns/cubism/presence.rb +11 -3
- data/bin/rails +14 -0
- data/bin/standardize +4 -0
- data/bin/test +5 -0
- data/cubism.gemspec +36 -0
- data/cubism.gemspec~ +28 -0
- data/lib/cubism/broadcaster.rb +13 -6
- data/lib/cubism/cubicle_store.rb +141 -0
- data/lib/cubism/engine.rb +23 -2
- data/lib/cubism/importmap.rb +2 -0
- data/lib/cubism/preprocessor.rb +4 -1
- data/lib/cubism/version.rb +1 -1
- data/lib/cubism.rb +3 -2
- data/package.json +43 -0
- data/package.json~ +33 -0
- data/rollup.config.js +77 -0
- data/{lib/cubism/parser.rb~ → rollup.config.js~} +0 -0
- data/test/block_container_test.rb +105 -0
- data/test/block_source_test.rb +102 -0
- data/test/broadcaster_test.rb +66 -0
- data/test/channels/cubism/presence_channel_test.rb +72 -0
- data/test/cubicle_store_test.rb +34 -0
- data/test/cubism_test.rb +7 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/post.rb +3 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +76 -0
- data/test/dummy/config/environments/production.rb +120 -0
- data/test/dummy/config/environments/test.rb +59 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +12 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
- data/test/dummy/config/initializers/content_security_policy.rb +28 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/permissions_policy.rb +11 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/puma.rb +43 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/migrate/20220102072929_create_posts.rb +10 -0
- data/test/dummy/db/migrate/20220102073003_create_users.rb +9 -0
- data/test/dummy/db/schema.rb +26 -0
- data/test/dummy/test/models/post_test.rb +7 -0
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/helpers/cubism_helper_test.rb +39 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/models/concerns/presence_test.rb +25 -0
- data/test/models/concerns/user_test.rb +9 -0
- data/test/rendering/preprocessor_test.rb +61 -0
- data/test/test_helper.rb +16 -0
- data/yarn.lock +2814 -0
- metadata +118 -18
- data/app/channels/cubism/presence_channel.rb~ +0 -52
- data/app/helpers/cubism_helper.rb~ +0 -34
- data/app/models/concerns/cubism/presence.rb~ +0 -13
- data/config/routes.rb +0 -2
- data/lib/cubism/broadcaster.rb~ +0 -50
- data/lib/cubism/cubicle_block_store.rb +0 -56
- data/lib/cubism/cubicle_block_store.rb~ +0 -43
- data/lib/cubism/engine.rb~ +0 -4
- data/lib/cubism/preprocessor.rb~ +0 -26
- data/lib/cubism/version.rb~ +0 -3
- data/lib/cubism.rb~ +0 -18
- data/lib/tasks/cubism_tasks.rake +0 -4
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 2022_01_02_073003) do
|
14
|
+
create_table "posts", force: :cascade do |t|
|
15
|
+
t.string "title"
|
16
|
+
t.text "body"
|
17
|
+
t.datetime "created_at", precision: 6, null: false
|
18
|
+
t.datetime "updated_at", precision: 6, null: false
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table "users", force: :cascade do |t|
|
22
|
+
t.string "username"
|
23
|
+
t.datetime "created_at", precision: 6, null: false
|
24
|
+
t.datetime "updated_at", precision: 6, null: false
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class CubismHelperTest < ActionView::TestCase
|
2
|
+
include CubismHelper
|
3
|
+
|
4
|
+
setup do
|
5
|
+
@post = posts(:one)
|
6
|
+
@user = users(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
Cubism.block_store.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
test "it displays a cubicle element for a resource" do
|
14
|
+
element = Nokogiri::HTML.fragment(cubicle_for(@post, @user) { |users| })
|
15
|
+
|
16
|
+
cubicle_element = element.children.first
|
17
|
+
|
18
|
+
assert_equal "cubicle-element", cubicle_element.name
|
19
|
+
assert_equal "connect", cubicle_element["appear-trigger"]
|
20
|
+
assert_nil cubicle_element["disappear-trigger"]
|
21
|
+
assert_nil cubicle_element["trigger-root"]
|
22
|
+
assert cubicle_element["exclude-current-user"]
|
23
|
+
|
24
|
+
refute_nil cubicle_element["id"]
|
25
|
+
end
|
26
|
+
|
27
|
+
test "it passes html_options" do
|
28
|
+
element = Nokogiri::HTML.fragment(cubicle_for(@post, @user, html_options: {class: "my-class1 my-class2"}) { |users| })
|
29
|
+
cubicle_element = element.children.first
|
30
|
+
|
31
|
+
assert_equal "my-class1 my-class2", cubicle_element["class"]
|
32
|
+
end
|
33
|
+
|
34
|
+
test "it stores the passed block in the global store" do
|
35
|
+
Nokogiri::HTML.fragment(cubicle_for(@post, @user) { |present_users| })
|
36
|
+
|
37
|
+
assert_equal 1, Cubism.block_store.size
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Cubism::PresenceTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
scoped_present_users = {
|
6
|
+
"" => Marshal.dump(Set.new([users(:one).id, users(:two).id])),
|
7
|
+
:edit => Marshal.dump(Set.new([users(:one).id])),
|
8
|
+
:show => Marshal.dump(Set.new([users(:two).id]))
|
9
|
+
}
|
10
|
+
|
11
|
+
@post = posts(:one)
|
12
|
+
@post.stubs(:present_users).returns(scoped_present_users)
|
13
|
+
@post.stubs(:excluded_user_id_for_element_id).returns({"foo" => users(:one).id, "bar" => users(:two).id})
|
14
|
+
end
|
15
|
+
|
16
|
+
test "Cubism::Presence respects excluded users per element" do
|
17
|
+
assert_equal [users(:two)], @post.present_users_for_element_id_and_scope("foo")
|
18
|
+
assert_equal [users(:one)], @post.present_users_for_element_id_and_scope("bar")
|
19
|
+
end
|
20
|
+
|
21
|
+
test "Cubism::Presence respects scopes along with excluded users" do
|
22
|
+
assert_equal [users(:one)], @post.present_users_for_element_id_and_scope("bar", :edit)
|
23
|
+
assert_equal [], @post.present_users_for_element_id_and_scope("bar", :show)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class PreprocessorTest < ActionView::TestCase
|
2
|
+
test "it extracts a simple cubicle_for block" do
|
3
|
+
source = <<-ERB
|
4
|
+
<%= cubicle_for post, user do |users| %>
|
5
|
+
<span class="presence">
|
6
|
+
<%= users.map(&:username).to_sentence %>
|
7
|
+
<span>
|
8
|
+
<% end %>
|
9
|
+
ERB
|
10
|
+
|
11
|
+
result = <<~ERB
|
12
|
+
<span class="presence">
|
13
|
+
<%= users.map(&:username).to_sentence %>
|
14
|
+
<span>
|
15
|
+
ERB
|
16
|
+
|
17
|
+
preprocessor = Cubism::Preprocessor.new(source: source, view_context: self)
|
18
|
+
|
19
|
+
assert_equal result.squish, preprocessor.process.squish
|
20
|
+
end
|
21
|
+
|
22
|
+
test "it respects ERB tags nested in the block" do
|
23
|
+
source = <<-ERB
|
24
|
+
<%= cubicle_for post, user do |users| %>
|
25
|
+
<% if users.size > 0 %>
|
26
|
+
<span class="presence">
|
27
|
+
<%= users.map(&:username).to_sentence %>
|
28
|
+
<span>
|
29
|
+
<% end %>
|
30
|
+
<% end %>
|
31
|
+
ERB
|
32
|
+
|
33
|
+
result = <<~ERB
|
34
|
+
<% if users.size > 0 %>
|
35
|
+
<span class="presence">
|
36
|
+
<%= users.map(&:username).to_sentence %>
|
37
|
+
<span>
|
38
|
+
<% end %>
|
39
|
+
ERB
|
40
|
+
|
41
|
+
preprocessor = Cubism::Preprocessor.new(source: source, view_context: self)
|
42
|
+
|
43
|
+
assert_equal result.squish, preprocessor.process.squish
|
44
|
+
end
|
45
|
+
|
46
|
+
test "it respects render calls nested in the block" do
|
47
|
+
source = <<-ERB
|
48
|
+
<%= cubicle_for post, user do |users| %>
|
49
|
+
<%= render "presence_partial", users: users %>
|
50
|
+
<% end %>
|
51
|
+
ERB
|
52
|
+
|
53
|
+
result = <<~ERB
|
54
|
+
<%= render "presence_partial", users: users %>
|
55
|
+
ERB
|
56
|
+
|
57
|
+
preprocessor = Cubism::Preprocessor.new(source: source, view_context: self)
|
58
|
+
|
59
|
+
assert_equal result.squish, preprocessor.process.squish
|
60
|
+
end
|
61
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require_relative "../test/dummy/config/environment"
|
5
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
|
6
|
+
require "rails/test_help"
|
7
|
+
require "minitest/unit"
|
8
|
+
require "mocha/minitest"
|
9
|
+
|
10
|
+
# Load fixtures from the engine
|
11
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
12
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("dummy/test/fixtures", __dir__)
|
13
|
+
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
14
|
+
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
|
15
|
+
ActiveSupport::TestCase.fixtures :all
|
16
|
+
end
|