futurism 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba66b2cb1a12fb863e2e0fc34798411d7f95947a197496150e1a499582fc4e28
4
- data.tar.gz: 3f7f290ef2b0b79f9c9e5100e7eaed2520dcb8e481e391bd537649d0023d379b
3
+ metadata.gz: dc887b3a3173cce8feec82e572327f820cdb39793b5ee5fd5977b6e32c1edb78
4
+ data.tar.gz: e0f429c1861f30754e91c3dcce1121bf95894f558792f15f7f72958006b01dea
5
5
  SHA512:
6
- metadata.gz: e772253cf0ed802d14c6836c0fb7285f7011f79f516fa88cc85e13191b7de0f29ebbc0edbd5c7996f4f858ec4efe4890613605587a2cbd6c17c4ecbad05b4985
7
- data.tar.gz: cf4db9dd38a545a7fe43381dc22597a4c5e77a4023698b19017740fa996e6aa0433e1927c115a1187bb9028ad26e2b36aa3ecd9f66fb19000380a6b6467efffb
6
+ metadata.gz: 603a65c0d08974feeaceb867e076ab69daf99e51a139fd8f9c2634d7e3b885a7f662ae1c2c32e0e2c31ec6e2dd1b55ec2df8ad385441abfe25d66a7088d30a21
7
+ data.tar.gz: 11d930242efc8ff82a7b495197b4c5fceb9a0a7cc4e89fc48d9464e05e85e7eb307b7a25dac85628e2a5f7e66e1427e960150f544b325552142fc1ececb5e7db
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Futurism
2
2
  [![Twitter follow](https://img.shields.io/twitter/follow/julian_rubisch?style=social)](https://twitter.com/julian_rubisch)
3
3
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors-)
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors-)
5
5
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
6
6
  Lazy-load Rails partials via CableReady
7
7
 
@@ -10,6 +10,25 @@ Lazy-load Rails partials via CableReady
10
10
  <img src="https://user-images.githubusercontent.com/4352208/88374198-9e6f3500-cd99-11ea-804b-0216ed320eff.jpg" alt="birmingham-museums-trust-GrvC6MI-z4w-unsplash" width="50%" align="center"/>
11
11
  <span>Photo by <a href="https://unsplash.com/@birminghammuseumstrust?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Birmingham Museums Trust</a> on <a href="https://unsplash.com/s/photos/futurism?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>
12
12
 
