stimulus_reflex 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of stimulus_reflex might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3c225ea9ccdf33b87964486c734e4091e454650c0276c1d000104246e7cd3bc
4
- data.tar.gz: d38efd762fec5cf27843c64c37959dec9f10167c93a0c4a742e276a5de176853
3
+ metadata.gz: 2d807548446462e67ea049821b1de6da399d1575da3b679df3055e7bf2973fba
4
+ data.tar.gz: d204d0a31de01ac1c88baefb597982fc99882c1b25b17899593e8b90c32032d7
5
5
  SHA512:
6
- metadata.gz: 62993d44aaec8ad5805820163927a91c58eb69072bad71e062c23c345b6a2415b4698530838a8b46c85cad4611e23bf56e833f61e91fd80eb302cb5938e5bf69
7
- data.tar.gz: 9787c3178e523c35bf6d6883c0b8a0bb2e755c5c1e138795ba9bfa1a1fbb66e0e6278119bf343104a5dc731b87d94c554ce3bfb17d21f73fa33bad34b1c1acf0
6
+ metadata.gz: 6e37b24a2783cc89a54b47bb2ba1d7305f2a64be4efbc05f9b57120dc9ee8f13e42e9299a93c205e243fb991324f5180387eb054ba11a88e46f4fc33a963ff79
7
+ data.tar.gz: 0d6dbfe3e29c00e5fd0d211ac13405953f89995ab8dfab519f0e2eab992e2372eadd63696bb3f1fde59d426f9c1d92a3329bb22603618778168b1f647601938a
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (2.0.2)
5
- cable_ready (>= 4.0.3)
4
+ stimulus_reflex (2.1.0)
5
+ cable_ready (>= 4.0.7)
6
6
  nokogiri
7
7
  rack
8
8
  rails (>= 5.2)
@@ -67,7 +67,7 @@ GEM
67
67
  zeitwerk (~> 2.1, >= 2.1.8)
68
68
  ast (2.4.0)
69
69
  builder (3.2.3)
70
- cable_ready (4.0.5)
70
+ cable_ready (4.0.7)
71
71
  rails (>= 5.2)
72
72
  coderay (1.1.2)
73
73
  concurrent-ruby (1.1.5)
@@ -75,7 +75,7 @@ GEM
75
75
  erubi (1.9.0)
76
76
  globalid (0.4.2)
77
77
  activesupport (>= 4.2.0)
78
- i18n (1.6.0)
78
+ i18n (1.7.0)
79
79
  concurrent-ruby (~> 1.0)
80
80
  jaro_winkler (1.5.3)
81
81
  loofah (2.3.0)
@@ -93,8 +93,8 @@ GEM
93
93
  nio4r (2.5.2)
94
94
  nokogiri (1.10.4)
95
95
  mini_portile2 (~> 2.4.0)
96
- parallel (1.17.0)
97
- parser (2.6.4.1)
96
+ parallel (1.18.0)
97
+ parser (2.6.5.0)
98
98
  ast (~> 2.4.0)
99
99
  pry (0.12.2)
100
100
  coderay (~> 1.1.0)
@@ -122,8 +122,8 @@ GEM
122
122
  rails-dom-testing (2.0.3)
123
123
  activesupport (>= 4.2.0)
124
124
  nokogiri (>= 1.6)
125
- rails-html-sanitizer (1.2.0)
126
- loofah (~> 2.2, >= 2.2.2)
125
+ rails-html-sanitizer (1.3.0)
126
+ loofah (~> 2.3)
127
127
  railties (6.0.0)
128
128
  actionpack (= 6.0.0)
