Skip to content

Commit 4ee033e

Browse files
committed
Namespacing and isolating engine. Include documentation to mount and run tests. Using named route in helper partial. Including helper on init. Upgrading Ruby from 2.5.3 > 2.7.3. Upgrading Rubocop and linting accordingly.
1 parent 86a4533 commit 4ee033e

20 files changed

Lines changed: 109 additions & 90 deletions

.rubocop.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AllCops:
2-
TargetRubyVersion: 2.3
2+
TargetRubyVersion: 2.7
33
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
44
# to ignore them, so only the ones explicitly set in this file are enabled.
55
DisabledByDefault: true
@@ -11,17 +11,15 @@ AllCops:
1111
- 'db/**/*'
1212
- 'config/**/*'
1313
- 'vendor/**/*'
14+
- 'test/**/*'
15+
- 'bin/**/*'
16+
- 'Rakefile'
17+
NewCops: enable
1418

1519
# Prefer &&/|| over and/or.
1620
Style/AndOr:
1721
Enabled: true
1822

19-
# Do not use braces for hash literals when they are the last argument of a
20-
# method call.
21-
Style/BracesAroundHashParameters:
22-
Enabled: true
23-
EnforcedStyle: context_dependent
24-
2523
# Align `when` with `case`.
2624
Layout/CaseIndentation:
2725
Enabled: true
@@ -59,7 +57,6 @@ Style/HashSyntax:
5957
# extra level of indentation.
6058
Layout/IndentationConsistency:
6159
Enabled: true
62-
EnforcedStyle: rails
6360

6461
# Two spaces, no tabs (for indentation).
6562
Layout/IndentationWidth:
@@ -109,22 +106,21 @@ Layout/SpaceInsideParens:
109106
# Check quotes usage according to lint rule below.
110107
Style/StringLiterals:
111108
Enabled: true
112-
EnforcedStyle: double_quotes
113109

114110
# Detect hard tabs, no hard tabs.
115-
Layout/Tab:
111+
Layout/IndentationStyle:
116112
Enabled: true
117113

118114
# Blank lines should not have any spaces.
119-
Layout/TrailingBlankLines:
115+
Layout/TrailingEmptyLines:
120116
Enabled: true
121117

122118
# No trailing whitespace.
123119
Layout/TrailingWhitespace:
124120
Enabled: true
125121

126122
# Use quotes for string literals when they are enough.
127-
Style/UnneededPercentQ:
123+
Style/RedundantPercentQ:
128124
Enabled: true
129125

130126
# Align `end` with the matching keyword or starting expression except for
@@ -144,6 +140,9 @@ Metrics/LineLength:
144140
# Prefer the compact readable style
145141
Style/ClassAndModuleChildren:
146142
EnforcedStyle: compact
143+
Exclude:
144+
- 'lib/generators/abraham/install_generator.rb'
145+
- 'lib/abraham/engine.rb'
147146

148147
Style/FormatStringToken:
149148
EnforcedStyle: template

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.3
1+
2.7.3

Gemfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# frozen_string_literal: true
2-
source 'http://rubygems.org'
32

4-
group :development, :test do
5-
gem 'sassc-rails'
6-
end
3+
source 'http://rubygems.org'
74

85
# Set the Rails version. We have this switch so that we can test multiple
96
# versions for Rails on Travis CI.
@@ -13,7 +10,7 @@ rails = case rails_version
1310
when 'default'
1411
'~> 5.2'
1512
when 'master'
16-
{github: 'rails/rails'}
13+
{ github: 'rails/rails' }
1714
else
1815
"~> #{rails_version}"
1916
end

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Install the JavaScript dependencies:
4242
$ yarn add js-cookie@^2.2.0 shepherd.js@^6.0.0-beta
4343
```
4444

45+
Mount the engine in `config/routes.rb`. It is important to mount Abraham as `abraham`, since the inserted `abraham_tour` partial (below) leverages an isolated named route.
46+
47+
```
48+
mount Abraham::Engine, at: 'abraham'
49+
```
50+
4551
Require `abraham` in `app/assets/javascripts/application.js`
4652

4753
```
@@ -68,10 +74,13 @@ defaults: &defaults
6874

