bullet_train-themes-light 1.0.44 → 1.0.47

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20c969201f79403cce0cba8cb5a2d640f69ee2eac4a3b9c7194b6115d090ee66
4
- data.tar.gz: 8bacfd8bdc9af51ae1d5c9d4f7a7c9150caa015b34bd6235d82fd69af6a29495
3
+ metadata.gz: c253f5dd719876aebed5b2e12920b2bfe180848305a77cfc8a7ebe44d6d7f0c2
4
+ data.tar.gz: ea57904da051edeb079bbc2bd3fd3afca0c422b5eaaa5925e8ac2665ff716db1
5
5
  SHA512:
6
- metadata.gz: d682d968c52407f0ce55c5364653cf28e33aeb2c38b0f6f487c0362e9eaa02dac8c4a20a06a0d4970c7e0ca13bb2cb2cec35312d9e75b48b6e6473f316d64bfd
7
- data.tar.gz: 3c5c2681752f776e9af8a373c8d3b581395e8b373c076175ff15a307b8a47c97d1328b81f63fb10e938c9c8c067c98ff926199243349001cc0f6b07c9f291dd5
6
+ metadata.gz: a51ee5dfb6568b0a02d65852993609e76e36dd027dae87109eae5d7e32763969cdcf7710b241aeae112e062c8bb83a1432447ed4921c8801a68787cd9b730711
7
+ data.tar.gz: 31340a496d57fece4a5125277f5edbe534bc683cbde4da17a933856e75a58853b80344c9747e03aa091a43a133f6506b3d786d2fc95eb2d26e9e9ac51dff946b
@@ -8,11 +8,10 @@
8
8
  background-color: rgba(0, 0, 0, 0.15);
9
9
  }
10
10
 
