bullet_train 1.0.45 → 1.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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.bt-link +0 -0
  3. data/README.md +4 -3
  4. data/app/controllers/concerns/account/controllers/base.rb +9 -0
  5. data/app/controllers/concerns/account/invitations/controller_base.rb +11 -6
  6. data/app/controllers/concerns/account/teams/controller_base.rb +1 -1
  7. data/app/controllers/concerns/controllers/base.rb +26 -2
  8. data/app/controllers/concerns/registrations/controller_base.rb +4 -7
  9. data/app/controllers/concerns/root_redirect.rb +1 -5
  10. data/app/controllers/concerns/sessions/controller_base.rb +0 -6
  11. data/app/controllers/sessions_controller.rb +11 -0
  12. data/app/controllers/turbo_devise_controller.rb +19 -0
  13. data/app/helpers/account/dates_helper.rb +10 -8
  14. data/app/helpers/account/forms_helper.rb +0 -4
  15. data/app/helpers/account/locale_helper.rb +2 -2
  16. data/app/helpers/base_helper.rb +5 -1
  17. data/app/helpers/concerns/helpers/base.rb +18 -0
  18. data/app/helpers/invitations_helper.rb +0 -15
  19. data/app/javascript/controllers/bulk_action_form_controller.js +88 -0
  20. data/app/javascript/controllers/bulk_actions_controller.js +95 -0
  21. data/app/javascript/controllers/clipboard_controller.js +1 -1
  22. data/app/javascript/controllers/form_controller.js +1 -1
  23. data/app/javascript/controllers/index.js +7 -1
  24. data/app/javascript/controllers/mobile_menu_controller.js +19 -17
  25. data/app/javascript/controllers/text_toggle_controller.js +33 -0
  26. data/app/mailers/concerns/mailers/base.rb +1 -0
  27. data/app/models/concerns/current_attributes/base.rb +1 -1
  28. data/app/models/concerns/memberships/base.rb +10 -2
  29. data/app/models/concerns/records/base.rb +35 -0
  30. data/app/models/concerns/teams/base.rb +19 -0
  31. data/app/models/concerns/users/base.rb +12 -11
  32. data/app/models/invitation.rb +1 -1
  33. data/app/models/membership.rb +1 -1
  34. data/app/models/team.rb +2 -2
  35. data/app/models/user.rb +1 -1
  36. data/app/views/account/memberships/show.html.erb +3 -1
  37. data/app/views/account/onboarding/user_details/edit.html.erb +1 -1
  38. data/app/views/account/users/_oauth.html.erb +2 -0
  39. data/app/views/account/users/edit.html.erb +2 -3
  40. data/app/views/bullet_train/partial_resolver.html.erb +1 -0
  41. data/app/views/devise/registrations/new.html.erb +1 -1
  42. data/app/views/devise/sessions/new.html.erb +6 -6
  43. data/app/views/layouts/docs.html.erb +25 -24
  44. data/app/views/layouts/mailer.html.erb +1 -425
  45. data/config/initializers/concerns/inflections_base.rb +6 -0
  46. data/config/initializers/concerns/turbo_failure_app.rb +14 -0
  47. data/config/locales/en/billing/products.en.yml +17 -0
  48. data/config/locales/en/devise.en.yml +1 -0
  49. data/config/locales/en/framework_packages.yml +43 -0
  50. data/config/locales/en/invitations.en.yml +1 -0
  51. data/config/locales/en/teams.en.yml +1 -0
  52. data/docs/action-models.md +148 -0
  53. data/docs/authentication.md +2 -2
  54. data/docs/billing/stripe.md +95 -39
  55. data/docs/field-partials/super-select.md +70 -1
  56. data/docs/field-partials.md +25 -18
  57. data/docs/getting-started.md +12 -12
  58. data/docs/index.md +4 -1
  59. data/docs/indirection.md +30 -7
  60. data/docs/invitation_only.md +13 -0
  61. data/docs/javascript.md +18 -0
  62. data/docs/namespacing.md +1 -1
  63. data/docs/onboarding.md +10 -10
  64. data/docs/overriding.md +1 -1
  65. data/docs/permissions.md +1 -1
  66. data/docs/super-scaffolding/delegated-types.md +31 -3
  67. data/docs/super-scaffolding/sortable.md +137 -0
  68. data/docs/super-scaffolding.md +7 -1
  69. data/docs/tunneling.md +4 -4
  70. data/lib/bullet_train/core_ext/string_emoji_helper.rb +18 -0
  71. data/lib/bullet_train/resolver.rb +61 -47
  72. data/lib/bullet_train/version.rb +1 -1
  73. data/lib/bullet_train.rb +23 -9
  74. data/lib/tasks/bullet_train_tasks.rake +148 -7
  75. metadata +115 -33
  76. data/app/assets/javascripts/bullet-train.esm.js +0 -2
  77. data/app/assets/javascripts/bullet-train.esm.js.map +0 -1
  78. data/app/assets/javascripts/bullet-train.js +0 -2
  79. data/app/assets/javascripts/bullet-train.js.map +0 -1
  80. data/app/assets/javascripts/bullet-train.modern.js +0 -2
  81. data/app/assets/javascripts/bullet-train.modern.js.map +0 -1
  82. data/app/assets/javascripts/bullet-train.umd.js +0 -2
  83. data/app/assets/javascripts/bullet-train.umd.js.map +0 -1
  84. data/lib/string/emoji.rb +0 -10