13
+ ## Table of Contents
14
+
15
+ - [Table of Contents](#table-of-contents)
16
+ - [Facts](#facts)
17
+ - [Browser Support](#browser-support)
18
+ - [Usage](#usage)
19
+ - [API](#api)
20
+ - [Resource](#resource)
21
+ - [Explicit Partial](#explicit-partial)
22
+ - [HTML Options](#html-options)
23
+ - [Events](#events)
24
+ - [Installation](#installation)
25
+ - [Manual Installation](#manual-installation)
26
+ - [Authentication](#authentication)
27
+ - [Gotchas](#gotchas)
28
+ - [Contributing](#contributing)
29
+ - [License](#license)
30
+ - [Contributors](#contributors)
31
+
13
32
  ## Facts
14
33
  - only one dependency: CableReady
15
34
  - bundle size (without CableReady) is around [~1.04kB](https://bundlephobia.com/result?p=@minthesize/futurism@0.1.3)
@@ -155,7 +174,7 @@ $ bin/yarn add @minthesize/futurism
155
174
  In your `app/javascript/channels/index.js`, add the following
156
175
 
157
176
  ```js
158
- import * as Futurism from '@minthesize/futurism''
177
+ import * as Futurism from '@minthesize/futurism'
159
178
 
160
179
  import consumer from './consumer'
161
180
 
@@ -163,6 +182,39 @@ Futurism.initializeElements()
163
182
  Futurism.createSubscription(consumer)
164
183
  ```
165
184
 
185
+ ## Authentication
186
+ For authentication, you can rely on ActionCable identifiers, for example, if you use Devise:
187
+
188
+ ```ruby
189
+ module ApplicationCable
190
+ class Connection < ActionCable::Connection::Base
191
+ identified_by :current_user
192
+
193
+ def connect
194
+ self.current_user = env["warden"].user || reject_unauthorized_connection
195
+ end
196
+ end
197
+ end
198
+ ```
199
+
200
+ The [Stimulus Reflex Docs](https://docs.stimulusreflex.com/authentication) have an excellent section about all sorts of authentication.
201
+
202
+ ## Gotchas
203
+
204
+ ### ActiveStorage URLs aren't correct in development
205
+
206
+ Out of the box, Rails will prefix generated urls with `http://example.org` rather than `http://localhost`, much like ActionMailer. To amend this, add
207
+
208
+ ```ruby
209
+ # config/environments/development.rb
210
+ config.action_controller.default_url_options = {host: "localhost", port: 3000}
211
+
212
+ # config/environments/production.rb
213
+ config.action_controller.default_url_options = {host: "mysite.com"}
214
+ ```
215
+
216
+ to your environments.
217
+
166
218
  ## Contributing
167
219
 
168
220
  ## License
@@ -189,6 +241,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
189
241
  <td align="center"><a href="http://fractaledmind.com"><img src="https://avatars3.githubusercontent.com/u/5077225?v=4" width="100px;" alt=""/><br /><sub><b>Stephen Margheim</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=fractaledmind" title="Code">💻</a></td>
190
242
  <td align="center"><a href="http://hass.codes"><img src="https://avatars2.githubusercontent.com/u/1064205?v=4" width="100px;" alt=""/><br /><sub><b>Hassanin Ahmed</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=sas1ni69" title="Code">💻</a></td>
191
243
  <td align="center"><a href="https://marcoroth.dev"><img src="https://avatars2.githubusercontent.com/u/6411752?v=4" width="100px;" alt=""/><br /><sub><b>Marco Roth</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=marcoroth" title="Code">💻</a></td>
244
+ <td align="center"><a href="https://viedit.com"><img src="https://avatars1.githubusercontent.com/u/49990587?v=4" width="100px;" alt=""/><br /><sub><b>Viedit com</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=vieditcom" title="Documentation">📖</a></td>
245
+ <td align="center"><a href="http://scottbarrow.ca"><img src="https://avatars2.githubusercontent.com/u/5571736?v=4" width="100px;" alt=""/><br /><sub><b>Scott Barrow</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=scottbarrow" title="Code">💻</a></td>
192
246
  </tr>
193
247
  </table>
194
248
 
@@ -2,8 +2,16 @@ module Futurism
2
2
  class Channel < ActionCable::Channel::Base
3
3
  include CableReady::Broadcaster
4
4
 
5
+ def stream_name
6
+ ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
7
+ [
8
+ params[:channel],
9
+ ids.select(&:present?).join(";")
10
+ ].select(&:present?).join(":")
11
+ end
12
+
5
13
  def subscribed
6
- stream_from "Futurism::Channel"
14
+ stream_from stream_name
7
15
  end
8
16
 
9
17
  def receive(data)
@@ -15,7 +23,7 @@ module Futurism
15
23
  resources.each do |signed_params, sgid|
16
24
  selector = "[data-signed-params='#{signed_params}']"
17
25
  selector << "[data-sgid='#{sgid}']" if sgid.present?
18
- cable_ready["Futurism::Channel"].outer_html(
26
+ cable_ready[stream_name].outer_html(
19
27
  selector: selector,
20
28
  html: ApplicationController.render(resource(signed_params: signed_params, sgid: sgid))
21
29
  )
@@ -36,31 +36,32 @@ module Futurism
36
36
  class Element
37
37
  include ActionView::Helpers
38
38
 
39
- attr_reader :extends, :placeholder, :html_options, :model, :options
39
+ attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options
40
40
 
41
41
  def initialize(extends:, placeholder:, options:)
42
42
  @extends = extends
43
43
  @placeholder = placeholder
44
44
  @html_options = options.delete(:html_options) || {}
45
+ @data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
45
46
  @model = options.delete(:model)
46
- @options = options
47
+ @options = data_attributes.any? ? options.merge(data: data_attributes) : options
47
48
  end
48
49
 
49
50
  def dataset
50
- {
51
+ data_attributes.merge({
51
52
  signed_params: signed_params,
52
53
  sgid: model && model.to_sgid.to_s
53
- }
54
+ })
54
55
  end
55
56
 
56
57
  def render
57
58
  case extends
58
59
  when :li
59
- content_tag :li, placeholder, {data: dataset, is: "futurism-li"}.merge(html_options)
60
+ content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
60
61
  when :tr
61
- content_tag :tr, placeholder, {data: dataset, is: "futurism-table-row"}.merge(html_options)
62
+ content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
62
63
  else
63
- content_tag :"futurism-element", placeholder, {data: dataset}.merge(html_options)
64
+ content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
64
65
  end
65
66
  end
66
67
 
@@ -1,3 +1,3 @@
1
1
  module Futurism
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: futurism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Rubisch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-24 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler