Skip to content

Commit 2bc652f

Browse files
committed
Provide Roda plugin to mix in Streamlined helpers
1 parent 21f6799 commit 2bc652f

File tree

8 files changed

+45
-8
lines changed

8 files changed

+45
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [0.4.0] — 2024-04-04
6+
7+
- Provide Roda plugin to mix in Streamlined helpers.
8+
59
## [0.3.1] - 2023-11-10
610

711
- Ensure false or nil values for attributes avoid rendering attributes at all

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
streamlined (0.3.1)
4+
streamlined (0.4.0)
55
serbea (>= 2.1)
66
zeitwerk (~> 2.5)
77

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Streamlined
22

3-
Component rendering for Ruby using streamlined procs & heredocs. Rails and Bridgetown both supported.
3+
HTML fragment and component rendering for Ruby using streamlined procs & heredocs with safety checks via RuboCop. Bridgetown, Roda, and Rails all supported.
44

55
## Installation
66

@@ -10,7 +10,7 @@ Add Streamlined to your application's Gemfile by running:
1010
bundle add streamlined
1111
```
1212

13-
(If you're using Bridgetown, it's bundled in for Bridgetown 1.4…coming soon)
13+
(If you're using Bridgetown, it's bundled in for Bridgetown 2.0…coming soon)
1414

1515
## Usage
1616

lib/roda/plugins/streamlined.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
class Roda
4+
module RodaPlugins
5+
module Streamlined
6+
module CheckForStreamlined
7+
def self.===(other)
8+
other.is_a?(Proc) && other.respond_to?(:touched) && other.touched
9+
end
10+
end
11+
12+
module InstanceMethods
13+
include ::Streamlined::Helpers
14+
end
15+
16+
def self.load_dependencies(app, _opts = OPTS)
17+
app.plugin :custom_block_results
18+
end
19+
20+
def self.configure(app, _opts = OPTS)
21+
app.handle_block_result CheckForStreamlined, &:to_s
22+
end
23+
end
24+
25+
register_plugin :streamlined, Streamlined
26+
end
27+
end

lib/streamlined.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
require "serbea/pipeline"
55
require "zeitwerk"
66
loader = Zeitwerk::Loader.for_gem
7+
loader.ignore("#{__dir__}/roda")
78
loader.setup
89

910
module Streamlined
1011
class Error < StandardError; end
1112
end
1213

1314
if defined?(Bridgetown)
14-
Bridgetown.initializer :streamlined do # |config|
15+
Bridgetown.initializer :streamlined do |config|
16+
config.roda do |app|
17+
app.plugin :streamlined
18+
end
1519
end
1620
end

lib/streamlined/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

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

streamlined.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Gem::Specification.new do |spec|
88
spec.author = "Bridgetown Team"
99
spec.email = "[email protected]"
1010

11-
spec.summary = "Component rendering for Ruby using streamlined procs & heredocs."
11+
spec.summary = "HTML fragment & component rendering for Ruby using streamlined procs & heredocs."
1212
spec.homepage = "https://github.com/bridgetownrb/streamlined"
1313
spec.license = "MIT"
14-
spec.required_ruby_version = ">= 3.0"
14+
spec.required_ruby_version = ">= 3.1"
1515
spec.metadata["rubygems_mfa_required"] = "true"
1616

1717
# Specify which files should be added to the gem when it is released.

test/test_streamlined.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ def template(&block)
4848
false_value = false
4949
nil_value = nil
5050
other_value = 123
51+
tags_in_attribute = "<h3>Whoa</h3>"
5152

5253
render html -> { <<~HTML
5354
<section>
5455
<h1 #{html_attributes(false_value:, nil_value:, other_value:)}>#{text -> { heading }}</h1>
55-
<h2>#{text -> { @name }}</h2>
56+
<h2 class="#{text -> { tags_in_attribute }}">#{text -> { @name }}</h2>
5657
#{html -> { capture(self, &block) }}
5758
<footer>#{text -> { @number }.pipe { multiplied_by(10) }}</footer>
5859
</section>
@@ -108,6 +109,7 @@ def test_component_output
108109
# test a couple of things on the raw HTML output
109110
assert_includes rendered_markup, "I should be &lt;&quot;escaped&quot;&gt;"
110111
assert_includes rendered_markup, %(<h1 other-value="123">)
112+
assert_includes rendered_markup, "<h2 class=\"&lt;h3&gt;Whoa&lt;/h3&gt;\">"
111113

112114
document_root(rendered_markup)
113115

0 commit comments

Comments
 (0)