@@ -34,7 +34,7 @@ rails g model Message subject:string
34
34
  rails g model Comment content:text
35
35
  ```
36
36
 
37
- Note that in this specific approach we don't need a `team:references` on `Message` and `Comment`. That's because in this approach there are no controllers specific to `Message` and `Comment`, so all permissions are being inforced by checking the ownership of `Entry`. (That's not to say it would be wrong to add them for other reasons, we're just keeping it as simple as possible here.)
37
+ Note that in this specific approach we don't need a `team:references` on `Message` and `Comment`. That's because in this approach there are no controllers specific to `Message` and `Comment`, so all permissions are being enforced by checking the ownership of `Entry`. (That's not to say it would be wrong to add them for other reasons, we're just keeping it as simple as possible here.)
38
38
 
39
39
  ### 2. Super Scaffolding for `Entry`
40
40
 
@@ -59,7 +59,33 @@ fields: &fields
59
59
  "Comment": Comment
60
60
  ```
61
61
 
62
- <small>TODO Insert a live example of what `shared/fields/buttons` looks like with these options passed in.</small>
62
+ We will add this block below in the next step on our `new.html.erb` page so you don't have to worry about it now, but with the options above in place, our buttons partial will now allow your users to select either a `Message` or a `Comment` before creating the `Entry` itself:
63
+
64
+ ```
65
+ <% with_field_settings form: form do %>
66
+ <%= render 'shared/fields/buttons', method: :entryable_type, html_options: {autofocus: true} %>
67
+ <%# 🚅 super scaffolding will insert new fields above this line. %>
68
+ <% end %>
69
+ ```
70
+
71
+ This will produce the following HTML:
72
+ ```
73
+ <div>
74
+ <label class="btn-toggle" data-controller="fields--button-toggle">
75
+ <input data-fields--button-toggle-target="shadowField" type="radio" value="Message" name="entry[entryable_type]" id="entry_entryable_type_message">
76
+ <button type="button" class="button-alternative mb-1.5 mr-1" data-action="fields--button-toggle#clickShadowField">
77
+ Message
78
+ </button>
79
+ </label>
80
+ <label class="btn-toggle" data-controller="fields--button-toggle">
81
+ <input data-fields--button-toggle-target="shadowField" type="radio" value="Comment" name="entry[entryable_type]" id="entry_entryable_type_comment">
82
+ <button type="button" class="button-alternative mb-1.5 mr-1" data-action="fields--button-toggle#clickShadowField">
83
+ Comment
84
+ </button>
85
+ </label>
86
+ </div>
87
+ ```
88
+
63
89
 
64
90
  ### 4. Add Our First Step to `new.html.erb`
65
91
 
@@ -234,9 +260,11 @@ We add this _below_ the Super Scaffolding hook because we want any additional fi
234
260
 
235
261
  ### 10. Add Attributes of the Concrete Children to `show.html.erb`
236
262
 
237
- Under the Super Scaffolding hook in `app/views/account/entries/show.html.erb`, add the following:
263
+ Add the following in `app/views/account/entries/show.html.erb` under the Super Scaffolding hook shown in the example code below:
238
264
 
