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.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +16 -0
  3. data/Appraisals~ +16 -0
  4. data/CHANGELOG.md +87 -0
  5. data/Gemfile +7 -0
  6. data/Gemfile.lock +220 -0
  7. data/Gemfile~ +9 -0
  8. data/README.md +35 -14
  9. data/README.md~ +191 -0
  10. data/app/assets/javascripts/cubism.js +141 -0
  11. data/app/assets/javascripts/cubism.min.js +2 -0
  12. data/app/assets/javascripts/cubism.min.js.map +1 -0
  13. data/app/assets/javascripts/cubism.umd.js +149 -0
  14. data/app/assets/javascripts/cubism.umd.min.js +2 -0
  15. data/app/assets/javascripts/cubism.umd.min.js.map +1 -0
  16. data/app/channels/cubism/presence_channel.rb +14 -5
  17. data/app/helpers/cubism_helper.rb +15 -17
  18. data/app/models/concerns/cubism/presence.rb +11 -3
  19. data/bin/rails +14 -0
  20. data/bin/standardize +4 -0
  21. data/bin/test +5 -0
  22. data/cubism.gemspec +36 -0
  23. data/cubism.gemspec~ +28 -0
  24. data/lib/cubism/broadcaster.rb +13 -6
  25. data/lib/cubism/cubicle_store.rb +141 -0
  26. data/lib/cubism/engine.rb +23 -2
  27. data/lib/cubism/importmap.rb +2 -0
  28. data/lib/cubism/preprocessor.rb +4 -1
  29. data/lib/cubism/version.rb +1 -1
  30. data/lib/cubism.rb +3 -2
  31. data/package.json +43 -0
  32. data/package.json~ +33 -0
  33. data/rollup.config.js +77 -0
  34. data/{lib/cubism/parser.rb~ → rollup.config.js~} +0 -0
  35. data/test/block_container_test.rb +105 -0
  36. data/test/block_source_test.rb +102 -0
  37. data/test/broadcaster_test.rb +66 -0
  38. data/test/channels/cubism/presence_channel_test.rb +72 -0
  39. data/test/cubicle_store_test.rb +34 -0
  40. data/test/cubism_test.rb +7 -0
  41. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  42. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  43. data/test/dummy/app/controllers/application_controller.rb +2 -0
  44. data/test/dummy/app/helpers/application_helper.rb +2 -0
  45. data/test/dummy/app/jobs/application_job.rb +7 -0
  46. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  47. data/test/dummy/app/models/application_record.rb +3 -0
  48. data/test/dummy/app/models/post.rb +3 -0
  49. data/test/dummy/app/models/user.rb +3 -0
  50. data/test/dummy/config/application.rb +22 -0
  51. data/test/dummy/config/boot.rb +5 -0
  52. data/test/dummy/config/environment.rb +5 -0
  53. data/test/dummy/config/environments/development.rb +76 -0
  54. data/test/dummy/config/environments/production.rb +120 -0
  55. data/test/dummy/config/environments/test.rb +59 -0
  56. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  57. data/test/dummy/config/initializers/assets.rb +12 -0
  58. data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
  59. data/test/dummy/config/initializers/content_security_policy.rb +28 -0
  60. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  61. data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  62. data/test/dummy/config/initializers/inflections.rb +16 -0
  63. data/test/dummy/config/initializers/mime_types.rb +4 -0
  64. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/dummy/config/puma.rb +43 -0
  67. data/test/dummy/config/routes.rb +3 -0
  68. data/test/dummy/db/migrate/20220102072929_create_posts.rb +10 -0
  69. data/test/dummy/db/migrate/20220102073003_create_users.rb +9 -0
  70. data/test/dummy/db/schema.rb +26 -0
  71. data/test/dummy/test/models/post_test.rb +7 -0
  72. data/test/dummy/test/models/user_test.rb +7 -0
  73. data/test/helpers/cubism_helper_test.rb +39 -0
  74. data/test/integration/navigation_test.rb +7 -0
  75. data/test/models/concerns/presence_test.rb +25 -0
  76. data/test/models/concerns/user_test.rb +9 -0
  77. data/test/rendering/preprocessor_test.rb +61 -0
  78. data/test/test_helper.rb +16 -0
  79. data/yarn.lock +2814 -0
  80. metadata +118 -18
  81. data/app/channels/cubism/presence_channel.rb~ +0 -52
  82. data/app/helpers/cubism_helper.rb~ +0 -34
  83. data/app/models/concerns/cubism/presence.rb~ +0 -13
  84. data/config/routes.rb +0 -2
  85. data/lib/cubism/broadcaster.rb~ +0 -50
  86. data/lib/cubism/cubicle_block_store.rb +0 -56
  87. data/lib/cubism/cubicle_block_store.rb~ +0 -43
  88. data/lib/cubism/engine.rb~ +0 -4
  89. data/lib/cubism/preprocessor.rb~ +0 -26
  90. data/lib/cubism/version.rb~ +0 -3
  91. data/lib/cubism.rb~ +0 -18
  92. 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,7 @@
1
+ require "test_helper"
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ 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,7 @@
1
+ require "test_helper"
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ 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,9 @@
1
+ require "test_helper"
2
+
3
+ class Cubism::UserTest < ActiveSupport::TestCase
4
+ test "Cubism::User registers global Cubism.user_class upon inclusion" do
5
+ user = users(:one)
6
+
7
+ assert_equal Cubism.user_class, user.class
8
+ end
9
+ 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
@@ -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