Support for controller modules (resolves #38)
This commit is contained in:
parent
eaf6ae78c8
commit
a5c4e8ef71
20
README.md
20
README.md
@ -78,12 +78,15 @@ Tell Abraham where to insert its generated JavaScript in `app/views/layouts/appl
|
||||
|
||||
## Defining your tours
|
||||
|
||||
Define your tours in the `config/tours` directory corresponding to the views defined in your application. Its directory structure mirrors your application's controllers, and the tour files mirror your actions/views.
|
||||
Define your tours in the `config/tours` directory corresponding to the views defined in your application. Its directory structure mirrors your application's controllers, and the tour files mirror your actions/views. (As of version 2.4.0, Abraham respects controllers organized into modules.)
|
||||
|
||||
```
|
||||
config/
|
||||
└── tours/
|
||||
└── blog/
|
||||
├── admin/
|
||||
│ └── articles/
|
||||
│ └── edit.en.yml
|
||||
├── blog/
|
||||
│ ├── show.en.yml
|
||||
│ └── show.es.yml
|
||||
└── articles/
|
||||
@ -193,7 +196,18 @@ end
|
||||
|
||||
We provide a [small example app](https://github.com/actmd/abraham-example) that implements Abraham, so you can see it in action.
|
||||
|
||||
## Upgrading from version 1
|
||||
## Upgrading
|
||||
|
||||
### From version 2.3.0 or earlier
|
||||
|
||||
Abraham 2.4.0 introduced an updated initializer that supports controllers organized into modules.
|
||||
Rerun the generator with these options to replace the old initializer:
|
||||
|
||||
```
|
||||
$ rails generate abraham:install --skip-migration --skip-config
|
||||
```
|
||||
|
||||
### From version 1
|
||||
|
||||
Abraham v1 was built using Shepherd 1.8, v2 now uses Shepherd 6 – quite a jump, yes.
|
||||
|
||||
|
@ -3,15 +3,15 @@
|
||||
module AbrahamHelper
|
||||
def abraham_tour
|
||||
# Do we have tours for this controller/action in the user's locale?
|
||||
tours = Rails.configuration.abraham.tours["#{controller_name}.#{action_name}.#{I18n.locale}"]
|
||||
tours = Rails.configuration.abraham.tours["#{controller_path}.#{action_name}.#{I18n.locale}"]
|
||||
# Otherwise, default to the default locale
|
||||
tours ||= Rails.configuration.abraham.tours["#{controller_name}.#{action_name}.#{I18n.default_locale}"]
|
||||
tours ||= Rails.configuration.abraham.tours["#{controller_path}.#{action_name}.#{I18n.default_locale}"]
|
||||
|
||||
if tours
|
||||
# Have any automatic tours been completed already?
|
||||
completed = AbrahamHistory.where(
|
||||
creator_id: current_user.id,
|
||||
controller_name: controller_name,
|
||||
controller_name: controller_path,
|
||||
action_name: action_name
|
||||
)
|
||||
|
||||
@ -33,7 +33,7 @@ module AbrahamHelper
|
||||
end
|
||||
|
||||
def abraham_cookie_prefix
|
||||
"abraham-#{fetch_application_name.to_s.underscore}-#{current_user.id}-#{controller_name}-#{action_name}"
|
||||
"abraham-#{fetch_application_name.to_s.underscore}-#{current_user.id}-#{controller_path}-#{action_name}"
|
||||
end
|
||||
|
||||
def fetch_application_name
|
||||
@ -44,7 +44,6 @@ module AbrahamHelper
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def abraham_domain
|
||||
request.host
|
||||
end
|
||||
|
@ -9,7 +9,7 @@
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
authenticity_token: '<%= form_authenticity_token %>',
|
||||
controller_name: '<%= controller_name %>',
|
||||
controller_name: '<%= controller_path %>',
|
||||
action_name: '<%= action_name %>',
|
||||
tour_name: '<%= tour_name %>'
|
||||
})
|
||||
|
@ -10,6 +10,7 @@ module Abraham
|
||||
|
||||
class_option :'skip-migration', type: :boolean, desc: "Don't generate a migration for the histories table"
|
||||
class_option :'skip-initializer', type: :boolean, desc: "Don't generate an initializer"
|
||||
class_option :'skip-config', type: :boolean, desc: "Don't generate a config file"
|
||||
|
||||
source_root File.expand_path(File.join(File.dirname(__FILE__), "templates"))
|
||||
|
||||
@ -24,6 +25,11 @@ module Abraham
|
||||
return if options["skip-initializer"]
|
||||
|
||||
copy_file "initializer.rb", "config/initializers/abraham.rb"
|
||||
end
|
||||
|
||||
def create_config
|
||||
return if options["skip-config"]
|
||||
|
||||
copy_file "abraham.yml", "config/abraham.yml"
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Foobar::DashboardController < ApplicationController
|
||||
def home; end
|
||||
end
|
4
test/dummy/app/views/foobar/dashboard/home.html.erb
Normal file
4
test/dummy/app/views/foobar/dashboard/home.html.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<h1>Foobar::Dashboard#home</h1>
|
||||
<p>Find me in app/views/foobar/dashboard/home.html.erb</p>
|
||||
|
||||
We should get a unique tour for this module, not the same one as Dashboard#home
|
@ -2,18 +2,19 @@
|
||||
|
||||
Rails.application.configure do
|
||||
tours = {}
|
||||
tours_root = Pathname.new(Rails.root.join("config/tours"))
|
||||
|
||||
if Rails.root.join("config/tours").exist?
|
||||
Dir[Rails.root.join("config/tours/*/")].each do |dir|
|
||||
Dir[dir + "*.yml"].each do |yml|
|
||||
path_parts = yml.split(File::SEPARATOR)
|
||||
controller = path_parts[path_parts.size - 2]
|
||||
file_parts = path_parts[path_parts.size - 1].split(".")
|
||||
Dir.glob(Rails.root.join("config/tours/**/*.yml")).each do |yml|
|
||||
relative_filename = Pathname.new(yml).relative_path_from(tours_root)
|
||||
# `controller_path` is either "controller_name" or "module_name/controller_name"
|
||||
controller_path, filename = relative_filename.split
|
||||
file_parts = filename.to_s.split(".")
|
||||
action = file_parts[0]
|
||||
locale = file_parts[1]
|
||||
t = YAML.load_file(yml)
|
||||
tours["#{controller}.#{action}.#{locale}"] = t
|
||||
end
|
||||
tours["#{controller_path}.#{action}.#{locale}"] = t
|
||||
puts "#{controller_path}.#{action}.#{locale}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -6,5 +6,9 @@ Rails.application.routes.draw do
|
||||
get "dashboard/placement"
|
||||
get "dashboard/missing"
|
||||
|
||||
namespace :foobar do
|
||||
get "dashboard/home"
|
||||
end
|
||||
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
end
|
||||
|
4
test/dummy/config/tours/foobar/dashboard/home.en.yml
Normal file
4
test/dummy/config/tours/foobar/dashboard/home.en.yml
Normal file
@ -0,0 +1,4 @@
|
||||
module:
|
||||
steps:
|
||||
1:
|
||||
text: "This tour should appear for the Foobar::DashboardController only"
|
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class Foobar::DashboardControllerTest < ActionDispatch::IntegrationTest
|
||||
# setup do
|
||||
# I18n.locale = :en
|
||||
# end
|
||||
|
||||
# teardown do
|
||||
# I18n.locale = :en
|
||||
# end
|
||||
|
||||
test "home should have home tour code" do
|
||||
get foobar_dashboard_home_url
|
||||
assert_response :success
|
||||
|
||||
assert_select "body script" do |element|
|
||||
# it's the Foobar module home tour
|
||||
assert element.text.include? "This tour should appear for the Foobar::DashboardController only"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user