11
- .bg-dark-gradient {
11
+ .bg-light-gradient {
12
12
  &:before {
13
13
  background: linear-gradient(to bottom right, var(--dark-gradient-from), var(--dark-gradient-to) 100%);
14
14
  }
15
- background: linear-gradient(to bottom right, var(--dark-gradient-from), var(--dark-gradient-to) 100%);
16
15
  }
17
16
 
18
17
  /**
@@ -1,7 +1,7 @@
1
1
  <% color ||= 'yellow' %>
2
2
 
3
3
  <div class="rounded-md bg-<%= color %>-400 border border-<%= color %>-500 py-4 px-5 mb-3">
4
- <h3 class="text-sm text-<%= color %>-600 text-<%= color %>-600 font-light">
4
+ <h3 class="text-sm text-<%= color %>-900 font-light">
5
5
  <%= yield %>
6
6
  </h3>
7
7
  </div>
@@ -38,7 +38,7 @@
38
38
  </div>
39
39
  <% end %>
40
40
 
41
- <% if p.content_for? :actions || pagy %>
41
+ <% if p.content_for?(:actions) || pagy %>
42
42
  <div class="pb-7 px-8 space-y-7">
43
43
  <div class="sm:flex">
44
44
  <div class="flex-1 space-x">
@@ -0,0 +1,228 @@
1
+ module BulletTrain
2
+ module Themes
3
+ module Light
4
+ class CustomThemeFileReplacer
5
+ mattr_accessor :repo_path
6
+
7
+ include BulletTrain::Themes::Light::FileReplacer
8
+
9
+ def initialize(custom_theme)
10
+ @repo_path = "./local/bullet_train-themes-#{custom_theme}"
11
+ end
12
+
13
+ def replace_theme(original_theme, custom_theme)
14
+ # Rename the directories
15
+ [
16
+ "/app/assets/stylesheets/bullet_train/themes/#{original_theme}/",
17
+ "/app/assets/stylesheets/#{original_theme}/",
18
+ "/app/views/themes/#{original_theme}/",
19
+ "/lib/bullet_train/themes/#{original_theme}/"
20
+ ].map { |file| @repo_path + file }.each do |original_directory|
21
+ custom_directory = original_directory.gsub(/(.*)(#{original_theme})(\/$)/, '\1' + custom_theme + '\3')
22
+ FileUtils.mv(original_directory, custom_directory)
23
+ end
24
+
25
+ # Only compare ejected files.
26
+ files_to_replace =
27
+ ejected_files_to_replace(original_theme, custom_theme).map { |file| {file_name: file, must_compare: true} } +
28
+ default_files_to_replace(original_theme).map { |file| {file_name: file, must_compare: false} }
29
+
30
+ # Replace the file contents and rename the files.
31
+ files_to_replace.each do |custom_gem_file|
32
+ # All of the files we want to compare against the fresh gem are in the main app.
33
+ main_app_file = build_main_app_file_name(original_theme, custom_theme, custom_gem_file[:file_name].gsub(@repo_path, "."))
34
+ custom_gem_file[:file_name] = adjust_directory_hierarchy(custom_gem_file[:file_name], original_theme)
35
+
36
+ # The content in the main app should replace the cloned gem files.
37
+ if custom_gem_file[:must_compare] && !BulletTrain::Themes::Light::FileReplacer.files_have_same_content?(custom_gem_file[:file_name], main_app_file)
38
+ BulletTrain::Themes::Light::FileReplacer.replace_content(old: custom_gem_file[:file_name], new: main_app_file)
39
+ end
40
+
41
+ # Only rename file names that still have the original theme in them, i.e. - ./tailwind.config.light.js
42
+ if File.basename(custom_gem_file[:file_name]).match?(original_theme)
43
+ main_app_file = adjust_directory_hierarchy(main_app_file, custom_theme)
44
+ new_file_name = main_app_file.gsub(/^\./, @repo_path).gsub(original_theme, custom_theme)
45
+ File.rename(custom_gem_file[:file_name], new_file_name)
46
+ end
47
+ end
48
+
49
+ # Change the content of specific files that contain the orignal theme's string.
50
+ # i.e. - `module Light` and `tailwind.light.config`.
51
+ constantized_original = constantize_from_snake_case(original_theme)
52
+ constantized_custom = constantize_from_snake_case(custom_theme)
53
+ files_whose_contents_need_to_be_replaced(custom_theme).each do |file|
54
+ new_lines = []
55
+ File.open(file, "r") do |f|
56
+ new_lines = f.readlines
57
+ new_lines = new_lines.map do |line|
58
+ # We want the original theme it's being edited from when creating a new theme.
59
+ # We also remove mattr_accessor in the eject task, so we need to add it back here.
60
+ if f.path == "#{@repo_path}/lib/bullet_train/themes/#{custom_theme}.rb" && line.match?("class Theme < BulletTrain::Themes::")
61
+ line = " mattr_accessor :color, default: :blue\n class Theme < BulletTrain::Themes::#{constantize_from_snake_case(original_theme)}::Theme\n"
62
+ else
63
+ # `_account.html.erb` and `_devise.html.erb` have tailwind classes that contain `light`.
64
+ # We shouldn't be replacing the classes with the custom theme string, so we skip it here.
65
+ # TODO: We should change this Regexp to check if the original theme is prefixed with `-`.
66
+ # If it is, we ignore the string if it's not prefixed with `bullet_train-themes-`,
67
+ line.gsub!(original_theme, custom_theme) unless line.match?("bg-light-gradient")
68
+ line.gsub!(constantized_original, constantized_custom)
69
+ end
70
+ line
71
+ end
72
+ end
73
+
74
+ File.open(file, "w") do |f|
75
+ f.puts new_lines.join
76
+ end
77
+ end
78
+
79
+ # The contents in this specific main app file don't have the require statements which the gem
80
+ # originally has, so we add those back after moving the main app file contents to the gem.
81
+ new_lines = nil
82
+ File.open("#{@repo_path}/lib/bullet_train/themes/#{custom_theme}.rb", "r") do |file|
83
+ new_lines = file.readlines
84
+ require_lines =
85
+ <<~RUBY
86
+ require "bullet_train/themes/#{custom_theme}/version"
87
+ require "bullet_train/themes/#{custom_theme}/engine"
88
+ require "bullet_train/themes/#{original_theme}"
89
+
90
+ RUBY
91
+ new_lines.unshift(require_lines)
92
+ end
93
+ File.open("#{@repo_path}/lib/bullet_train/themes/#{custom_theme}.rb", "w") do |file|
94
+ file.puts new_lines.flatten.join
95
+ end
96
+
97
+ # Since we're generating a new gem, it should be version 1.0
98
+ File.open("#{@repo_path}/lib/bullet_train/themes/#{custom_theme}/version.rb", "r") do |file|
99
+ new_lines = file.readlines
100
+ new_lines = new_lines.map { |line| line.match?("VERSION") ? " VERSION = \"1.0\"\n" : line }
101
+ end
102
+ File.open("#{@repo_path}/lib/bullet_train/themes/#{custom_theme}/version.rb", "w") do |file|
103
+ file.puts new_lines.join
104
+ end
105
+
106
+ # Remove files and directories from the main application.
107
+ files_to_remove_from_main_app(custom_theme).each { |file| File.delete(file) }
108
+ directories_to_remove_from_main_app(custom_theme).each do |directory|
109
+ FileUtils.rm_rf(directory) unless directory.nil?
110
+ end
111
+
112
+ # Update the author and email.
113
+ # If the developer hasn't set these yet, this should simply return empty strings.
114
+ author = `git config --global user.name`.chomp
115
+ email = `git config --global user.email`.chomp
116
+ File.open("#{@repo_path}/bullet_train-themes-#{custom_theme}.gemspec", "r") do |file|
117
+ new_lines = file.readlines
118
+ new_lines = new_lines.map do |line|
119
+ if line.match?("spec.authors")
120
+ " spec.authors = [\"#{author}\"]\n"
121
+ elsif line.match?("spec.email")
122
+ " spec.email = [\"#{email}\"]\n"
123
+ else
124
+ line
125
+ end
126
+ end
127
+ end
128
+ File.open("#{@repo_path}/bullet_train-themes-#{custom_theme}.gemspec", "w") do |file|
129
+ file.puts new_lines.join
130
+ end
131
+ end
132
+
133
+ # By the time we call this method we have already updated the new gem's directories with
134
+ # the custom theme name, but the FILE names are still the same from when they were cloned,
135
+ # so we use `original_theme` for specific file names below.
136
+ def ejected_files_to_replace(original_theme, custom_theme)
137
+ [
138
+ Dir.glob("#{@repo_path}/app/assets/stylesheets/#{custom_theme}/**/*.css"),
139
+ Dir.glob("#{@repo_path}/app/assets/stylesheets/#{custom_theme}/**/*.scss"),
140
+ Dir.glob("#{@repo_path}/app/views/themes/#{custom_theme}/**/*.html.erb"),
141
+ "/app/javascript/application.#{original_theme}.js",
142
+ "/tailwind.#{original_theme}.config.js",
143
+ "/app/lib/bullet_train/themes/#{original_theme}.rb",
144
+ # The Glob up top doesn't grab the #{original_theme}.tailwind.css file, so we set that here.
145
+ "/app/assets/stylesheets/#{original_theme}.tailwind.css",
146
+ "/tailwind.mailer.#{original_theme}.config.js"
147
+ ].flatten.map { |file| file.match?(/^#{@repo_path}/) ? file : @repo_path + file }
148
+ end
149
+
150
+ # These files represent ones such as "./lib/bullet_train/themes/light.rb" which
151
+ # aren't ejected to the developer's main app, but still need to be changed.
152
+ def default_files_to_replace(original_theme)
153
+ # TODO: Add this file and the FileReplacer module once they're added to the main branch.
154
+ [
155
+ "/bullet_train-themes-#{original_theme}.gemspec",
156
+ "/app/assets/config/bullet_train_themes_#{original_theme}_manifest.js",
157
+ "/lib/tasks/bullet_train/themes/#{original_theme}_tasks.rake",
158
+ "/test/bullet_train/themes/#{original_theme}_test.rb"
159
+ ].map { |file| @repo_path + file }
160
+ end
161
+
162
+ def files_to_remove_from_main_app(custom_theme)
163
+ [
164
+ Dir.glob("./app/assets/stylesheets/#{custom_theme}/**/*.css"),
165
+ Dir.glob("./app/assets/stylesheets/#{custom_theme}/**/*.scss"),
166
+ "./app/assets/stylesheets/#{custom_theme}.tailwind.css",
167
+ "./app/javascript/application.#{custom_theme}.js",
168
+ "./app/lib/bullet_train/themes/#{custom_theme}.rb",
169
+ Dir.glob("./app/views/themes/#{custom_theme}/**/*.html.erb")
170
+ ].flatten
171
+ end
172
+
173
+ def files_whose_contents_need_to_be_replaced(custom_theme)
174
+ [
175
+ "/app/assets/stylesheets/#{custom_theme}.tailwind.css",
176
+ "/app/views/themes/#{custom_theme}/layouts/_account.html.erb",
177
+ "/app/views/themes/#{custom_theme}/layouts/_devise.html.erb",
178
+ "/bin/rails",
179
+ "/lib/bullet_train/themes/#{custom_theme}/engine.rb",
180
+ "/lib/bullet_train/themes/#{custom_theme}/version.rb",
181
+ "/lib/bullet_train/themes/#{custom_theme}.rb",
182
+ "/lib/tasks/bullet_train/themes/#{custom_theme}_tasks.rake",
183
+ "/test/bullet_train/themes/#{custom_theme}_test.rb",
184
+ "/test/dummy/app/views/layouts/mailer.html.erb",
185
+ "/test/dummy/config/application.rb",
186
+ "/bullet_train-themes-#{custom_theme}.gemspec",
187
+ "/Gemfile",
188
+ "/README.md"
189
+ ].map { |file| @repo_path + file }
190
+ end
191
+
192
+ def directories_to_remove_from_main_app(custom_theme)
193
+ [
194
+ "./app/assets/stylesheets/#{custom_theme}/",
195
+ "./app/views/themes/#{custom_theme}/",
196
+ "./app/lib/"
197
+ ].map { |directory| directory unless directory == "./app/lib/" && Dir.empty?(directory) }
198
+ end
199
+
200
+ # Since we're cloning a fresh gem, file names that contain the original
201
+ # theme stay the same, i.e. - tailwind.light.config.js. However, the names have
202
+ # already been changed in the main app when the original theme was ejected.
203
+ # Here, we build the correct string that is in the main app to compare the
204
+ # files' contents. Then later on we actually rename the new gem's file names.
205
+ def build_main_app_file_name(original_theme, custom_theme, custom_gem_file)
206
+ main_app_file = custom_gem_file
207
+ custom_gem_file_hierarchy = custom_gem_file.split("/")
208
+ if custom_gem_file_hierarchy.last.match?(original_theme)
209
+ custom_gem_file_hierarchy.last.gsub!(original_theme, custom_theme)
210
+ main_app_file = custom_gem_file_hierarchy.join("/")
211
+ end
212
+ main_app_file
213
+ end
214
+
215
+ # This addresses one specific file where the hierarchy is
216
+ # different after the file is ejected into the main application.
217
+ def adjust_directory_hierarchy(file_name, theme_name)
218
+ file_name.match?("lib/bullet_train/themes/#{theme_name}") ? file_name.gsub(/\/app/, "") : file_name
219
+ end
220
+
221
+ # i.e. - foo_bar or foo-bar to FooBar
222
+ def constantize_from_snake_case(str)
223
+ str.split(/[_|-]/).map(&:capitalize).join
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,18 @@
1
+ # TODO: We overwrite/edit/create files a lot in Bullet Train,
2
+ # so I feel like this and a lot of similar content could go inside its own gem.
3
+ module BulletTrain
4
+ module Themes
5
+ module Light
6
+ module FileReplacer
7
+ def self.files_have_same_content?(first_file_name, second_file_name)
8
+ File.open(first_file_name).readlines == File.open(second_file_name).readlines
9
+ end
10
+
11
+ # Replaces the old content with a brand new file.
12
+ def self.replace_content(old:, new:)
13
+ File.write(old, File.open(new).readlines.join(""))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  module BulletTrain
2
2
  module Themes
3
3
  module Light
4
- VERSION = "1.0.44"
4
+ VERSION = "1.0.47"
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,8 @@
1
1
  require "bullet_train/themes/light/version"
2
2
  require "bullet_train/themes/light/engine"
3
3
  require "bullet_train/themes/tailwind_css"
4
+ require "bullet_train/themes/light/file_replacer"
5
+ require "bullet_train/themes/light/custom_theme_file_replacer"
4
6
 
5
7
  module BulletTrain
6
8
  module Themes
@@ -52,6 +52,110 @@ namespace :bullet_train do
52
52
 
53
53
  puts "You must restart `bin/dev` at this point, because of the changes to `Procfile.dev` and `package.json`."
54
54
  end
55
+
56
+ desc "Publish your custom theme theme as a Ruby gem."
57
+ task :release, [:theme_name] => :environment do |task, args|
58
+ puts "Preparing to release your custom theme: ".blue + args[:theme_name]
59
+ puts ""
60
+ puts "Before we make a new Ruby gem for your theme, you'll have to set up a GitHub repository first.".blue
61
+ puts "Hit <Return> and we'll open a browser to GitHub where you can create a new repository.".blue
62
+ puts "Make sure you name the repository ".blue + "bullet_train-themes-#{args[:theme_name]}"
63
+ puts ""
64
+ puts "When you're done, copy the SSH path from the new repository and return here.".blue
65
+ ask "We'll ask you to paste it to us in the next step."
66
+ `#{Gem::Platform.local.os == "linux" ? "xdg-open" : "open"} https://github.com/new`
67
+
68
+ ssh_path = ask "OK, what was the SSH path? (It should look like `git@github.com:your-account/your-new-repo.git`.)"
69
+ puts ""
70
+ puts "Great, you're all set.".blue
71
+ puts "We'll take it from here, so sit back and enjoy the ride 🚄️".blue
72
+ puts ""
73
+ puts "Creating a Ruby gem for ".blue + "#{args[:theme_name]}..."
74
+
75
+ Dir.mkdir("local") unless Dir.exist?("./local")
76
+ if Dir.exist?("./local/bullet_train-themes-#{args[:theme_name]}")
77
+ raise "You already have a repository named `bullet_train-themes-#{args[:theme_name]}` in `./local`.\n" \
78
+ "Make sure you delete it first to create an entirely new gem."
79
+ end
80
+ `git clone git@github.com:bullet-train-co/bullet_train-themes-light.git ./local/bullet_train-themes-#{args[:theme_name]}`
81
+
82
+ custom_file_replacer = BulletTrain::Themes::Light::CustomThemeFileReplacer.new(args[:theme_name])
83
+ custom_file_replacer.replace_theme("light", args[:theme_name])
84
+
85
+ work_tree_flag = "--work-tree=local/bullet_train-themes-#{args[:theme_name]}"
86
+ git_dir_flag = "--git-dir=local/bullet_train-themes-#{args[:theme_name]}/.git"
87
+ path = "./local/bullet_train-themes-#{args[:theme_name]}"
88
+
89
+ # Set up the proper remote.
90
+ `git #{work_tree_flag} #{git_dir_flag} remote set-url origin #{ssh_path}`
91
+ `git #{work_tree_flag} #{git_dir_flag} add .`
92
+ `git #{work_tree_flag} #{git_dir_flag} commit -m "Add initial files"`
93
+
94
+ # Build the gem.
95
+ `(cd #{path} && gem build bullet_train-themes-#{args[:theme_name]}.gemspec)`
96
+ `git #{work_tree_flag} #{git_dir_flag} add .`
97
+ `git #{work_tree_flag} #{git_dir_flag} commit -m "Build gem"`
98
+
99
+ # Commit the deleted files on the main application.
100
+ `git add .`
101
+ `git commit -m "Remove #{args[:theme_name]} files from application"`
102
+
103
+ # Push the gem's source code, but not the last commit in the main application.
104
+ `git #{work_tree_flag} #{git_dir_flag} push -u origin main`
105
+
106
+ puts ""
107
+ puts ""
108
+ puts "You're all set! Copy and paste the following commands to publish your gem:".blue
109
+ puts "cd ./local/bullet_train-themes-#{args[:theme_name]}"
110
+ puts "gem push bullet_train-themes-#{args[:theme_name]}-1.0.gem && cd ../../"
111
+ puts ""
112
+ puts "You may have to wait for some time until the gem can be downloaded via the Gemfile.".blue
113
+ puts "After a few minutes, run the following command in your main application:".blue
114
+ puts "bundle add bullet_train-themes-#{args[:theme_name]}"
115
+ puts ""
116
+ puts "Then you'll be ready to use your custom gem in your Bullet Train application.".blue
117
+ end
118
+
119
+ desc "Install this theme to your main application."
120
+ task :install do |rake_task|
121
+ # Grab the theme name from the rake task, bullet_train:theme:light:install
122
+ theme_name = rake_task.name.split(":")[2]
123
+
124
+ # Grabs the current theme from
125
+ # def current_theme
126
+ # :theme_name
127
+ # end
128
+ current_theme_regexp = /(^ :)(.*)/
129
+ current_theme = nil
130
+
131
+ new_lines = []
132
+ [
133
+ "./app/helpers/application_helper.rb",
134
+ "./Procfile.dev",
135
+ "./package.json"
136
+ ].each do |file|
137
+ File.open(file, "r") do |f|
138
+ new_lines = f.readlines
139
+ new_lines = new_lines.map do |line|
140
+ # Make sure we get the current theme before trying to replace it in any of the files.
141
+ # We grab it from the first file in the array above.
142
+ current_theme = line.scan(current_theme_regexp).flatten.last if line.match?(current_theme_regexp)
143
+
144
+ line.gsub!(/#{current_theme}/, theme_name) unless current_theme.nil?
145
+ line
146
+ end
147
+ end
148
+
149
+ File.open(file, "w") do |f|
150
+ f.puts new_lines.join
151
+ end
152
+ end
153
+ end
154
+
155
+ def ask(string)
156
+ puts string.blue
157
+ $stdin.gets.strip
158
+ end
55
159
  end
56
160
  end
57
161
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-themes-light
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.44
4
+ version: 1.0.47
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-07-21 00:00:00.000000000 Z
11
+ date: 2022-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -124,7 +124,9 @@ files:
124
124
  - app/views/themes/light/workflow/_box.html.erb
125
125
  - config/routes.rb
126
126
  - lib/bullet_train/themes/light.rb
127
+ - lib/bullet_train/themes/light/custom_theme_file_replacer.rb
127
128
  - lib/bullet_train/themes/light/engine.rb
129
+ - lib/bullet_train/themes/light/file_replacer.rb
128
130
  - lib/bullet_train/themes/light/version.rb
129
131
  - lib/tasks/bullet_train/themes/light_tasks.rake
130
132
  - tailwind.light.config.js