turbo-ruby 0.1.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: 31e2bd7e1925cb38b345a71777b9ea8f62cfe8b6c809e6b94223d41ad2ac86a5
4
+ data.tar.gz: '0865e597688e1adb38acf9264d2bda21ce7565abaa553ec07dc99882de14f9be'
5
+ SHA512:
6
+ metadata.gz: 7b14e1c87275e7973e883c4a5b7b93d54b9176a5f6d1d1e64cda07d68c228036d76304e15580d3aa19b2408c4af8dd2c1684a18ff8876f87553d3a349a81b32b
7
+ data.tar.gz: c392b2e3018600311fccc821bc49e7d107c50aa285820f991c9a61d549f34f0d834076579d4d356d9c87e290417cf7cb6f07d4b8db5725fcb0d346b832a80cf9
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Marco Roth
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,53 @@
1
+ # Turbo::Ruby
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ $ bundle add turbo-ruby
8
+
9
+ If bundler is not being used to manage dependencies, install the gem by executing:
10
+
11
+ $ gem install turbo-ruby
12
+
13
+ ## Usage
14
+
15
+ ### Regular Element
16
+
17
+ ```html+erb
18
+ <%= render Turbo::Elements::TurboStream.new(action: "console_log", message: "Hello World") %>
19
+ ```
20
+
21
+ ### Blocks
22
+
23
+ ```html+erb
24
+ <%= render Turbo::Elements::TurboStream.new(action: "morph", target: "post_1") do %>
25
+ <div id="post_id">
26
+ <h1>Post 1</h1>
27
+ </div>
28
+ <% end %>
29
+ ```
30
+
31
+ ### Partials
32
+
33
+ ```html+erb
34
+ <%= render Turbo::Elements::TurboStream.new(action: "morph", target: "post_1", view_context: self, partial: "posts/post", locals: { post: @post } %>
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/turbo-ruby. 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/marcoroth/turbo-ruby/blob/main/CODE_OF_CONDUCT.md).
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the Turbo::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/turbo-ruby/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Elements
5
+ class TurboFrame < Phlex::HTML
6
+ register_element :turbo_frame
7
+ end
8
+ end
9
+ end
File without changes
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Elements
5
+ class TurboStream < Phlex::HTML
6
+ register_element :turbo_stream
7
+
8
+ def initialize(view_context: nil, action: nil, target: nil, content: nil, allow_inferred_rendering: true,
9
+ attributes: {}, **rendering, &block)
10
+ super
11
+ @view_context = view_context
12
+ @action = action
13
+ @target = target
14
+ @content = content
15
+ @allow_inferred_rendering = allow_inferred_rendering
16
+ @attributes = attributes
17
+ @rendering = rendering
18
+ @block = block
19
+ end
20
+
21
+ def template(&block)
22
+ content = render_template(&block)
23
+
24
+ turbo_stream action: @action, target: @target, **@attributes do
25
+ if @block || content
26
+ template_tag do
27
+ unsafe_raw content if content
28
+ unsafe_raw @block.call if @block
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def render_template(&block)
35
+ if @content
36
+ @allow_inferred_rendering ? (render_record(@content) || @content) : @content
37
+ elsif block_given?
38
+ throw "no view_context error" if @view_context.nil?
39
+ @view_context.capture(&block)
40
+ elsif @rendering.any?
41
+ throw "no view_context error" if @view_context.nil?
42
+ @view_context.render(formats: [:html], **@rendering)
43
+ elsif @allow_inferred_rendering
44
+ render_record(@target)
45
+ end
46
+ end
47
+
48
+ def render_record(possible_record)
49
+ return unless possible_record.respond_to?(:to_partial_path)
50
+
51
+ throw "no view_context error" if @view_context.nil?
52
+ record = possible_record
53
+ @view_context.render(partial: record, formats: :html)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Elements
5
+ class TurboStream < Phlex::HTML
6
+ register_element :turbo_stream
7
+
8
+ def initialize(view_context: nil, action: nil, target: nil, content: nil, allow_inferred_rendering: true,
9
+ attributes: {}, **rendering, &block)
10
+ super
11
+ @view_context = view_context
12
+ @action = action
13
+ @target = target
14
+ @content = content
15
+ @allow_inferred_rendering = allow_inferred_rendering
16
+ @attributes = attributes
17
+ @rendering = rendering
18
+ @block = block
19
+ end
20
+
21
+ def template(&block)
22
+ content = render_template(&block)
23
+
24
+ turbo_stream action: @action, target: @target, **@attributes do
25
+ if @block || content
26
+ template_tag do
27
+ unsafe_raw content if content
28
+ unsafe_raw @block.call if @block
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def render_template(&block)
35
+ if @content
36
+ @allow_inferred_rendering ? (render_record(@content) || @content) : @content
37
+ elsif block_given?
38
+ throw "no view_context error" if @view_context.nil?
39
+ @view_context.capture(&block)
40
+ elsif @rendering.any?
41
+ throw "no view_context error" if @view_context.nil?
42
+ @view_context.render(formats: [:html], **@rendering)
43
+ elsif @allow_inferred_rendering
44
+ render_record(@target)
45
+ end
46
+ end
47
+
48
+ def render_record(possible_record)
49
+ return unless possible_record.respond_to?(:to_partial_path)
50
+
51
+ throw "no view_context error" if @view_context.nil?
52
+ record = possible_record
53
+ @view_context.render(partial: record, formats: :html)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Elements
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Turbo
2
+ module Elements
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Ruby
5
+ module Helpers
6
+ def action(...)
7
+ self.class.action(...)
8
+ end
9
+
10
+ def self.action(name, target, content = nil, view_context: nil, allow_inferred_rendering: true, attributes: {},
11
+ **rendering, &block)
12
+ TurboStreamElement.new(
13
+ action: name,
14
+ target: target,
15
+ content: content,
16
+ view_context: view_context,
17
+ allow_inferred_rendering: allow_inferred_rendering,
18
+ attributes: attributes,
19
+ **rendering,
20
+ &block
21
+ )
22
+ end
23
+
24
+ def action_all(...)
25
+ self.class.action_all(...)
26
+ end
27
+
28
+ def self.action_all
29
+ # ...
30
+ end
31
+
32
+ def self.turbo_stream_action_tag
33
+ # ...
34
+ end
35
+
36
+ def self.turbo_frame_tag
37
+ # ...
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Ruby
5
+ module Helpers
6
+ def action(...)
7
+ self.class.action(...)
8
+ end
9
+
10
+ def self.action(name, target, content = nil, view_context: nil, allow_inferred_rendering: true, attributes: {},
11
+ **rendering, &block)
12
+ TurboStreamElement.new(
13
+ action: name,
14
+ target: target,
15
+ content: content,
16
+ view_context: view_context,
17
+ allow_inferred_rendering: allow_inferred_rendering,
18
+ attributes: attributes,
19
+ **rendering,
20
+ &block
21
+ )
22
+ end
23
+
24
+ def action_all(...)
25
+ self.class.action_all(...)
26
+ end
27
+
28
+ def self.action_all
29
+ # ...
30
+ end
31
+
32
+ def self.turbo_stream_action_tag
33
+ # ...
34
+ end
35
+
36
+ def self.turbo_frame_tag
37
+ # ...
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbo
4
+ module Ruby
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/turbo/ruby.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "phlex"
4
+ require "phlex-rails"
5
+
6
+ require_relative "ruby/version"
7
+ require_relative "ruby/helpers"
8
+ require_relative "elements"
9
+ require_relative "elements/turbo_stream"
10
+ require_relative "elements/turbo_frame"
11
+
12
+ module Turbo
13
+ module Ruby
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "phlex"
4
+ require "phlex-rails"
5
+
6
+ require_relative "ruby/version"
7
+ require_relative "ruby/helpers"
8
+ require_relative "elements"
9
+ require_relative "elements/turbo_stream"
10
+ require_relative "elements/turbo_frame"
11
+
12
+ module Turbo
13
+ module Ruby
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turbo-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco Roth
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: phlex
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: phlex-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ description: Turbo helpers without the requirement for Rails
42
+ email:
43
+ - marco.roth@intergga.ch
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - lib/turbo/elements.rb
51
+ - lib/turbo/elements.rb~
52
+ - lib/turbo/elements/turbo_frame.rb
53
+ - lib/turbo/elements/turbo_frame.rb~
54
+ - lib/turbo/elements/turbo_stream.rb
55
+ - lib/turbo/elements/turbo_stream.rb~
56
+ - lib/turbo/ruby.rb
57
+ - lib/turbo/ruby.rb~
58
+ - lib/turbo/ruby/helpers.rb
59
+ - lib/turbo/ruby/helpers.rb~
60
+ - lib/turbo/ruby/version.rb
61
+ homepage: https://github.com/marcoroth/turbo-ruby
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://github.com/marcoroth/turbo-ruby
66
+ source_code_uri: https://github.com/marcoroth/turbo-ruby
67
+ changelog_uri: https://github.com/marcoroth/turbo-ruby
68
+ rubygems_mfa_required: 'true'
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.7.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.4.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Turbo helpers without the requirement for Rails
88
+ test_files: []