cable_ready 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cde8a8432716d621f81ee6da1cf536e4e8fd1c1
4
- data.tar.gz: 66d5621b36f528677331b4067ed20ea8379033d7
3
+ metadata.gz: 46d93ee8a3d6c9c96279beb3e2a9a7c37aab209a
4
+ data.tar.gz: b1d4cf53a5f5eaeca125028270691a1aafebc760
5
5
  SHA512:
6
- metadata.gz: 4893b800ff4e87f8960dc116b1bc6520c537d7534454d3c90cbf9e5bfaccbe8921520424fd2ed37312a8761ab54c028e5603ebf698a0ea023ced65bd030e0802
7
- data.tar.gz: 2a101cb0562f074ac1335fb44b9193b30b7ac115f5ba7601bb0d5287020085251564832b49d7af5f5031571884bbdac171710d42958836488eff9e8b4cf0f210
6
+ metadata.gz: 61faf1a5d2ca86c75372ddad5a8b0182bc4a1c85cff77fd03ccf13ac1d24cbd97b6d75b07ee4103c1a8bb00ceebb7287519bffca30ac9a07ea5f2a1ee1e6b3e7
7
+ data.tar.gz: a0709a74d6e85976c90c21511245a668efe857d375cd973353b24c5820f607dc17d49f6035b05e8038cec2b9a7db6f24b235e9abe08246b1985f78a89ffc858b
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cable_ready (2.0.2)
4
+ cable_ready (2.0.3)
5
5
  activesupport (>= 5.0.0)
