ride_the_streetcar 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aad963b2cccd682cb67cf84a2f04095ab7570a745a2d39df3a3eeb932e4b8c7d
4
+ data.tar.gz: d07c479535b6efb196f0c2d3e04591ab5d7c1d186fc3274d581826e00df28529
5
+ SHA512:
6
+ metadata.gz: bb2ee1f86d6d87da0ecedb3b1dfe27b8974d1a58fe4dfab26a6ea60252336b7f3570853201d5250e92c13b0299928532ae10ba2f89380e895a0e6f5d2b7a8dc2
7
+ data.tar.gz: c2ba62ceab209a82c78f91118e86210587dd9f38038b61cd9d9270eebff9a26fdb7278dab64fd9cf52416d8af1680c156c589e59ab66f5305a1876f14fe7f64f
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ require: rubocop-bridgetown
2
+ inherit_gem:
3
+ rubocop-bridgetown: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.2
7
+
8
+ Style/FrozenStringLiteralComment:
9
+ Enabled: false
10
+
11
+ Layout/SpaceBeforeBlockBraces:
12
+ Enabled: false
13
+
14
+ Layout/SpaceBeforeFirstArg:
15
+ Enabled: false
16
+
17
+ Layout/MultilineBlockLayout:
18
+ Enabled: false
19
+
20
+ Lint/Void:
21
+ Exclude:
22
+ - test/**/*.rb
data/.solargraph.yml ADDED
@@ -0,0 +1,12 @@
1
+ include:
2
+ - "**/*.rb"
3
+ exclude:
4
+ - vendor/**/*
5
+ - ".bundle/**/*"
6
+ require:
7
+ - "bridgetown-foundation"
8
+ domains: []
9
+ reporters:
10
+ - rubocop
11
+ - require_not_found
12
+ max_files: 5000
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.2.0] - 2026-07-15
6
+
7
+ Add `dsl` shortcut, `dispatch_event` and `navigate`
8
+
9
+ ## [0.1.0] - 2025-10-13
10
+
11
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ require "ride_the_streetcar"
2
+
3
+ guard :minitest do
4
+ # with Minitest::Unit
5
+ watch(%r{^test/(.*)/?test_(.*)\.rb$})
6
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
7
+ watch(%r{^test/minitest_helper\.rb$}) { "test" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025-2026 Jared White
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,41 @@
1
+ # Ride The Streetcar 🚋
2
+ ## Ruby Backend (by the ❤️ Heartml project)
3
+
4
+ This is the Ruby server-side component of Ride The Streetcar. You will also need to install the [JavaScript frontend](https://codeberg.org/heartml/streetcar-elements). ([Looking for a JavaScript backend instead?](https://codeberg.org/heartml/ride-the-streetcar-js))
5
+
6
+ ----
7
+
8
+ > [!NOTE]
9
+ > A work in progress! Docs coming upon release!
10
+
11
+ ## Installation
12
+
13
+ Requires Ruby 3.2 or later.
14
+
15
+ Install the gem and add to the application's Gemfile by executing:
16
+
17
+ ```bash
18
+ bundle add ride_the_streetcar
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ 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/guard` which lets you watch tests as you modify them as well as interact with the gem using Pry.
28
+
29
+ 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 `bundle exec 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ride_the_streetcar. 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/[USERNAME]/ride_the_streetcar/blob/main/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the RideTheStreetcar project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ride_the_streetcar/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[rubocop test]
@@ -0,0 +1,20 @@
1
+ module RideTheStreetcar
2
+ class Apply
3
+ include Streamlined::Renderable
4
+
5
+ def initialize(method_chain, *args)
6
+ @method_chain = method_chain
7
+ @args = args
8
+ end
9
+
10
+ def template
11
+ attributes = { method: @method_chain }
12
+ attributes[:args] = @args.to_json unless @args.empty?
13
+
14
+ html -> { <<~HTML
15
+ <sc-apply #{html_attributes attributes}></sc-apply>
16
+ HTML
17
+ }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module RideTheStreetcar
2
+ class ClassList
3
+ include Streamlined::Renderable
4
+
5
+ def statements = @statements ||= []
6
+
7
+ def add(class_names)
8
+ joined_names = Array(class_names).join(",")
9
+
10
+ statements << { add: joined_names }
11
+ end
12
+
13
+ def remove(class_names)
14
+ joined_names = Array(class_names).join(",")
15
+
16
+ statements << { remove: joined_names }
17
+ end
18
+
19
+ def toggle(name, force: nil)
20
+ statements << { toggle: name, force: }
21
+ end
22
+
23
+ def template
24
+ html -> { <<~HTML
25
+ #{html_map(statements) do |statement|
26
+ html -> { <<~HTML
27
+ <sc-class-list #{html_attributes statement}></sc-class-list>
28
+ HTML
29
+ }
30
+ end}
31
+ HTML
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ module RideTheStreetcar
2
+ class Console
3
+ include Streamlined::Renderable
4
+
5
+ def statements = @statements ||= []
6
+
7
+ def debug(message)
8
+ statements << { debug: message }
9
+ end
10
+
11
+ def log(message)
12
+ statements << { log: message }
13
+ end
14
+
15
+ def info(message)
16
+ statements << { info: message }
17
+ end
18
+
19
+ def warn(message)
20
+ statements << { warn: message }
21
+ end
22
+
23
+ def error(message)
24
+ statements << { error: message }
25
+ end
26
+
27
+ def template
28
+ html -> { <<~HTML
29
+ #{html_map(statements) do |statement|
30
+ html -> { <<~HTML
31
+ <sc-console #{html_attributes statement}></sc-console>
32
+ HTML
33
+ }
34
+ end}
35
+ HTML
36
+ }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ module RideTheStreetcar
2
+ class Custom
3
+ include Streamlined::Renderable
4
+
5
+ #
6
+ attr_reader :tag_name
7
+
8
+ #
9
+ attr_reader :attributes
10
+
11
+ #
12
+ attr_reader :block
13
+
14
+ def initialize(tag_name, **attributes, &block)
15
+ @tag_name = tag_name.to_s.tr("_", "-").prepend("sc-c-")
16
+ @attributes = attributes
17
+ @block = block
18
+ end
19
+
20
+ def template
21
+ interior = helpers.capture(&block).then { "<template>#{_1.to_s.strip}</template>" } if block
22
+ tag_name = self.tag_name.then { attributes.empty? ? _1 : "#{_1} " }
23
+
24
+ html -> { <<~HTML.strip
25
+ <#{text tag_name}#{html_attributes attributes}>#{html->{ interior }}</#{text tag_name.strip}>
26
+ HTML
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "statements_list"
2
+
3
+ module RideTheStreetcar
4
+ class DSL
5
+ include Streamlined::Renderable
6
+ include StatementsList
7
+
8
+ def statements = @statements ||= []
9
+
10
+ # Write your Streetcar logic within a block using the DSL
11
+ #
12
+ # @param start_transition [Boolean]
13
+ # @yieldparam [RideTheStreetcar::DSL]
14
+ # @return [String] serialized statements HTML output
15
+ def ride(start_transition: false, &block)
16
+ @start_transition = start_transition
17
+ block.arity == 1 ? yield(self) : instance_exec(&block)
18
+
19
+ template.to_s.strip.tap { @statements.clear }
20
+ end
21
+
22
+ # rubocop:disable Style/IfUnlessModifier
23
+ def template
24
+ html->{ <<~HTML
25
+ <sc-line#{text -> { " start-transition" } if @start_transition}>#{html_map(statements) { |statement| render(statement) }}</sc-line>
26
+ HTML
27
+ }
28
+ end
29
+ # rubocop:enable Style/IfUnlessModifier
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module RideTheStreetcar
2
+ class JS
3
+ include Streamlined::Renderable
4
+
5
+ #
6
+ attr_reader :chain
7
+ #
8
+ attr_reader :args
9
+
10
+ def initialize
11
+ @chain = []
12
+ @args = []
13
+ end
14
+
15
+ def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToMissing
16
+ @args = args if args.length.positive?
17
+
18
+ chain << method_name
19
+ self
20
+ end
21
+
22
+ def set_property? = chain.last.end_with?("=")
23
+
24
+ def to_s
25
+ chain.join(".").delete_suffix("=")
26
+ end
27
+
28
+ def template
29
+ if set_property?
30
+ render SetProperty.new(to_s, args.first)
31
+ else
32
+ render Apply.new(to_s, *args)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,198 @@
1
+ module RideTheStreetcar
2
+ class QuerySelector
3
+ include Streamlined::Renderable
4
+
5
+ # @return [String]
6
+ attr_reader :selectors
7
+
8
+ # @return [Boolean]
9
+ attr_reader :all
10
+
11
+ def initialize(selectors, all: false)
12
+ @selectors = if selectors.respond_to?(:to_dom_selector)
13
+ selectors.to_dom_selector
14
+ elsif selectors.is_a?(Symbol)
15
+ selectors.to_s.tr("_", "-")
16
+ else
17
+ selectors.to_s
18
+ end
19
+ @all = all
20
+ end
21
+
22
+ def statements = @statements ||= []
23
+
24
+ def inner_html=(code)
25
+ statements << { inner_html: { code: } }
26
+ self # rubocop:disable Lint/Void
27
+ end
28
+ alias_method :inner_html, :inner_html=
29
+
30
+ def outer_html=(code)
31
+ statements << { outer_html: { code: } }
32
+ self # rubocop:disable Lint/Void
33
+ end
34
+ alias_method :outer_html, :inner_html=
35
+
36
+ def text_content=(code)
37
+ statements << { text_content: { code: } }
38
+ self # rubocop:disable Lint/Void
39
+ end
40
+ alias_method :text_content, :text_content=
41
+
42
+ def class_list
43
+ ClassList.new.tap { statements << { class_list: { obj: _1 } } }
44
+ end
45
+
46
+ def set_attribute(name, value)
47
+ name = normalize_name(name)
48
+ statements << { set_attribute: { name:, value: } }
49
+ self
50
+ end
51
+
52
+ def remove_attribute(name)
53
+ name = normalize_name(name)
54
+ statements << { remove_attribute: { name: } }
55
+ self
56
+ end
57
+
58
+ def toggle_attribute(name, force: nil)
59
+ name = normalize_name(name)
60
+ statements << { toggle_attribute: { name:, force: } }
61
+ self
62
+ end
63
+
64
+ def __insert(code)
65
+ statements << { __callee__ => { code: } }
66
+ self
67
+ end
68
+ alias_method :before, :__insert
69
+ alias_method :prepend, :__insert
70
+ alias_method :append, :__insert
71
+ alias_method :after, :__insert
72
+
73
+ def remove
74
+ statements << { remove: {} }
75
+ self
76
+ end
77
+
78
+ def apply(...)
79
+ Apply.new(...).tap { statements << { apply: { obj: _1 } } }
80
+ self
81
+ end
82
+
83
+ def set_property(...)
84
+ SetProperty.new(...).tap { statements << { set_property: { obj: _1 } } }
85
+ self
86
+ end
87
+
88
+ def set_style(name, value)
89
+ name = name.to_s.gsub(%r!_[a-z]!) { _1[1].upcase }
90
+ statements << { set_style: { name:, value: } }
91
+ self
92
+ end
93
+
94
+ def dispatch_event(name, bubbles: false, cancelable: false, composed: false, detail: nil) # rubocop:disable Metrics/ParameterLists
95
+ extra_details = detail.nil? ? {} : { detail: detail.to_json }
96
+
97
+ statements << { dispatch_event: { name:, bubbles:, cancelable:, composed:, **extra_details } }
98
+ self
99
+ end
100
+
101
+ # TODO: setTimeout
102
+
103
+ def js
104
+ JS.new.tap { statements << { js: { obj: _1 } } }
105
+ end
106
+
107
+ def custom(...)
108
+ Custom.new(...).tap { statements << { custom: { obj: _1 } } }
109
+ end
110
+
111
+ def template
112
+ html->{ <<~HTML
113
+ <sc-query-selector#{text->{ " all" } if all} selectors="#{text->{ selectors }}">#{
114
+ html_map(statements) { |statement| output_statement(statement) }
115
+ }</sc-query-selector>
116
+ HTML
117
+ }
118
+ end
119
+
120
+ private
121
+
122
+ def normalize_name(name) = name.to_s.tr("_", "-")
123
+
124
+ def output_statement(statement)
125
+ name, kwargs = statement.to_a.first
126
+ send("#{name}_statement", **kwargs)
127
+ end
128
+
129
+ def inner_html_statement(code:)
130
+ "<sc-inner-html><template>#{code}</template></sc-inner-html>"
131
+ end
132
+
133
+ def outer_html_statement(code:)
134
+ "<sc-outer-html><template>#{code}</template></sc-outer-html>"
135
+ end
136
+
137
+ def text_content_statement(code:)
138
+ "<sc-text-content><template>#{code}</template></sc-text-content>"
139
+ end
140
+
141
+ def set_attribute_statement(**attrs)
142
+ html -> { <<~HTML.strip
143
+ <sc-set-attribute #{html_attributes attrs}></sc-set-attribute>
144
+ HTML
145
+ }
146
+ end
147
+
148
+ def remove_attribute_statement(**attrs)
149
+ html -> { <<~HTML.strip
150
+ <sc-remove-attribute #{html_attributes attrs}></sc-remove-attribute>
151
+ HTML
152
+ }
153
+ end
154
+
155
+ def toggle_attribute_statement(**attrs)
156
+ html -> { <<~HTML.strip
157
+ <sc-toggle-attribute #{html_attributes attrs}></sc-toggle-attribute>
158
+ HTML
159
+ }
160
+ end
161
+
162
+ def append_statement(code:)
163
+ tag_name = __callee__.to_s.delete_suffix("_statement")
164
+ "<sc-#{tag_name}><template>#{code}</template></sc-#{tag_name}>"
165
+ end
166
+ alias_method :before_statement, :append_statement
167
+ alias_method :prepend_statement, :append_statement
168
+ alias_method :after_statement, :append_statement
169
+
170
+ def remove_statement(*)
171
+ "<sc-remove></sc-remove>"
172
+ end
173
+
174
+ def class_list_statement(obj:) = render(obj)
175
+
176
+ def apply_statement(obj:) = render(obj)
177
+
178
+ def set_property_statement(obj:) = render(obj)
179
+
180
+ def set_style_statement(**attrs)
181
+ html -> { <<~HTML.strip
182
+ <sc-set-style #{html_attributes attrs}></sc-set-style>
183
+ HTML
184
+ }
185
+ end
186
+
187
+ def dispatch_event_statement(**attrs)
188
+ html -> { <<~HTML.strip
189
+ <sc-dispatch-event #{html_attributes attrs}></sc-dispatch-event>
190
+ HTML
191
+ }
192
+ end
193
+
194
+ def js_statement(obj:) = render(obj)
195
+
196
+ def custom_statement(obj:) = render(obj)
197
+ end
198
+ end
@@ -0,0 +1,17 @@
1
+ module RideTheStreetcar
2
+ class SetProperty
3
+ include Streamlined::Renderable
4
+
5
+ def initialize(object_chain, value)
6
+ @object_chain = object_chain
7
+ @value = value.to_json
8
+ end
9
+
10
+ def template
11
+ html -> { <<~HTML
12
+ <sc-set-property name="#{text->{ @object_chain }}" value="#{text->{ @value }}"></sc-set-property>
13
+ HTML
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module RideTheStreetcar
2
+ module StatementsList
3
+ class Navigate
4
+ include Streamlined::Renderable
5
+
6
+ def initialize(href:)
7
+ @href = href
8
+ end
9
+
10
+ def template
11
+ html -> { <<~HTML
12
+ <sc-navigate href="#{text->{ @href }}"></sc-navigate>
13
+ HTML
14
+ }
15
+ end
16
+ end
17
+
18
+ def query_selector(selectors) = QuerySelector.new(selectors).tap { statements << _1 }
19
+ alias_method :q, :query_selector
20
+
21
+ def [](selectors) = query_selector(selectors)
22
+
23
+ def query_selector_all(selectors) =
24
+ QuerySelector.new(selectors, all: true).tap { statements << _1 }
25
+
26
+ alias_method :q_all, :query_selector_all
27
+
28
+ def console = Console.new.tap { statements << _1 }
29
+
30
+ def apply(...) = Apply.new(...).tap { statements << _1 }
31
+
32
+ def set_property(...) = SetProperty.new(...).tap { statements << _1 }
33
+
34
+ def js = JS.new.tap { statements << _1 }
35
+
36
+ def custom(...) = Custom.new(...).tap { statements << _1 }
37
+
38
+ def navigate(href) = Navigate.new(href:).tap { statements << _1 }
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RideTheStreetcar
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "ride_the_streetcar/version"
2
+ require "json"
3
+ require "streamlined"
4
+
5
+ module RideTheStreetcar
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+
9
+ # Provides a new "streetcar" to "ride" (aka the Streetcar DSL)
10
+ #
11
+ # @return [StreetcarDSL]
12
+ def self.dsl = DSL.new
13
+
14
+ # @param mod [Module]
15
+ def self.customize(mod)
16
+ DSL.include mod
17
+ DSL.include mod::GlobalStatements if mod.const_defined?(:GlobalStatements)
18
+ QuerySelector.include mod
19
+ QuerySelector.include mod::QueryStatements if mod.const_defined?(:QueryStatements)
20
+
21
+ self
22
+ end
23
+ end
24
+
25
+ require_relative "ride_the_streetcar/apply"
26
+ require_relative "ride_the_streetcar/custom"
27
+ require_relative "ride_the_streetcar/class_list"
28
+ require_relative "ride_the_streetcar/console"
29
+ require_relative "ride_the_streetcar/js"
30
+ require_relative "ride_the_streetcar/set_property"
31
+
32
+ require_relative "ride_the_streetcar/query_selector"
33
+ require_relative "ride_the_streetcar/dsl"
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ride_the_streetcar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jared White
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2026-07-16 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: streamlined
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.6'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0.6'
26
+ email:
27
+ - jared@whitefusion.studio
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - ".rubocop.yml"
33
+ - ".solargraph.yml"
34
+ - CHANGELOG.md
35
+ - CODE_OF_CONDUCT.md
36
+ - Guardfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/ride_the_streetcar.rb
41
+ - lib/ride_the_streetcar/apply.rb
42
+ - lib/ride_the_streetcar/class_list.rb
43
+ - lib/ride_the_streetcar/console.rb
44
+ - lib/ride_the_streetcar/custom.rb
45
+ - lib/ride_the_streetcar/dsl.rb
46
+ - lib/ride_the_streetcar/js.rb
47
+ - lib/ride_the_streetcar/query_selector.rb
48
+ - lib/ride_the_streetcar/set_property.rb
49
+ - lib/ride_the_streetcar/statements_list.rb
50
+ - lib/ride_the_streetcar/version.rb
51
+ homepage: https://heartml.dev/docs/ride-the-streetcar/ruby-backend/
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ rubygems_mfa_required: 'true'
56
+ homepage_uri: https://heartml.dev/docs/ride-the-streetcar/ruby-backend/
57
+ source_code_uri: https://codeberg.org/heartml/ride_the_streetcar
58
+ changelog_uri: https://codeberg.org/heartml/ride_the_streetcar/src/branch/main/CHANGELOG.md
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.2.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.6.2
74
+ specification_version: 4
75
+ summary: Ride The Streetcar backend for Ruby servers. Drive surgical state changes
76
+ to your frontend DOM and client-side objects.
77
+ test_files: []