239
265
  ```
266
+ <%# 🚅 super scaffolding will insert new fields above this line. %>
267
+
240
268
  <% with_attribute_settings object: @entry.entryable, strategy: :label do %>
241
269
  <% case @entry.entryable %>
242
270
  <% when Message %>
@@ -0,0 +1,137 @@
1
+ # Super Scaffolding with the `--sortable` option
2
+
3
+ When issuing a `bin/super-scaffold crud` command, you can pass the `--sortable` option like this:
4
+
5
+ ```
6
+ # E.g. Pages belong to a Site and are sortable via drag-and-drop:
7
+ rails g model Page site:references name:string path:text
8
+ bin/super-scaffold crud Page Site,Team name:text path:text --sortable
9
+ ```
10
+
11
+ The `--sortable` option:
12
+
13
+ 1. Wraps the table's body in a `sortable` Stimulus controller, providing drag-and-drop re-ordering;
14
+ 2. Adds a `reorder` action to your resource via `include SortableActions`, triggered automatically on re-order;
15
+ 3. Adds a migration to add the `sort_order` column to your model to store the ordering;
16
+ 4. Adds a `default_scope` which orders by `sort_order` and auto increments `sort_order` on create via `include Sortable` on the model.
17
+
18
+ ## Disabling Saving on Re-order
19
+
20
+ By default, a call to save the new `sort_order` is triggered automatically on re-order.
21
+
22
+ ### To disable auto-saving
23
+
24
+ Add the `data-sortable-save-on-reorder-value="false"` param on the `sortable` root element:
25
+
26
+ ```html
27
+ <tbody data-controller="sortable"
28
+ data-sortable-save-on-reorder-value="false"
29
+ ...
30
+ >
31
+ ```
32
+
33
+ ### To manually fire the save action via a button
34
+
35
+ Since the button won't be part of the `sortable` root element's descendants (all its direct descendants are sortable by default), you'll need to wrap both the `sortable` element and the save button in a new Stimulus controlled ancestor element.
36
+
37
+ ```js
38
+ /* sortable-wrapper_controller.js */
39
+ import { Controller } from "@hotwired/stimulus"
40
+
41
+ export default class extends Controller {
42
+ static targets = [ "sortable" ]
43
+
44
+ saveSortOrder() {
45
+ if (!this.hasSortableTarget) { return }
46
+ this.sortableTarget.dispatchEvent(new CustomEvent("save-sort-order"))
47
+ }
48
+ }
49
+ ```
50
+
51
+ On the button, add a `data-action`
52
+
53
+ ```html
54
+ <button data-action="sortable-wrapper#saveSortOrder">Save Sort Order</button>
55
+ ```
56
+
57
+ And on the `sortable` element, catch the `save-sort-order` event and define it as the `sortable` target for the `sortable-wrapper` controller:
58
+
59
+ ```html
60
+ <tbody data-controller="sortable"
61
+ data-sortable-save-on-reorder-value="false"
62
+ data-action="save-sort-order->sortable#saveSortOrder"
63
+ data-sortable-wrapper-target="sortable"
64
+ ...
65
+ >
66
+ ```
67
+
68
+ ## Events
69
+
70
+ Under the hood, the `sortable` Stimulus controller uses the [dragula](https://github.com/bevacqua/dragula) library.
71
+
72
+ All of the events that `dragula` defines are re-dispatched as native DOM events. The native DOM event name is prefixed with `sortable:`
73
+
74
+ | dragula event name | DOM event name |
75
+ |---------------------|----------------------|
76
+ | drag | sortable:drag |
77
+ | dragend | sortable:dragend |
78
+ | drop | sortable:drop |
79
+ | cancel | sortable:cancel |
80
+ | remove | sortable:remove |
81
+ | shadow | sortable:shadow |
82
+ | over | sortable:over |
83
+ | out | sortable:out |
84
+ | cloned | sortable:cloned |
85
+
86
+ The original event's listener arguments are passed to the native DOM event as a simple numbered Array under `event.detail.args`. See [dragula's list of events](https://github.com/bevacqua/dragula#drakeon-events) for the listener arguments.
87
+
88
+ ### Example: Asking for Confirmation on the `drop` Event
89
+
90
+ Let's say we'd like to ask the user to confirm before saving the new sort order:
91
+
92
+ > Are you sure you want to place DROPPED ITEM before SIBLING ITEM?
93
+
94
+ ```js
95
+ /* confirm-reorder_controller.js */
96
+ import { Controller } from "@hotwired/stimulus"
97
+
98
+ export default class extends Controller {
99
+ static targets = [ "sortable" ]
100
+
101
+ requestConfirmation(event) {
102
+ const [el, target, source, sibling] = event.detail?.args
103
+
104
+ // sibling will be undefined if dropped in last position, taking a shortcut here
105
+ const areYouSure = `Are you sure you want to place ${el.dataset.name} before ${sibling.dataset.name}?`
106
+
107
+ // let's suppose each <tr> in sortable has a data-name attribute
108
+ if (confirm(areYouSure)) {
109
+ this.sortableTarget.dispatchEvent(new CustomEvent('save-sort-order'))
110
+ } else {
111
+ this.revertToOriginalOrder()
112
+ }
113
+ }
114
+
115
+ prepareForRevertOnCancel(event) {
116
+ // we're assuming we can swap out the HTML safely
117
+ this.originalSortableHTML = this.sortableTarget.innerHTML
118
+ }
119
+
120
+ revertToOriginalOrder() {
121
+ if (this.originalSortableHTML === undefined) { return }
122
+ this.sortableTarget.innerHTML = this.originalSortableHTML
123
+ this.originalSortableHTML = undefined
124
+ }
125
+ }
126
+ ```
127
+
128
+ And on the `sortable` element, catch the `sortable:drop`, `sortable:drag` (for catching when dragging starts) and `save-sort-order` events. Also define it as the `sortable` target for the `confirm-reorder` controller:
129
+
130
+ ```html
131
+ <tbody data-controller="sortable"
132
+ data-sortable-save-on-reorder-value="false"
133
+ data-action="sortable:drop->confirm-reorder#requestConfirmation sortable:drag->confirm-reorder#prepareForRevertOnCancel save-sort-order->sortable#saveSortOrder"
134
+ data-confirm-reorder-target="sortable"
135
+ ...
136
+ >
137
+ ```
@@ -23,7 +23,7 @@ Bullet Train's Super Scaffolding engine is a unique approach to code generation,
23
23
 
24
24
  ## Prerequisites
25
25
 
26
- Before getting started with Super Scaffolding, we recommend reading about [the philosophy of domain modeling in Bullet Train](/docs/topics/domain-modeling.md).
26
+ Before getting started with Super Scaffolding, we recommend reading about [the philosophy of domain modeling in Bullet Train](/docs/modeling.md).
27
27
 
28
28
  ## Usage
29
29
 
@@ -108,6 +108,11 @@ rake db:migrate
108
108
 
109
109
  As you can see, when we're using `crud-field`, we don't need to supply the chain of ownership back to `Team`.
110
110
 
111
+ If you want to scaffold a new field to use for read-only purposes, add the following option to omit the field from the form and all other files that apply:
112
+ ```
113
+ bin/super-scaffold crud-field Project description:trix_editor{readonly}
114
+ ```
115
+
111
116
  ### 4. Adding Option Fields with Fixed, Translatable Options
112
117
 
113
118
  Continuing with the earlier example, let's address the following new requirement:
@@ -244,3 +249,4 @@ HIDE_THINGS: true
244
249
 
245
250
  ## Advanced Examples
246
251
  - [Super Scaffolding with Delegated Types](/docs/super-scaffolding/delegated-types.md)
252
+ - [Super Scaffolding with the `--sortable` option](/docs/super-scaffolding/sortable.md)
data/docs/tunneling.md CHANGED
@@ -4,14 +4,14 @@ Before your application can take advantage of features that depend on incoming w
4
4
 
5
5
  ## Use a Paid Plan
6
6
 
7
- You should specifically sign up for a paid account. Although ngrok offers a free plan, their $5/month paid plan will allow you to reserve a custom subdomain for reuse each time you spin up your tunnel. This is a critical productivity improvement, because in practice you'll end up configuring your tunnel URL in a bunch of different places like `config/application.yml` but also in external systems like when you [configure payment providers to deliver webhooks to you](docs/billing/stripe.md).
7
+ You should specifically sign up for a paid account. Although ngrok offers a free plan, their $25/month paid plan will allow you to reserve a custom subdomain for reuse each time you spin up your tunnel. This is a critical productivity improvement, because in practice you'll end up configuring your tunnel URL in a bunch of different places like `config/application.yml` but also in external systems like when you [configure payment providers to deliver webhooks to you](docs/billing/stripe.md).
8
8
 
9
9
  ## Usage
10
10
 
11
- Once you have ngrok installed, you can start your tunnel like so, replacing `your-subdomain` with whatever subdomain you reserved in your ngrok account:
11
+ Once you have ngrok installed, you can start your tunnel like so, replacing `YOUR-SUBDOMAIN` with whatever subdomain you reserved in your ngrok account:
12
12
 
13
13
  ```
14
- ngrok http 3000 -subdomain=your-subdomain
14
+ ngrok http 3000 -subdomain=YOUR-SUBDOMAIN
15
15
  ```
16
16
 
17
17
  ## Updating Your Configuration
@@ -19,7 +19,7 @@ ngrok http 3000 -subdomain=your-subdomain
19
19
  Before your Rails application will accept connections on your tunnel hostname, you need to update `config/application.yml` with:
20
20
 
21
21
  ```
22
- BASE_URL: https://your-subdomain.ngrok.io
22
+ BASE_URL: https://YOUR-SUBDOMAIN.ngrok.io
23
23
  ```
24
24
 
25
25
  You'll also need to restart your Rails server:
@@ -0,0 +1,18 @@
1
+ require "unicode/emoji"
2
+
3
+ module BulletTrain
4
+ module CoreExt
5
+ module StringEmojiHelper
6
+ def strip_emojis
7
+ gsub(Unicode::Emoji::REGEX, "")
8
+ end
9
+
10
+ def only_emoji?
11
+ return false if strip.empty?
12
+ strip_emojis.strip.empty?
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ String.include(BulletTrain::CoreExt::StringEmojiHelper)
@@ -1,4 +1,4 @@
1
- require 'io/wait'
1
+ require "io/wait"
2
2
 
3
3
  module BulletTrain
4
4
  class Resolver
@@ -13,28 +13,23 @@ module BulletTrain
13
13
  source_file = calculate_source_file_details
14
14
 
15
15
  if source_file[:absolute_path]
16
+ puts ""
17
+ puts "Absolute path:".green
18
+ puts " #{source_file[:absolute_path]}".green
19
+ puts ""
16
20
  if source_file[:package_name].present?
17
- puts ""
18
- puts "Absolute path:".green
19
- puts " #{source_file[:absolute_path]}".green
20
- puts ""
21
21
  puts "Package name:".green
22
22
  puts " #{source_file[:package_name]}".green
23
- puts ""
24
23
  else
25
- puts ""
26
- puts "Project path:".green
27
- puts " #{source_file[:project_path]}".green
28
- puts ""
29
24
  puts "Note: If this file was previously ejected from a package, we can no longer see which package it came from. However, it should say at the top of the file where it was ejected from.".yellow
30
- puts ""
31
25
  end
26
+ puts ""
32
27
 
33
28
  if interactive && !eject
34
29
  puts "\nWould you like to eject the file into the local project? (y/n)\n"
35
30
  input = $stdin.gets
36
31
  $stdin.getc while $stdin.ready?
37
- if input.first.downcase == 'y'
32
+ if input.first.downcase == "y"
38
33
  eject = true
39
34
  end
40
35
  end
@@ -46,7 +41,7 @@ module BulletTrain
46
41
  else
47
42
  `mkdir -p #{source_file[:project_path].split("/")[0...-1].join("/")}`
48
43
  puts "Ejecting `#{source_file[:absolute_path]}` to `#{source_file[:project_path]}`".green
49
- File.open("#{source_file[:project_path]}", "w+") do |file|
44
+ File.open((source_file[:project_path]).to_s, "w+") do |file|
50
45
  case source_file[:project_path].split(".").last
51
46
  when "rb", "yml"
52
47
  file.puts "# Ejected from `#{source_file[:package_name]}`.\n\n"
@@ -69,13 +64,13 @@ module BulletTrain
69
64
  puts "\nWould you like to open `#{source_file[:absolute_path]}`? (y/n)\n"
70
65
  input = $stdin.gets
71
66
  $stdin.getc while $stdin.ready?
72
- if input.first.downcase == 'y'
67
+ if input.first.downcase == "y"
73
68
  open = true
74
69
  end
75
70
  end
76
71
 
77
72
  if open
78
- path = source_file[:package_name] ? source_file[:absolute_path] : "#{source_file[:project_path]}"
73
+ path = source_file[:package_name] ? source_file[:absolute_path] : (source_file[:project_path]).to_s
79
74
  puts "Opening `#{path}`.\n".green
80
75
  exec "open #{path}"
81
76
  end
@@ -91,28 +86,28 @@ module BulletTrain
91
86
  package_name: nil,
