streamlined 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9f935f1b1697ca3f91e7f88e06dddc00e11a1ce3a511410eb727709657a9291
4
+ data.tar.gz: f4557e6da0e100db9fa2e6c8467c61ead04bc688b3153938fcea420b851cb086
5
+ SHA512:
6
+ metadata.gz: 006a5720f453344b5c83c1a1db4a08346b7574b3f3266920c5fd5ce001203b69824d60edca04e2beb7e4dd86230e1ce92f54a7bf0fd84726a48f8bcd7505ea6c
7
+ data.tar.gz: e6fac9d8eea670a6cc2f84476a1a05d0279c369ab6deaecaca56fe99116b3b7dc9d73671efa753524ac93dcafd2dac5302e1737ec746353da86d13bf145e6b91
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ require:
2
+ - rubocop-bridgetown
3
+ - rubocop-minitest
4
+ - rubocop-rake
5
+
6
+ inherit_gem:
7
+ rubocop-bridgetown: .rubocop.yml
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 3.0
11
+ NewCops: enable
12
+
13
+ Exclude:
14
+ - .gitignore
15
+ - .rubocop.yml
16
+ - "*.gemspec"
17
+
18
+ - Gemfile.lock
19
+ - CHANGELOG.md
20
+ - LICENSE.txt
21
+ - README.md
22
+ - Rakefile
23
+
24
+ - bin/**/*
25
+ - test/fixtures/**/*
26
+ - vendor/**/*
27
+
28
+ # Disabled to aid in template readability
29
+ Layout/MultilineBlockLayout:
30
+ Enabled: false
31
+
32
+ # Disabled to aid in template readability
33
+ Lint/AmbiguousBlockAssociation:
34
+ Enabled: false
35
+
36
+ Metrics/AbcSize:
37
+ Exclude:
38
+ - test/**/*.rb
39
+
40
+ Metrics/ClassLength:
41
+ Exclude:
42
+ - test/**/*.rb
43
+
44
+ Metrics/MethodLength:
45
+ Exclude:
46
+ - test/**/*.rb
47
+
48
+ # Disabled to aid in template readability
49
+ Style/NestedParenthesizedCalls:
50
+ Enabled: false
51
+
52
+ Layout/LineLength:
53
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.2.0] - 2023-11-07
6
+
7
+ - Back out of more complicated `render_in` mechanics
8
+
9
+ ## [0.1.0] - 2023-11-04
10
+
11
+ - Extraction from Bridgetown & Lifeform to serve as a standalone gem.
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jared@jaredwhite.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in streamlined.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+ gem "minitest-reporters", "~> 1.5"
12
+
13
+ gem "rubocop", "~> 1.21"
14
+ gem "rubocop-bridgetown", "~> 0.4"
15
+
16
+ gem "solargraph", "~> 0.49.0"
17
+
18
+ gem "rails-dom-testing", "~> 2.0"
19
+
20
+ gem "rubocop-minitest", "~> 0.20.0"
21
+ gem "rubocop-rake", "~> 0.6.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,140 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ streamlined (0.2.0)
5
+ serbea (>= 2.1)
6
+ zeitwerk (~> 2.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.1.1)
12
+ base64
13
+ bigdecimal
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ connection_pool (>= 2.2.5)
16
+ drb
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ mutex_m
20
+ tzinfo (~> 2.0)
21
+ ansi (1.5.0)
22
+ ast (2.4.2)
23
+ backport (1.2.0)
24
+ base64 (0.1.1)
25
+ benchmark (0.2.1)
26
+ bigdecimal (3.1.4)
27
+ builder (3.2.4)
28
+ concurrent-ruby (1.2.2)
29
+ connection_pool (2.4.1)
30
+ diff-lcs (1.5.0)
31
+ drb (2.1.1)
32
+ ruby2_keywords
33
+ e2mmap (0.1.0)
34
+ erubi (1.12.0)
35
+ i18n (1.14.1)
36
+ concurrent-ruby (~> 1.0)
37
+ jaro_winkler (1.5.6)
38
+ json (2.6.3)
39
+ kramdown (2.4.0)
40
+ rexml
41
+ kramdown-parser-gfm (1.1.0)
42
+ kramdown (~> 2.0)
43
+ language_server-protocol (3.17.0.3)
44
+ minitest (5.20.0)
45
+ minitest-reporters (1.6.1)
46
+ ansi
47
+ builder
48
+ minitest (>= 5.0)
49
+ ruby-progressbar
50
+ mutex_m (0.1.2)
51
+ nokogiri (1.15.4-arm64-darwin)
52
+ racc (~> 1.4)
53
+ nokogiri (1.15.4-x86_64-linux)
54
+ racc (~> 1.4)
55
+ parallel (1.23.0)
56
+ parser (3.2.2.4)
57
+ ast (~> 2.4.1)
58
+ racc
59
+ racc (1.7.3)
60
+ rails-dom-testing (2.2.0)
61
+ activesupport (>= 5.0.0)
62
+ minitest
63
+ nokogiri (>= 1.6)
64
+ rainbow (3.1.1)
65
+ rake (13.1.0)
66
+ rbs (2.8.4)
67
+ regexp_parser (2.8.2)
68
+ reverse_markdown (2.1.1)
69
+ nokogiri
70
+ rexml (3.2.6)
71
+ rubocop (1.57.2)
72
+ json (~> 2.3)
73
+ language_server-protocol (>= 3.17.0)
74
+ parallel (~> 1.10)
75
+ parser (>= 3.2.2.4)
76
+ rainbow (>= 2.2.2, < 4.0)
77
+ regexp_parser (>= 1.8, < 3.0)
78
+ rexml (>= 3.2.5, < 4.0)
79
+ rubocop-ast (>= 1.28.1, < 2.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (>= 2.4.0, < 3.0)
82
+ rubocop-ast (1.30.0)
83
+ parser (>= 3.2.1.0)
84
+ rubocop-bridgetown (0.4.0)
85
+ rubocop (~> 1.23)
86
+ rubocop-performance (~> 1.12)
87
+ rubocop-minitest (0.20.1)
88
+ rubocop (>= 0.90, < 2.0)
89
+ rubocop-performance (1.19.1)
90
+ rubocop (>= 1.7.0, < 2.0)
91
+ rubocop-ast (>= 0.4.0)
92
+ rubocop-rake (0.6.0)
93
+ rubocop (~> 1.0)
94
+ ruby-progressbar (1.13.0)
95
+ ruby2_keywords (0.0.5)
96
+ serbea (2.1.0)
97
+ erubi (>= 1.10)
98
+ tilt (~> 2.0)
99
+ solargraph (0.49.0)
100
+ backport (~> 1.2)
101
+ benchmark
102
+ bundler (~> 2.0)
103
+ diff-lcs (~> 1.4)
104
+ e2mmap
105
+ jaro_winkler (~> 1.5)
106
+ kramdown (~> 2.3)
107
+ kramdown-parser-gfm (~> 1.1)
108
+ parser (~> 3.0)
109
+ rbs (~> 2.0)
110
+ reverse_markdown (~> 2.0)
111
+ rubocop (~> 1.38)
112
+ thor (~> 1.0)
113
+ tilt (~> 2.0)
114
+ yard (~> 0.9, >= 0.9.24)
115
+ thor (1.3.0)
116
+ tilt (2.3.0)
117
+ tzinfo (2.0.6)
118
+ concurrent-ruby (~> 1.0)
119
+ unicode-display_width (2.5.0)
120
+ yard (0.9.34)
121
+ zeitwerk (2.6.12)
122
+
123
+ PLATFORMS
124
+ arm64-darwin-21
125
+ x86_64-linux
126
+
127
+ DEPENDENCIES
128
+ minitest (~> 5.0)
129
+ minitest-reporters (~> 1.5)
130
+ rails-dom-testing (~> 2.0)
131
+ rake (~> 13.0)
132
+ rubocop (~> 1.21)
133
+ rubocop-bridgetown (~> 0.4)
134
+ rubocop-minitest (~> 0.20.0)
135
+ rubocop-rake (~> 0.6.0)
136
+ solargraph (~> 0.49.0)
137
+ streamlined!
138
+
139
+ BUNDLED WITH
140
+ 2.3.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Jared White and Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Streamlined
2
+
3
+ Component rendering for Ruby using streamlined procs & heredocs. Rails and Bridgetown both supported.
4
+
5
+ ## Installation
6
+
7
+ Add Streamlined to your application's Gemfile by running:
8
+
9
+ ```sh
10
+ bundle add streamlined
11
+ ```
12
+
13
+ (If you're using Bridgetown, it's bundled in for Bridgetown 1.4…coming soon)
14
+
15
+ ## Usage
16
+
17
+ Docs forthcoming...
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
22
+
23
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bridgetownrb/streamlined. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bridgetownrb/streamlined/blob/main/CODE_OF_CONDUCT.md).
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the Streamlined project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bridgetownrb/streamlined/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.warning = false
10
+ t.test_files = FileList["test/**/test_*.rb"]
11
+ end
12
+
13
+ require "rubocop/rake_task"
14
+
15
+ RuboCop::RakeTask.new
16
+
17
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "streamlined"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("bundle", __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("bundle", __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Streamlined
4
+ 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
12
+
13
+ self.touched = true
14
+ return self unless block
15
+
16
+ tap { _1.pipe_block = block }
17
+ end
18
+
19
+ def html_safe
20
+ @html_safe = true
21
+ self
22
+ end
23
+
24
+ def html_safe?
25
+ @html_safe == true
26
+ end
27
+
28
+ def to_s
29
+ return self.().to_s.then { html_safe? ? _1.html_safe : _1 } if touched
30
+
31
+ super
32
+ end
33
+
34
+ def encode(...)
35
+ to_s.encode(...)
36
+ end
37
+ end
38
+
39
+ ::Proc.prepend(PipeableProc)
40
+
41
+ # Create a set of attributes from a hash.
42
+ #
43
+ # @param options [Hash] key-value pairs of HTML attributes (or use keyword arguments)
44
+ # @param prefix_space [Boolean] add a starting space if attributes are present,
45
+ # useful in tag builders
46
+ # @return [String]
47
+ def html_attributes(options = nil, prefix_space: false, **kwargs)
48
+ options ||= kwargs
49
+ segments = []
50
+ options.each do |attr, option|
51
+ attr = dashed(attr)
52
+ if option.is_a?(Hash)
53
+ option = option.transform_keys { |key| "#{attr}-#{dashed(key)}" }
54
+ segments << html_attributes(option)
55
+ else
56
+ segments << attribute_segment(attr, option)
57
+ end
58
+ end
59
+ segments.join(" ").then do |output|
60
+ prefix_space && !output.empty? ? " #{output}" : output
61
+ end
62
+ end
63
+
64
+ # Covert an underscored value into a dashed string.
65
+ #
66
+ # @example "foo_bar_baz" => "foo-bar-baz"
67
+ #
68
+ # @param value [String|Symbol]
69
+ # @return [String]
70
+ def dashed(value)
71
+ value.to_s.tr("_", "-")
72
+ end
73
+
74
+ # Create an attribute segment for a tag.
75
+ #
76
+ # @param attr [String] the HTML attribute name
77
+ # @param value [String] the attribute value
78
+ # @return [String]
79
+ def attribute_segment(attr, value)
80
+ "#{attr}=#{value.to_s.encode(xml: :attr)}"
81
+ end
82
+
83
+ def text(callback)
84
+ (callback.is_a?(Proc) ? html(callback) : callback).to_s.then do |str|
85
+ next str if str.html_safe?
86
+
87
+ str.encode(xml: :attr).gsub(%r{\A"|"\Z}, "")
88
+ end
89
+ end
90
+
91
+ def html(callback)
92
+ callback.html_safe.pipe
93
+ end
94
+
95
+ def html_map(input, &callback)
96
+ input.map(&callback).join
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Streamlined
4
+ module Renderable
5
+ include Streamlined::Helpers
6
+
7
+ class OutputBuffer < String
8
+ def initialize
9
+ super
10
+ @html_safe = true
11
+ end
12
+ end
13
+
14
+ def render_in(view_context, &block)
15
+ @_view_context = view_context
16
+ template(&block).to_s.strip
17
+ end
18
+
19
+ def render(item = nil, **options, &block) # rubocop:disable Metrics
20
+ return @_rbout if !block && options.empty? && item.nil?
21
+
22
+ if item.is_a?(Proc) || (block && item.nil?)
23
+ result = item.is_a?(Proc) ? item.to_s : yield
24
+ return result if result.is_a?(OutputBuffer)
25
+
26
+ result = text(result) if result.is_a?(String) && !result.html_safe?
27
+
28
+ @_rbout ||= OutputBuffer.new
29
+ @_rbout << result.to_s
30
+
31
+ return @_rbout
32
+ end
33
+
34
+ if item.respond_to?(:render_in)
35
+ result = item.render_in(self, &block)
36
+ result&.to_s&.html_safe
37
+ else
38
+ raise Error, "You must implement a `partial' implementation yourself" unless respond_to?(:partial)
39
+
40
+ partial(item, **options, &block)&.html_safe
41
+ end
42
+ end
43
+
44
+ def helpers
45
+ @_view_context
46
+ end
47
+
48
+ # rubocop:disable Style/ArgumentsForwarding
49
+ def capture(*args, &block)
50
+ helpers ? helpers.capture(*args, &block) : yield(*args)
51
+ end
52
+ # rubocop:enable Style/ArgumentsForwarding
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Streamlined
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "serbea/helpers" # primarily just for HTML safety polyfill
4
+ require "serbea/pipeline"
5
+ require "zeitwerk"
6
+ loader = Zeitwerk::Loader.for_gem
7
+ loader.setup
8
+
9
+ module Streamlined
10
+ class Error < StandardError; end
11
+ end
12
+
13
+ if defined?(Bridgetown)
14
+ Bridgetown.initializer :streamlined do # |config|
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/streamlined/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "streamlined"
7
+ spec.version = Streamlined::VERSION
8
+ spec.author = "Bridgetown Team"
9
+ spec.email = "maintainers@bridgetownrb.com"
10
+
11
+ spec.summary = "Component rendering for Ruby using streamlined procs & heredocs."
12
+ spec.homepage = "https://github.com/bridgetownrb/streamlined"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.0"
15
+ spec.metadata["rubygems_mfa_required"] = "true"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
22
+ end
23
+ end
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "serbea", ">= 2.1"
27
+ spec.add_dependency "zeitwerk", "~> 2.5"
28
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: streamlined
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Bridgetown Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: serbea
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: zeitwerk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ description:
42
+ email: maintainers@bridgetownrb.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".rubocop.yml"
48
+ - ".ruby-version"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/rake
58
+ - bin/rubocop
59
+ - bin/setup
60
+ - lib/streamlined.rb
61
+ - lib/streamlined/helpers.rb
62
+ - lib/streamlined/renderable.rb
63
+ - lib/streamlined/version.rb
64
+ - streamlined.gemspec
65
+ homepage: https://github.com/bridgetownrb/streamlined
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ rubygems_mfa_required: 'true'
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '3.0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Component rendering for Ruby using streamlined procs & heredocs.
89
+ test_files: []