Skip to content

Commit

Permalink
Merge pull request #4 from WriterZephos/0.1.4_development
Browse files Browse the repository at this point in the history
Version 0.1.4
  • Loading branch information
WriterZephos authored May 1, 2024
2 parents d5fec04 + 6604856 commit cce7661
Show file tree
Hide file tree
Showing 11 changed files with 989 additions and 39 deletions.
24 changes: 13 additions & 11 deletions .rspec_status
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
example_id | status | run_time |
-------------------------------------------------------------------------- | ------ | --------------- |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:1:1] | passed | 0.00399 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:2:1:1:1] | passed | 0.04985 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:2:1:2:1] | passed | 0.00811 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:2:2:1] | passed | 0.00269 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:3:1] | passed | 0.00846 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:1:1:1] | passed | 0.00597 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:1:2:1] | passed | 0.00672 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:1:3:1] | passed | 0.00429 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:2:1] | passed | 0.00241 seconds |
./spec/turbo_router/controllers/helper_test_controller_spec.rb[1:1:1:1] | passed | 0.00412 seconds |
./spec/turbo_router_spec.rb[1:1] | passed | 0.00106 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:1:1] | passed | 0.00495 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:2:1:1:1] | passed | 0.03875 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:2:1:2:1] | passed | 0.00642 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:2:2:1] | passed | 0.00245 seconds |
./spec/turbo_router/controllers/custom_test_controller_spec.rb[1:3:1] | passed | 0.00873 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:1:1:1] | passed | 0.00562 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:1:2:1] | passed | 0.00632 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:1:3:1] | passed | 0.00421 seconds |
./spec/turbo_router/controllers/default_test_controller_spec.rb[1:1:2:1] | passed | 0.00247 seconds |
./spec/turbo_router/controllers/helper_test_controller_spec.rb[1:1:1:1] | passed | 0.00392 seconds |
./spec/turbo_router/helpers/application_helpers_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
./spec/turbo_router/helpers/application_helpers_spec.rb[1:1:2:1] | passed | 0.00024 seconds |
./spec/turbo_router_spec.rb[1:1] | passed | 0.00088 seconds |
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PATH
specs:
turbo-router (0.1.4)
rails (>= 7.0.2.2)
turbo-rails
turbo-rails (~> 2.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -171,7 +171,7 @@ GEM
rspec-support (3.12.0)
thor (1.2.1)
timeout (0.3.2)
turbo-rails (1.4.0)
turbo-rails (2.0.5)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
Expand Down
1 change: 1 addition & 0 deletions lib/turbo-router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "turbo_router/version"
require "turbo_router/controller"
require "turbo_router/view_helpers"
require "turbo_router/application_helpers"
require "turbo_router/railtie" if defined?(Rails)

module TurboRouter
Expand Down
7 changes: 7 additions & 0 deletions lib/turbo_router/application_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module TurboRouter
module ApplicationHelpers
def turbo_router_frame_id_for_request
request.headers["Turbo-frame"].present? ? request.headers["Turbo-frame"] : "turbo_router_content"
end
end
end
22 changes: 0 additions & 22 deletions lib/turbo_router/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ module Controller
layout lambda {
use_dynamic_layout? ? "layouts/turbo_router_content" : self.class.page_layout
}

before_action :set_turbo_frame_request_variant
helper_method :turbo_router_frame_options
helper_method :turbo_router_frame_id_for_request
end

class_methods do
Expand All @@ -40,23 +36,5 @@ def use_dynamic_layout?
def turbo_router_stream(template, id = :turbo_router_content, **options)
render turbo_stream: turbo_stream.replace(id, template: template, locals: options)
end

def turbo_router_frame_options
@turbo_router_advance ? { turbo_action: "advance", target: request.headers["Turbo-frame"] } : {}
end

def turbo_router_frame_id_for_request
request.headers["Turbo-frame"].present? ? request.headers["Turbo-frame"] : "turbo_router_content"
end

private

def set_turbo_frame_request_variant
request.variant = if turbo_frame_request?
:turbo_frame
else
:page
end
end
end
end
10 changes: 9 additions & 1 deletion lib/turbo_router/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# frozen_string_literal: true
require "pry"

module TurboRouter
class Railtie < Rails::Railtie
initializer "turbo_router.view_helpers" do
ActiveSupport.on_load(:action_view) { include TurboRouter::ViewHelpers }
ActiveSupport.on_load(:action_view) do
include TurboRouter::ViewHelpers
include TurboRouter::ApplicationHelpers
end
end

initializer 'turbo_router.controller_helpers' do
ActiveSupport.on_load(:action_controller) { include TurboRouter::ApplicationHelpers }
end
end
end
2 changes: 1 addition & 1 deletion spec/dummy/app/views/layouts/_turbo_router_content.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= turbo_frame_tag(turbo_router_frame_id_for_request, **turbo_router_frame_options) do %>
<%= turbo_frame_tag(turbo_router_frame_id_for_request) do %>
<%= yield %>
<% end %>
1 change: 0 additions & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require "turbo_router"

module Dummy
class Application < Rails::Application
Expand Down
Loading

0 comments on commit cce7661

Please sign in to comment.