6
+ htmlcompressor (~> 0.3.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -25,7 +26,8 @@ GEM
25
26
  tins (~> 1.6)
26
27
  debug_inspector (0.0.3)
27
28
  docile (1.1.5)
28
- i18n (0.9.0)
29
+ htmlcompressor (0.3.1)
30
+ i18n (0.9.1)
29
31
  concurrent-ruby (~> 1.0)
30
32
  interception (0.5)
31
33
  json (2.1.0)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Lines of Code](http://img.shields.io/badge/lines_of_code-114-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-232-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![Code Status](http://img.shields.io/codeclimate/github/hopsoft/cable_ready.svg?style=flat)](https://codeclimate.com/github/hopsoft/cable_ready)
3
3
  [![Dependency Status](http://img.shields.io/gemnasium/hopsoft/cable_ready.svg?style=flat)](https://gemnasium.com/hopsoft/cable_ready)
4
4
 
@@ -13,18 +13,6 @@ from the server via [ActionCable](http://guides.rubyonrails.org/action_cable_ove
13
13
 
14
14
  > Please read the official [ActionCable docs](http://guides.rubyonrails.org/action_cable_overview.html) to learn more about ActionCable before proceeding.
15
15
 
16
- ```ruby
17
- # app/models/user.rb
18
- class User < ApplicationRecord
19
- include CableReady::Broadcaster
20
-
21
- def broadcast_name_change
22
- cable_ready["UserChannel"].text_content selector: "#user-name", text: name
23
- cable_ready.broadcast
24
- end
25
- end
26
- ```
27
-
28
16
  ```javascript
29
17
  // app/assets/javascripts/application.js
30
18
  /*
@@ -43,9 +31,25 @@ App.cable.subscriptions.create({ channel: "UserChannel" }, {
43
31
  });
44
32
  ```
45
33
 
34
+ ```ruby
35
+ # app/models/user.rb
36
+ class User < ApplicationRecord
37
+ include CableReady::Broadcaster
38
+
39
+ def broadcast_name_change
40
+ cable_ready["UserChannel"].text_content selector: "#user-name", text: name
41
+ cable_ready.broadcast
42
+ end
43
+ end
44
+ ```
45
+
46
+ See [CableReady TodoMVC](https://github.com/hopsoft/cable_ready_todomvc)
47
+ for a more complete reference implementation.
48
+
46
49
  ## Supported DOM Operations
47
50
 
48
51
  - [dispatchEvent](#dispatchevent)
52
+ - [morph](#morph)
49
53
  - [innerHTML](#innerhtml)
50
54
  - [insertAdjacentHTML](#insertAdjacentHTML)
51
55
  - [insertAdjacentText](#insertadjacenttext)
@@ -80,7 +84,7 @@ cable_ready["MyChannel"].dispatch_event(
80
84
 
81
85
  #### [morph](https://github.com/patrick-steele-idem/morphdom)
82
86
 
83
- Fast lightweight DOM diffing/patching without a virtual DOM.
87
+ [Fast lightweight DOM diffing/patching](https://github.com/patrick-steele-idem/morphdom) without a virtual DOM.
84
88
 
85
89
  ```ruby
86
90
  cable_ready["MyChannel"].morph(
@@ -1,6 +1,9 @@
1
+ require "htmlcompressor"
2
+
1
3
  module CableReady
2
4
  class Channel
3
5
  attr_reader :name, :operations
6
+ attr_accessor :compress_html
4
7
 
5
8
  # Example Operations Payload:
6
9
  #
@@ -15,10 +18,16 @@ module CableReady
15
18
  #
16
19
  # # Element Mutations ...........................................................................................
17
20
  #
21
+ # morph: [{
22
+ # selector: "string",
23
+ # focusSelector: "string",
24
+ # html: "string"
25
+ # }, ...],
26
+ #
18
27
  # inner_html: [{
19
- # selector: "string",
28
+ # selector: "string",
20
29
  # focusSelector: "string",
21
- # html: "string"
30
+ # html: "string"
22
31
  # }, ...],
23
32
  #
24
33
  # text_content: [{
@@ -27,10 +36,10 @@ module CableReady
27
36
  # }, ...]
28
37
  #
29
38
  # insert_adjacent_html: [{
30
- # selector: "string",
39
+ # selector: "string",
31
40
  # focusSelector: "string",
32
- # position: "string",
33
- # html: "string"
41
+ # position: "string",
42
+ # html: "string"
34
43
  # }, ...],
35
44
  #
36
45
  # insert_adjacent_text: [{
@@ -40,14 +49,14 @@ module CableReady
40
49
  # }, ...],
41
50
  #
42
51
  # remove: [{
43
- # selector: "string",
52
+ # selector: "string",
44
53
  # focusSelector: "string,
45
54
  # }, ...],
46
55
  #
47
56
  # replace: [{
48
- # selector: "string",
57
+ # selector: "string",
49
58
  # focusSelector: "string",
50
- # html: "string"
59
+ # html: "string"
51
60
  # }, ...],
52
61
  #
53
62
  # set_value: [{
@@ -91,6 +100,7 @@ module CableReady
91
100
  def initialize(name)
92
101
  @name = name
93
102
  @operations = stub
103
+ @compress_html = true
94
104
  end
95
105
 
96
106
  def clear
@@ -109,10 +119,12 @@ module CableReady
109
119
  end
110
120
 
111
121
  def morph(options={})
122
+ options[:html] = html_compressor.compress(options[:html].to_s) if compress_html
112
123
  operations[:morph] << options
113
124
  end
114
125
 
115
126
  def inner_html(options={})
127
+ options[:html] = html_compressor.compress(options[:html].to_s) if compress_html
116
128
  operations[:inner_html] << options
117
129
  end
118
130
 
@@ -121,6 +133,7 @@ module CableReady
121
133
  end
122
134
 
123
135
  def insert_adjacent_html(options={})
136
+ options[:html] = html_compressor.compress(options[:html].to_s) if compress_html
124
137
  operations[:insert_adjacent_html] << options
125
138
  end
126
139
 
@@ -133,6 +146,7 @@ module CableReady
133
146
  end
134
147
 
135
148
  def replace(options={})
149
+ options[:html] = html_compressor.compress(options[:html].to_s) if compress_html
136
150
  operations[:replace] << options
137
151
  end
138
152
 
@@ -180,5 +194,28 @@ module CableReady
180
194
  set_dataset_property: []
181
195
  }
182
196
  end
197
+
198
+ def html_compressor
199
+ @html_compressor ||= HtmlCompressor::Compressor.new(
200
+ enabled: true,
201
+ remove_multi_spaces: true,
202
+ remove_comments: true,
203
+ remove_intertag_spaces: false,
204
+ remove_quotes: true,
205
+ compress_css: false,
206
+ compress_javascript: false,
207
+ simple_doctype: false,
208
+ remove_script_attributes: true,
209
+ remove_style_attributes: true,
210
+ remove_link_attributes: true,
211
+ remove_form_attributes: false,
212
+ remove_input_attributes: true,
213
+ remove_javascript_protocol: true,
214
+ remove_http_protocol: false,
215
+ remove_https_protocol: false,
216
+ preserve_line_breaks: false,
217
+ simple_boolean_attributes: true
218
+ )
219
+ end
183
220
  end
184
221
  end
@@ -1,3 +1,3 @@
1
1
  module CableReady
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cable_ready
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlcompressor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement