bullet_train 1.0.28 ā†’ 1.0.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9a2cb019fbf151b922e19e9ad2aec5f84ac7fd50045bd23d2ba94478c86a0dc
4
- data.tar.gz: e63d7bb9128c48f49ee9e7b388c490173569624c2aaeb35d0c7a8d72d54c5abd
3
+ metadata.gz: 2967f0b80a95786b9a7e0816284db63ed4b149a644b1c050df1904a56df7947f
4
+ data.tar.gz: 92ac669e6fb6091e32772a8281207b35bb034a4481649971c4682e74486734dd
5
5
  SHA512:
6
- metadata.gz: cbfa5d7e78cb1d62ad68966763a1c8d654c2ca6d080a3ad7a3d6e1126d0b46a44d96dcfeac454e368b5d58388dc2c5ab7f3d41122b8c03acb004e1447c2aced6
7
- data.tar.gz: 73abfc993caaf2fbc71fccace9925bf8e897e35db76d4ef9c5cfe50495db45b33fecc924866da25a5b410e70d0a0f100da7f5a3f515cb4d681e2db68a60b1260
6
+ metadata.gz: 63ade82241aab3d3ca9267e8217ef604bde7f1142b25e63b21d1a95c93b0fa914ec51ee0f869c9b1080500e5b15a79317eefe369c91edd8db81dedf01bd37d46
7
+ data.tar.gz: c241470aa225ea03179125b2ac640ef34a8958058e2ae5457d3b1ca37de560d05808b15568b6bee2755e5fb6a44ef9b3fcc135b7160e5c77a797e6ccea76c07d
@@ -35,11 +35,43 @@ module Account::LocaleHelper
35
35
  end
36
36
 
37
37
  def t(key, options = {})
38
+ # When bundled Ruby gems provide a lot of translations, it can be difficult to figure out which strings in the
39
+ # application are coming from where. To help with this, you can add `?debug=true` to any URL and we'll output
40
+ # any rendered strings and their translation keys on the console.
41
+ unless Rails.env.production?
42
+ if params[:log_locales] || params[:show_locales]
43
+ # Often times we're only receiving partial keys like `.section`, so this is a crazy hack to trick I18n.t into
44
+ # telling us what the full key ended up being.
45
+ begin
46
+ super(key + "šŸ’£", options.except(:default))
47
+ rescue I18n::MissingTranslationData => exception
48
+ full_key = exception.message.rpartition(" ").last.gsub("šŸ’£", "")
49
+ end
50
+ end
51
+ end
52
+
38
53
  if account_controller?
39
- # give preference to the options they've passed in.
54
+ # Give preference to the options they've passed in.
40
55
  options = models_locales(@child_object, @parent_object).merge(options)
41
56
  end
42
- super(key, options)
57
+
58
+ result = super(key, options)
59
+
60
+ unless Rails.env.production?
61
+ if params[:log_locales]
62
+ if result == options[:default]
63
+ puts "šŸŒ #{full_key}: Not found? Result matched default: \"#{result}\"".yellow
64
+ else
65
+ puts "šŸŒ #{full_key}: \"#{result}\"".green
66
+ end
67
+ end
68
+
69
+ if params[:show_locales]
70
+ return full_key
71
+ end
72
+ end
73
+
74
+ return result
43
75
  end
44
76
 
45
77
  # like 't', but if the key isn't found, it returns nil.
@@ -0,0 +1,2 @@
1
+ <%= render @needle do |p| %>
2
+ <% end %>
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  <%= render 'account/shared/workflow/box' do |p| %>
4
2
  <% p.content_for :title, t('devise.headers.sign_in') %>
5
3
  <% p.content_for :body do %>
@@ -30,7 +30,12 @@
30
30
  # available at https://guides.rubyonrails.org/i18n.html.
31
31
 
32
32
  en:
33
-
33
+ bullet_train:
34
+ name: Bullet Train
35
+ tagline: The Ruby on Rails SaaS Template
36
+ description: Bullet Train is a Ruby on Rails SaaS-in-a-Box that saves developers weeks of effort.
37
+ keywords: bullet train ruby on rails saas template starter kit
38
+ support_email: ask@bullettrain.co
34
39
  global:
35
40
  or: Or
36
41
  more: More
@@ -0,0 +1,167 @@
1
+ require 'io/wait'
2
+
3
+ module BulletTrain
4
+ class Resolver
5
+ include I18n::Backend::Flatten
6
+
7
+ def initialize(needle)
8
+ @needle = needle
9
+ end
10
+
11
+ def run(eject: false, open: false, force: false, interactive: false)
12
+ # Try to figure out what kind of thing they're trying to look up.
13
+ source_file = calculate_source_file_details
14
+
15
+ if source_file[:absolute_path]
16
+ if source_file[:package_name].present?
17
+ puts ""
18
+ puts "Absolute path:".green
19
+ puts " #{source_file[:absolute_path]}".green
20
+ puts ""
21
+ puts "Package name:".green
22
+ puts " #{source_file[:package_name]}".green
23
+ puts ""
24
+ else
25
+ puts ""
26
+ puts "Project path:".green
27
+ puts " #{source_file[:project_path]}".green
28
+ puts ""
29
+ 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
+ end
32
+
33
+ if interactive && !eject
34
+ puts "\nWould you like to eject the file into the local project? (y/n)\n"
35
+ input = $stdin.gets
36
+ $stdin.getc while $stdin.ready?
37
+ if input.first.downcase == 'y'
38
+ eject = true
39
+ end
40
+ end
41
+
42
+ if eject
43
+ if source_file[:package_name]
44
+ if File.exist?(source_file[:project_path]) && !force
45
+ return puts "Can't eject! `#{source_file[:project_path]}` already exists!\n".red
46
+ else
47
+ `mkdir -p #{source_file[:project_path].split("/")[0...-1].join("/")}`
48
+ puts "Ejecting `#{source_file[:absolute_path]}` to `#{source_file[:project_path]}`".green
49
+ File.open("#{source_file[:project_path]}", "w+") do |file|
50
+ case source_file[:project_path].split(".").last
51
+ when "rb", "yml"
52
+ file.puts "# Ejected from `#{source_file[:package_name]}`.\n\n"
53
+ when "erb"
54
+ file.puts "<% # Ejected from `#{source_file[:package_name]}`. %>\n\n"
55
+ end
56
+ end
57
+ `cat #{source_file[:absolute_path]} >> #{source_file[:project_path]}`.strip
58
+ end
59
+
60
+ # Just in case they try to open the file, open it from the new location.
61
+ source_file[:absolute_path] = source_file[:project_path]
62
+ else
63
+ puts "This file is already in the local project directory. Skipping ejection.".yellow
64
+ puts ""
65
+ end
66
+ end
67
+
68
+ if interactive && !open
69
+ puts "\nWould you like to open `#{source_file[:absolute_path]}`? (y/n)\n"
70
+ input = $stdin.gets
71
+ $stdin.getc while $stdin.ready?
72
+ if input.first.downcase == 'y'
73
+ open = true
74
+ end
75
+ end
76
+
77
+ if open
78
+ path = source_file[:package_name] ? source_file[:absolute_path] : "#{source_file[:project_path]}"
79
+ puts "Opening `#{path}`.\n".green
80
+ exec "open #{path}"
81
+ end
82
+ else
83
+ puts "Couldn't resolve `#{@needle}`.".red
84
+ end
85
+ end
86
+
87
+ def calculate_source_file_details
88
+ result = {
89
+ absolute_path: nil,
90
+ project_path: nil,
91
+ package_name: nil,
92
+ }
93
+
94
+ result[:absolute_path] = class_path || partial_path || locale_path || file_path
95
+
96
+ 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
109
+
110
+ result[:project_path] = project_path
111
+ result[:package_name] = package_name
112
+ end
113
+ end
114
+ end
115
+
116
+ result
117
+ end
118
+
119
+ def url?
120
+ @needle.match?(/https?:\/\//)
121
+ end
122
+
123
+ def class_path
124
+ begin
125
+ @needle.constantize
126
+ return Object.const_source_location(@needle).first
127
+ rescue NameError => _
128
+ return false
129
+ end
130
+ end
131
+
132
+ def partial_path
133
+ 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
137
+ else
138
+ raise "It looks like Xray-rails isn't properly enabled?"
139
+ end
140
+ rescue ActionView::Template::Error => _
141
+ return nil
142
+ end
143
+ end
144
+
145
+ def file_path
146
+ # We don't have to do anything here... the absolute path is what we're passed, and we just pass it back.
147
+ @needle
148
+ end
149
+
150
+ def locale_path
151
+ # 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|
153
+ if File.exist?(locale_source)
154
+ `find -L #{locale_source} | grep ".yml"`.lines.map(&:strip).each do |file_path|
155
+ yaml = YAML.load_file(file_path, aliases: true)
156
+ translations = flatten_translations(nil, yaml, nil, false)
157
+ if translations[@needle.to_sym].present?
158
+ return file_path
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ return nil
165
+ end
166
+ end
167
+ end
@@ -1,3 +1,3 @@
1
1
  module BulletTrain
2
- VERSION = "1.0.28"
2
+ VERSION = "1.0.31"
3
3
  end
data/lib/bullet_train.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bullet_train/version"
2
2
  require "bullet_train/engine"
3
+ require "bullet_train/resolver"
3
4
 
4
5
  require "bullet_train/fields"
5
6
  require "bullet_train/roles"
@@ -1,3 +1,5 @@
1
+ require 'io/wait'
2
+
1
3
  namespace :bullet_train do
2
4
  desc "Symlink registered gems in `./tmp/gems` so their views, etc. can be inspected by Tailwind CSS."
3
5
  task :link_gems => :environment do
@@ -19,8 +21,37 @@ namespace :bullet_train do
19
21
  target = `bundle show #{linked_gem}`.chomp
20
22
  if target.present?
21
23
  puts "Linking '#{linked_gem}' to '#{target}'."
22
- puts `ln -s #{target} tmp/gems/#{linked_gem}`
24
+ `ln -s #{target} tmp/gems/#{linked_gem}`
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "Figure out where something is coming from."
30
+ task :resolve, [:all_options] => :environment do |t, arguments|
31
+ ARGV.pop while ARGV.any?
32
+
33
+ arguments[:all_options]&.split&.each do |argument|
34
+ ARGV.push(argument)
35
+ end
36
+
37
+ if ARGV.include?("--interactive")
38
+ puts "\nOK, paste what you've got for us and hit <Return>!\n".blue
39
+
40
+ input = $stdin.gets.strip
41
+ $stdin.getc while $stdin.ready?
42
+
43
+ # Extract absolute paths from XRAY comments.
44
+ if input.match(/<!--XRAY START \d+ (.*)-->/)
45
+ input = $1
23
46
  end
47
+
48
+ ARGV.unshift input.strip
49
+ end
50
+
51
+ if ARGV.first.present?
52
+ BulletTrain::Resolver.new(ARGV.first).run(eject: ARGV.include?("--eject"), open: ARGV.include?("--open"), force: ARGV.include?("--force"), interactive: ARGV.include?("--interactive"))
53
+ else
54
+ $stderr.puts "\nšŸš… Usage: `bin/resolve [path, partial, or URL] (--eject) (--open)`\n".blue
24
55
  end
25
56
  end
26
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.28
4
+ version: 1.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -450,6 +450,7 @@ files:
450
450
  - app/views/account/users/_form.html.erb
451
451
  - app/views/account/users/edit.html.erb
452
452
  - app/views/account/users/show.html.erb
453
+ - app/views/bullet_train/partial_resolver.html.erb
453
454
  - app/views/devise/confirmations/new.html.erb
454
455
  - app/views/devise/mailer/confirmation_instructions.html.erb
455
456
  - app/views/devise/mailer/password_change.html.erb
@@ -522,6 +523,7 @@ files:
522
523
  - db/migrate/20211027002944_add_doorkeeper_application_to_users.rb
523
524
  - lib/bullet_train.rb
524
525
  - lib/bullet_train/engine.rb
526
+ - lib/bullet_train/resolver.rb
525
527
  - lib/bullet_train/version.rb
526
528
  - lib/colorizer.rb
527
529
  - lib/string/emoji.rb