92
87
  }
93
88
 
94
- result[:absolute_path] = class_path || partial_path || locale_path || file_path
95
-
89
+ result[:absolute_path] = file_path || class_path || partial_path || locale_path
96
90
  if result[:absolute_path]
97
- base_path = "bullet_train" + result[:absolute_path].split("/bullet_train").last
98
-
99
- # Try to calculate which package the file is from, and what it's path is within that project.
100
- ["app", "config", "lib"].each do |directory|
101
- regex = /\/#{directory}\//
102
- if base_path.match?(regex)
103
- project_path = "./#{directory}/#{base_path.rpartition(regex).last}"
104
- package_name = base_path.rpartition(regex).first.split("/").last
105
- # If the "package name" is actually just the local project directory.
106
- if package_name == `pwd`.chomp.split("/").last
107
- package_name = nil
108
- end
91
+ if result[:absolute_path].include?("/bullet_train")
92
+ base_path = "bullet_train" + result[:absolute_path].partition("/bullet_train").last
93
+
94
+ # Try to calculate which package the file is from, and what it's path is within that project.
95
+ ["app", "config", "lib"].each do |directory|
96
+ regex = /\/#{directory}\//
97
+ if base_path.match?(regex)
98
+ project_path = "./#{directory}/#{base_path.rpartition(regex).last}"
99
+ package_name = base_path.rpartition(regex).first.split("/").last
100
+ # If the "package name" is actually just the local project directory.
101
+ if package_name == `pwd`.chomp.split("/").last
102
+ package_name = nil
103
+ end
109
104
 
110
- result[:project_path] = project_path
111
- result[:package_name] = package_name
105
+ result[:project_path] = project_path
106
+ result[:package_name] = package_name
107
+ end
112
108
  end
113
109
  end
114
110
  end
115
-
116
111
  result
117
112
  end
118
113
 
@@ -121,35 +116,48 @@ module BulletTrain
121
116
  end
122
117
 
123
118
  def class_path
124
- begin
125
- @needle.constantize
126
- return Object.const_source_location(@needle).first
127
- rescue NameError => _
128
- return false
129
- end
119
+ @needle.constantize
120
+ Object.const_source_location(@needle).first
121
+ rescue NameError => _
122
+ false
130
123
  end
131
124
 
132
125
  def partial_path
133
126
  begin
134
- xray_path = ApplicationController.render(template: "bullet_train/partial_resolver", layout: nil, assigns: {needle: @needle}).lines[1].chomp
135
- if xray_path.match(/<!--XRAY START \d+ (.*)-->/)
136
- return $1
127
+ annotated_path = ApplicationController.render(template: "bullet_train/partial_resolver", layout: nil, assigns: {needle: @needle}).lines[1].chomp
128
+ rescue ActionView::Template::Error => e
129
+ # This is a really hacky way to get the file name, but the reason we're getting an error in the first place is because
130
+ # the partial requires locals that we aren't providing in the ApplicationController.render call above,
131
+ # resulting in an undefined local variable error. We do however get the file name, which we can pass back to the developer.
132
+ return e.file_name
133
+ end
134
+
135
+ if annotated_path =~ /<!-- BEGIN (\S*) -->/
136
+ # If the developer enters a partial that is in bullet_train-base like devise/shared/oauth or devise/shared/links,
137
+ # it will return a string starting with app/ so we simply point them to the file in this repository.
138
+ if annotated_path.match?(/^<!-- BEGIN app/) && !ejected_theme?
139
+ gem_path = `bundle show bullet_train`.chomp
140
+ "#{gem_path}/#{$1}"
137
141
  else
138
- raise "It looks like Xray-rails isn't properly enabled?"
142
+ $1
139
143
  end
140
- rescue ActionView::Template::Error => _
141
- return nil
144
+ else
145
+ raise "It looks like `config.action_view.annotate_rendered_view_with_filenames` isn't enabled?"
142
146
  end
147
+ rescue ActionView::Template::Error => _
148
+ nil
143
149
  end
144
150
 
145
151
  def file_path
146
152
  # We don't have to do anything here... the absolute path is what we're passed, and we just pass it back.
147
- @needle
153
+ if @needle[0] == "/"
154
+ @needle
155
+ end
148
156
  end
149
157
 