6975
You can also [write your own Shepherd theme](https://shepherdjs.dev/docs/tutorial-03-styling.html) based on Shepherd's [default CSS](https://github.com/shipshapecode/shepherd/releases/download/v6.0.0-beta.1/shepherd.css).
7076

71-
Tell Abraham where to insert its generated JavaScript in `app/views/layouts/application.html.erb`, just before the closing `body` tag:
77+
Tell Abraham where to insert the JavaScript partial. This partial sets up the [Shepherd JS](https://shepherdjs.dev/) tour/s.
78+
79+
Generally it is inserted in `app/views/layouts/application.html.erb`, just before the closing `body` tag:
7280

7381
```erb
7482
<%= abraham_tour %>
83+
7584
</body>
7685
</html>
7786
```
@@ -250,7 +259,12 @@ Use `bundle info [gemname]` to see where a bundled gem is installed.
250259
251260
#### Testing locally
252261
253-
This Rails engine contains a test app called `dummy` with controller and system tests. They'll all get run with `rails t`.
262+
This Rails engine contains a test app called `dummy` with controller and system tests. You can run tests by:
263+
264+
```
265+
~ rake app:assets:precompile
266+
~ rails test
267+
```
254268
255269
Please note that if you change anything in the `lib/generators` folder (i.e. configuration, intializer, migration) you'll need to migrate the `dummy` app accordingly.
256270

abraham.gemspec

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# frozen_string_literal: true
22

3-
$LOAD_PATH.push File.expand_path("lib", __dir__)
3+
$LOAD_PATH.push File.expand_path('lib', __dir__)
44

55
# Maintain your gem's version:
6-
require "abraham/version"
6+
require 'abraham/version'
77

88
# Describe your gem and declare its dependencies:
99
Gem::Specification.new do |s|
10-
s.name = "abraham"
10+
s.name = 'abraham'
1111
s.version = Abraham::VERSION
12-
s.authors = ["Jonathan Abbett"]
13-
s.email = ["jonathan@act.md"]
14-
s.homepage = "https://github.com/actmd/abraham"
15-
s.summary = "Trackable application tours for Rails with i18n support, based on Shepherd.js."
16-
s.description = "Trackable application tours for Rails with i18n support, based on Shepherd.js."
17-
s.license = "MIT"
12+
s.authors = ['Jonathan Abbett']
13+
s.email = ['jonathan@act.md']
14+
s.homepage = 'https://github.com/actmd/abraham'
15+
s.summary = 'Trackable application tours for Rails with i18n support, based on Shepherd.js.'
16+
s.description = 'Trackable application tours for Rails with i18n support, based on Shepherd.js.'
17+
s.license = 'MIT'
1818

19-
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
19+
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
2020

2121
s.add_development_dependency 'sassc-rails'
2222
s.add_development_dependency 'sqlite3'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
class Abraham::HistoriesController < ApplicationController
4+
def create
5+
abraham_history = Abraham::History.new(abraham_history_params).tap do |history|
6+
history.creator_id = current_user.id
7+
end
8+
9+
respond_to do |format|
10+
if abraham_history.save
11+
format.json { render json: abraham_history, status: :created }
12+
else
13+
format.json { render json: abraham_history.errors, status: :unprocessable_entity }
14+
end
15+
end
16+
end
17+
18+
private
19+
20+
def abraham_history_params
21+
params.require(:history).permit(:controller_name, :action_name, :tour_name)
22+
end
23+
end

app/controllers/abraham_histories_controller.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/helpers/abraham_helper.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def abraham_tour
99

1010
if tours
1111
# Have any automatic tours been completed already?
12-
completed = AbrahamHistory.where(
12+
completed = Abraham::History.where(
1313
creator_id: current_user.id,
1414
controller_name: controller_path,
1515
action_name: action_name
@@ -21,11 +21,11 @@ def abraham_tour
2121
tour_html = ''
2222

2323
tour_keys.each do |key|
24-
tour_html += render(partial: "application/abraham",
25-
locals: { tour_name: key,
26-
tour_completed: tour_keys_completed.include?(key),
27-
trigger: tours[key]["trigger"],
28-
steps: tours[key]["steps"] })
24+
tour_html += render(partial: 'application/abraham',
25+
locals: { tour_name: key,
26+
tour_completed: tour_keys_completed.include?(key),
27+
trigger: tours[key]['trigger'],
28+
steps: tours[key]['steps'] })
2929
end
3030

3131
tour_html.html_safe
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

3-
class ApplicationRecord < ActiveRecord::Base
3+
class Abraham::ApplicationRecord < ActiveRecord::Base
44
self.abstract_class = true
55
end

app/models/abraham/history.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class Abraham::History < ApplicationRecord
4+
end

0 commit comments

Comments
 (0)