html-native-rails 0.1.0 → 0.2.0
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 +4 -4
- data/lib/html-native-rails.rb +44 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7980d0dfbc077078e0a3784074f03f22db9662cba13d146bbb7ffe5d8a8c7a8
|
4
|
+
data.tar.gz: '093c5290bc66f9ab7a5a4e087aecd3ada80c0648f73fdb8d94ee422025f6b2a9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb297a62eb7170fd5a8b34e2152c942dac1b47c5f9369c7f2e6dfb698462fb3be66e6b490b00d8a716b2c04b832ddd337daf82781adfb7589efe224e4906232
|
7
|
+
data.tar.gz: 92b47ac7e93256a7c302c490ebe21545a3f07d88277d49d6848abd1d0c720c8fd1d9852d606618e33d87beb2bad3f1d6ab8cd6471a5580a01b264e90ac79ab03
|
data/lib/html-native-rails.rb
CHANGED
@@ -1,22 +1,62 @@
|
|
1
1
|
require "html-native"
|
2
2
|
require "rails"
|
3
3
|
|
4
|
+
# There is no need to alias methods into components or handle existing helper
|
5
|
+
# functions as Builders. This is handled by Builder implicitly converting to a string
|
6
|
+
|
7
|
+
class ActiveSupport::SafeBuffer
|
8
|
+
alias_method :html_component_old_plus, :+
|
9
|
+
alias_method :html_component_old_insert, :<<
|
10
|
+
alias_method :html_component_old_concat, :concat
|
11
|
+
def +(other)
|
12
|
+
if other.kind_of? HTMLComponent::Builder
|
13
|
+
self.component + other
|
14
|
+
else
|
15
|
+
self.html_component_old_plus(other)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def <<(other)
|
20
|
+
if other.kind_of? HTMLComponent::Builder
|
21
|
+
self.component + other
|
22
|
+
else
|
23
|
+
self.html_component_old_insert(other)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def concat(other)
|
28
|
+
if other.kind_of? HTMLComponent::Builder
|
29
|
+
self.component + other
|
30
|
+
else
|
31
|
+
self.html_component_old_insert(other)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
4
36
|
# HTMLComponent is included in ActionView::Base to make sure the HTMLComponent
|
5
37
|
# methods are available for rendering.
|
38
|
+
#
|
39
|
+
# As a note to my future self, restricting HTMLComponent to be specifically included
|
40
|
+
# when the view is first rendered might be a better idea, though I don't quite
|
41
|
+
# know how I'd do that right now.
|
6
42
|
class ActionView::Base
|
7
43
|
include HTMLComponent
|
8
44
|
end
|
9
45
|
|
10
|
-
# As a note to my future self, restricting that to be specifically included
|
11
|
-
# when the view is first rendered might be a better idea, though I don't quite
|
12
|
-
# know how I'd do that right now.
|
13
46
|
|
14
47
|
class HTMLComponent::Builder
|
15
48
|
# Converts the Builder instance to an HTML-safe String. This does not
|
16
49
|
# guarantee the string is valid HTML, just safe.
|
17
50
|
def to_s
|
18
|
-
@
|
51
|
+
unless @cached
|
52
|
+
@cache << @strings.join.html_safe
|
53
|
+
@strings.clear
|
54
|
+
@cached = true
|
55
|
+
end
|
56
|
+
@cache.html_safe
|
19
57
|
end
|
58
|
+
|
59
|
+
alias_method :to_str, :to_s
|
20
60
|
end
|
21
61
|
|
22
62
|
module HTMLNativeRails
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-native-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kellen Watt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html-native
|