150
158
  def locale_path
151
159
  # This is a complete list of translation files provided by this app or any linked Bullet Train packages.
152
- (["#{Rails.root.to_s}/config/locales"] + `find ./tmp/gems/*`.lines.map(&:strip).map { |link| File.readlink(link) + "/config/locales" }).each do |locale_source|
160
+ (["#{Rails.root}/config/locales"] + `find ./tmp/gems/*`.lines.map(&:strip).map { |link| File.readlink(link) + "/config/locales" }).each do |locale_source|
153
161
  if File.exist?(locale_source)
154
162
  `find -L #{locale_source} | grep ".yml"`.lines.map(&:strip).each do |file_path|
155
163
  yaml = YAML.load_file(file_path, aliases: true)
@@ -161,7 +169,13 @@ module BulletTrain
161
169
  end
162
170
  end
163
171
 
164
- return nil
172
+ nil
173
+ end
174
+
175
+ def ejected_theme?
176
+ current_theme_symbol = File.read("#{Rails.root}/app/helpers/application_helper.rb").split("\n").find { |str| str.match?(/\s+:.*/) }
177
+ current_theme = current_theme_symbol.delete(":").strip
178
+ current_theme != "light" && Dir.exist?("#{Rails.root}/app/assets/stylesheets/#{current_theme}")
165
179
  end
166
180
  end
167
181
  end
@@ -1,3 +1,3 @@
1
1
  module BulletTrain
2
- VERSION = "1.0.45"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/bullet_train.rb CHANGED
@@ -9,7 +9,7 @@ require "bullet_train/has_uuid"
9
9
  require "bullet_train/scope_validator"
10
10
 
11
11
  require "colorizer"
12
- require "string/emoji"
12
+ require "bullet_train/core_ext/string_emoji_helper"
13
13
 
14
14
  require "devise"
15
15
  # require "devise-two-factor"
@@ -18,8 +18,6 @@ require "cancancan"
18
18
  require "possessive"
19
19
  require "sidekiq"
20
20
  require "fastimage"
21
- require "pry"
22
- require "pry-stack_explorer"
23
21
  require "awesome_print"
24
22
  require "microscope"
25
23
  require "http_accept_language"
@@ -31,10 +29,14 @@ require "figaro"
31
29
  require "valid_email"
32
30
  require "commonmarker"
33
31
  require "extended_email_reply_parser"
32
+ require "pagy"
33
+ require "devise/pwned_password"
34
34
 
35
35
  module BulletTrain
36
36
  mattr_accessor :routing_concerns, default: []
37
37
  mattr_accessor :linked_gems, default: ["bullet_train"]
38
+ mattr_accessor :parent_class, default: "Team"
39
+ mattr_accessor :base_class, default: "ApplicationRecord"
38
40
  end
39
41
 
40
42
  def default_url_options_from_base_url
@@ -59,7 +61,12 @@ def inbound_email_enabled?
59
61
  ENV["INBOUND_EMAIL_DOMAIN"].present?
60
62
  end
61
63
 
62
- def subscriptions_enabled?
64
+ def billing_enabled?
65
+ defined?(BulletTrain::Billing)
66
+ end
67
+
68
+ # TODO This should be in an initializer or something.
69
+ def billing_subscription_creation_disabled?
63
70
  false
64
71
  end
65
72
 
@@ -97,11 +104,14 @@ def two_factor_authentication_enabled?
97
104
  ENV["TWO_FACTOR_ENCRYPTION_KEY"].present?
98
105
  end
99
106
 
100
- def any_oauth_enabled?
101
- [
102
- stripe_enabled?,
103
- # 🚅 super scaffolding will insert new oauth provider checks above this line.
104
- ].select(&:present?).any?
107
+ # Don't redefine this if an application redefines it locally.
108
+ unless defined?(any_oauth_enabled?)
109
+ def any_oauth_enabled?
110
+ [
111
+ stripe_enabled?,
112
+ # 🚅 super scaffolding will insert new oauth provider checks above this line.
113
+ ].select(&:present?).any?
114
+ end
105
115
  end
106
116
 
107
117
  def invitation_only?
@@ -119,3 +129,7 @@ end
119
129
  def multiple_locales?
120
130
  @multiple_locales ||= I18n.available_locales.many?
121
131
  end
132
+
133
+ def silence_logs?
134
+ ENV["SILENCE_LOGS"].present?
135
+ end