129
129
  activesupport (= 6.0.0)
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
- [![Lines of Code](http://img.shields.io/badge/lines_of_code-223-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
1
+ [![Lines of Code](http://img.shields.io/badge/lines_of_code-472-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/2b24fdbd1ae37a24bedb/maintainability)](https://codeclimate.com/github/hopsoft/stimulus_reflex/maintainability)
3
- ![Prettier](https://github.com/hopsoft/stimulus_reflex/workflows/Prettier/badge.svg)
3
+ ![Prettier-Standard](https://github.com/hopsoft/stimulus_reflex/workflows/Prettier-Standard/badge.svg)
4
4
  ![StandardRB](https://github.com/hopsoft/stimulus_reflex/workflows/StandardRB/badge.svg)
5
+ ![Tests](https://github.com/hopsoft/stimulus_reflex/workflows/Tests/badge.svg)
5
6
 
6
7
  # StimulusReflex
7
8
 
@@ -25,7 +26,8 @@ Everyone interacting with StimulusReflex is expected to follow the [Code of Cond
25
26
  ### Coding Standards
26
27
 
27
28
  This project uses [Standard](https://github.com/testdouble/standard)
28
- and [Prettier](https://github.com/prettier/prettier) to minimize bike shedding related to code formatting.
29
+ and [Prettier-Standard](https://github.com/sheerun/prettier-standard) to minimize bike shedding related to code formatting.
30
+
29
31
  Please run `./bin/standardize` prior submitting pull requests.
30
32
 
31
33
  View the [wiki](https://github.com/hopsoft/stimulus_reflex/wiki/Editor-Configuration) to see recommendations for configuring your editor to work best with the project.
data/Rakefile CHANGED
@@ -5,5 +5,5 @@ require "bundler/gem_tasks"
5
5
  task default: [:test]
6
6
 
7
7
  task :test do
8
- puts "Please write some tests..."
8
+ exec "cd javascript && yarn run test"
9
9
  end
data/bin/loc ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ cloc --exclude-dir=node_modules,test --include-ext=rb,js .
data/bin/standardize CHANGED
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
3
  bundle exec standardrb --fix
4
4
  cd ./javascript && yarn run prettier-standard stimulus_reflex.js test/*.js
@@ -18,6 +18,8 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
18
18
 
19
19
  def receive(data)
20
20
  url = data["url"].to_s
21
+ selectors = (data["selectors"] || []).select(&:present?)
22
+ selectors = ["body"] if selectors.blank?
21
23
  target = data["target"].to_s
22
24
  reflex_name, method_name = target.split("#")
23
25
  reflex_name = reflex_name.classify
@@ -27,14 +29,14 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
27
29
  begin
28
30
  reflex_class = reflex_name.constantize
29
31
  raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(reflex_class)
30
- reflex = reflex_class.new(self, url: url, element: element)
32
+ reflex = reflex_class.new(self, url: url, element: element, selectors: selectors)
31
33
  delegate_call_to_reflex reflex, method_name, arguments
32
34
  rescue => invoke_error
33
35
  return broadcast_error("StimulusReflex::Channel Failed to invoke #{target}! #{url} #{invoke_error}", data)
34
36
  end
35
37
 
36
38
  begin
37
- render_page_and_broadcast_morph url, reflex, data
39
+ render_page_and_broadcast_morph url, reflex, selectors, data
38
40
  rescue => render_error
39
41
  broadcast_error "StimulusReflex::Channel Failed to re-render #{url} #{render_error}", data
40
42
  end
@@ -60,9 +62,9 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
60
62
  end
61
63
  end
62
64
 
63
- def render_page_and_broadcast_morph(url, reflex, data = {})
65
+ def render_page_and_broadcast_morph(url, reflex, selectors, data = {})
64
66
  html = render_page(url, reflex)
65
- broadcast_morph url, html, data if html.present?
67
+ broadcast_morphs selectors, data, html if html.present?
66
68
  end
67
69
 
68
70
  def render_page(url, reflex)
@@ -96,20 +98,28 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
96
98
  controller.response.body
97
99
  end
98
100
 
99
- def broadcast_morph(url, html, data = {})
100
- html = extract_body_html(html)
101
- cable_ready[stream_name].morph selector: "body", html: html, children_only: true, stimulus_reflex: data
101
+ def broadcast_morphs(selectors, data, html)
102
+ document = Nokogiri::HTML(html)
103
+ selectors.each do |selector|
104
+ match = document.css(selector)
105
+ next if match.blank?
106
+ cable_ready[stream_name].morph(
107
+ selector: selector,
108
+ html: match.inner_html,
109
+ children_only: true,
110
+ permanent_attribute_name: "data-reflex-permanent",
111
+ stimulus_reflex: data
112
+ )
113
+ end
102
114
  cable_ready.broadcast
103
115
  end
104
116
 
105
117
  def broadcast_error(message, data = {})
106
118
  logger.error "\e[31m#{message}\e[0m"
107
- cable_ready[stream_name].dispatch_event name: "stimulus-reflex:500", detail: {stimulus_reflex: data.merge(error: message)}
119
+ cable_ready[stream_name].dispatch_event(
120
+ name: "stimulus-reflex:500",
121
+ detail: {stimulus_reflex: data.merge(error: message)}
122
+ )
108
123
  cable_ready.broadcast
109
124
  end
110
-
111
- def extract_body_html(html)
112
- doc = Nokogiri::HTML(html)
113
- doc.css("body").to_s
114
- end
115
125
  end
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StimulusReflex::Reflex
4
- attr_reader :channel, :url, :element
4
+ attr_reader :channel, :url, :element, :selectors
5
5
 
6
6
  delegate :connection, to: :channel
7
7
  delegate :session, to: :request
8
8
 
9
- def initialize(channel, url: nil, element: nil)
9
+ def initialize(channel, url: nil, element: nil, selectors: [])
10
10
  @channel = channel
11
11
  @url = url
12
12
  @element = element
13
+ @selectors = selectors
13
14
  end
14
15
 
15
16
  def request
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusReflex
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-30 00:00:00.000000000 Z
12
+ date: 2019-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 4.0.3
62
+ version: 4.0.7
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 4.0.3
69
+ version: 4.0.7
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +152,7 @@ files:
152
152
  - README.md
153
153
  - Rakefile
154
154
  - bin/console
155
+ - bin/loc
155
156
  - bin/setup
156
157
  - bin/standardize
157
158
  - lib/stimulus_reflex.rb