Skip to content

Commit e82e7b7

Browse files
committed
Simplify syntax of pipe procs for text & html
1 parent 2bc652f commit e82e7b7

File tree

8 files changed

+57
-54
lines changed

8 files changed

+57
-54
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Metrics/MethodLength:
4848
Naming/BlockForwarding:
4949
Enabled: false
5050

51+
Style/ArgumentsForwarding:
52+
Enabled: false
53+
5154
# Disabled to aid in template readability
5255
Style/NestedParenthesizedCalls:
5356
Enabled: false

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [0.5.0 - 2024-04-06
6+
7+
- Simplify syntax of pipe procs for text & html
8+
59
## [0.4.0] — 2024-04-04
610

711
- Provide Roda plugin to mix in Streamlined helpers.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ gem "minitest-reporters", "~> 1.5"
1313
gem "rubocop", "~> 1.21"
1414
gem "rubocop-bridgetown", "~> 0.4"
1515

16-
gem "solargraph", "~> 0.49.0"
16+
gem "solargraph", "~> 0.50"
1717

1818
gem "rails-dom-testing", "~> 2.0"
1919

Gemfile.lock

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
PATH
22
remote: .
33
specs:
4-
streamlined (0.4.0)
4+
streamlined (0.5.0)
55
serbea (>= 2.1)
66
zeitwerk (~> 2.5)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
activesupport (7.1.1)
11+
activesupport (7.1.3.2)
1212
base64
1313
bigdecimal
1414
concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -21,39 +21,38 @@ GEM
2121
ansi (1.5.0)
2222
ast (2.4.2)
2323
backport (1.2.0)
24-
base64 (0.1.1)
25-
benchmark (0.2.1)
26-
bigdecimal (3.1.4)
24+
base64 (0.2.0)
25+
benchmark (0.3.0)
26+
bigdecimal (3.1.7)
2727
builder (3.2.4)
28-
concurrent-ruby (1.2.2)
28+
concurrent-ruby (1.2.3)
2929
connection_pool (2.4.1)
30-
diff-lcs (1.5.0)
31-
drb (2.1.1)
32-
ruby2_keywords
30+
diff-lcs (1.5.1)
31+
drb (2.2.1)
3332
e2mmap (0.1.0)
3433
erubi (1.12.0)
35-
i18n (1.14.1)
34+
i18n (1.14.4)
3635
concurrent-ruby (~> 1.0)
3736
jaro_winkler (1.5.6)
38-
json (2.6.3)
37+
json (2.7.2)
3938
kramdown (2.4.0)
4039
rexml
4140
kramdown-parser-gfm (1.1.0)
4241
kramdown (~> 2.0)
4342
language_server-protocol (3.17.0.3)
44-
minitest (5.20.0)
43+
minitest (5.22.3)
4544
minitest-reporters (1.6.1)
4645
ansi
4746
builder
4847
minitest (>= 5.0)
4948
ruby-progressbar
50-
mutex_m (0.1.2)
51-
nokogiri (1.15.4-arm64-darwin)
49+
mutex_m (0.2.0)
50+
nokogiri (1.16.3-arm64-darwin)
5251
racc (~> 1.4)
53-
nokogiri (1.15.4-x86_64-linux)
52+
nokogiri (1.16.3-x86_64-linux)
5453
racc (~> 1.4)
55-
parallel (1.23.0)
56-
parser (3.2.2.4)
54+
parallel (1.24.0)
55+
parser (3.3.0.5)
5756
ast (~> 2.4.1)
5857
racc
5958
racc (1.7.3)
@@ -62,41 +61,40 @@ GEM
6261
minitest
6362
nokogiri (>= 1.6)
6463
rainbow (3.1.1)
65-
rake (13.1.0)
64+
rake (13.2.0)
6665
rbs (2.8.4)
67-
regexp_parser (2.8.2)
66+
regexp_parser (2.9.0)
6867
reverse_markdown (2.1.1)
6968
nokogiri
7069
rexml (3.2.6)
71-
rubocop (1.57.2)
70+
rubocop (1.62.1)
7271
json (~> 2.3)
7372
language_server-protocol (>= 3.17.0)
7473
parallel (~> 1.10)
75-
parser (>= 3.2.2.4)
74+
parser (>= 3.3.0.2)
7675
rainbow (>= 2.2.2, < 4.0)
7776
regexp_parser (>= 1.8, < 3.0)
7877
rexml (>= 3.2.5, < 4.0)
79-
rubocop-ast (>= 1.28.1, < 2.0)
78+
rubocop-ast (>= 1.31.1, < 2.0)
8079
ruby-progressbar (~> 1.7)
8180
unicode-display_width (>= 2.4.0, < 3.0)
82-
rubocop-ast (1.30.0)
83-
parser (>= 3.2.1.0)
81+
rubocop-ast (1.31.2)
82+
parser (>= 3.3.0.4)
8483
rubocop-bridgetown (0.4.1)
8584
rubocop (~> 1.23)
8685
rubocop-performance (~> 1.12)
8786
rubocop-minitest (0.20.1)
8887
rubocop (>= 0.90, < 2.0)
89-
rubocop-performance (1.19.1)
90-
rubocop (>= 1.7.0, < 2.0)
91-
rubocop-ast (>= 0.4.0)
88+
rubocop-performance (1.21.0)
89+
rubocop (>= 1.48.1, < 2.0)
90+
rubocop-ast (>= 1.31.1, < 2.0)
9291
rubocop-rake (0.6.0)
9392
rubocop (~> 1.0)
9493
ruby-progressbar (1.13.0)
95-
ruby2_keywords (0.0.5)
9694
serbea (2.1.0)
9795
erubi (>= 1.10)
9896
tilt (~> 2.0)
99-
solargraph (0.49.0)
97+
solargraph (0.50.0)
10098
backport (~> 1.2)
10199
benchmark
102100
bundler (~> 2.0)
@@ -112,13 +110,13 @@ GEM
112110
thor (~> 1.0)
113111
tilt (~> 2.0)
114112
yard (~> 0.9, >= 0.9.24)
115-
thor (1.3.0)
113+
thor (1.3.1)
116114
tilt (2.3.0)
117115
tzinfo (2.0.6)
118116
concurrent-ruby (~> 1.0)
119117
unicode-display_width (2.5.0)
120-
yard (0.9.34)
121-
zeitwerk (2.6.12)
118+
yard (0.9.36)
119+
zeitwerk (2.6.13)
122120

123121
PLATFORMS
124122
arm64-darwin-21
@@ -133,7 +131,7 @@ DEPENDENCIES
133131
rubocop-bridgetown (~> 0.4)
134132
rubocop-minitest (~> 0.20.0)
135133
rubocop-rake (~> 0.6.0)
136-
solargraph (~> 0.49.0)
134+
solargraph (~> 0.50)
137135
streamlined!
138136

139137
BUNDLED WITH

lib/streamlined/helpers.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
# frozen_string_literal: true
22

3+
require "tilt/erubi"
4+
35
module Streamlined
46
module Helpers
5-
module PipeableProc
6-
include Serbea::Pipeline::Helper
7-
8-
attr_accessor :pipe_block, :touched
9-
10-
def pipe(&block)
11-
return super(self.(), &pipe_block) if pipe_block && !block
7+
module TouchableProc
8+
attr_accessor :touched
129

10+
def touch
1311
self.touched = true
14-
return self unless block
15-
16-
tap { _1.pipe_block = block }
12+
self
1713
end
1814

1915
def html_safe
@@ -36,7 +32,7 @@ def encode(...)
3632
end
3733
end
3834

39-
::Proc.prepend(PipeableProc)
35+
::Proc.prepend(TouchableProc)
4036

4137
# Create a set of attributes from a hash.
4238
#
@@ -82,16 +78,20 @@ def attribute_segment(attr, value)
8278
"#{attr}=#{value.to_s.encode(xml: :attr)}"
8379
end
8480

85-
def text(callback)
86-
(callback.is_a?(Proc) ? callback.pipe : callback).to_s.then do |str|
81+
def text(callback, piping = nil)
82+
callback = Serbea::Pipeline.new(binding, callback).tap { _1.instance_exec(&piping) } if piping
83+
84+
(callback.is_a?(Proc) ? callback.touch : callback).to_s.then do |str|
8785
next str if str.html_safe?
8886

8987
str.encode(xml: :attr).gsub(%r{\A"|"\Z}, "")
9088
end
9189
end
9290

93-
def html(callback)
94-
callback.html_safe.pipe
91+
def html(callback, piping = nil)
92+
callback = Serbea::Pipeline.new(binding, callback).tap { _1.instance_exec(&piping) } if piping
93+
94+
callback.html_safe.touch
9595
end
9696

9797
def html_map(input, &callback)

lib/streamlined/renderable.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ def helpers
4545
@_view_context
4646
end
4747

48-
# rubocop:disable Style/ArgumentsForwarding
4948
def capture(*args, &block)
5049
helpers ? helpers.capture(*args, &block) : yield(*args)
5150
end
52-
# rubocop:enable Style/ArgumentsForwarding
5351
end
5452
end

lib/streamlined/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Streamlined
4-
VERSION = "0.4.0"
4+
VERSION = "0.5.0"
55
end

test/test_streamlined.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def template(&block)
5454
<section>
5555
<h1 #{html_attributes(false_value:, nil_value:, other_value:)}>#{text -> { heading }}</h1>
5656
<h2 class="#{text -> { tags_in_attribute }}">#{text -> { @name }}</h2>
57-
#{html -> { capture(self, &block) }}
58-
<footer>#{text -> { @number }.pipe { multiplied_by(10) }}</footer>
57+
#{html self, -> { capture -> { block } }}
58+
<footer>#{text @number, -> { multiplied_by(10) }}</footer>
5959
</section>
6060
HTML
6161
}

0 commit comments

Comments
 (0)