bullet_train-themes 1.0.1

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 (37) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/config/bullet_train_themes_manifest.js +0 -0
  6. data/app/helpers/theme_helper.rb +19 -0
  7. data/app/views/themes/base/attributes/_attribute.html.erb +8 -0
  8. data/app/views/themes/base/attributes/_belongs_to.html.erb +14 -0
  9. data/app/views/themes/base/attributes/_block.html.erb +9 -0
  10. data/app/views/themes/base/attributes/_boolean.html.erb +9 -0
  11. data/app/views/themes/base/attributes/_code.html.erb +10 -0
  12. data/app/views/themes/base/attributes/_date.html.erb +9 -0
  13. data/app/views/themes/base/attributes/_date_and_time.html.erb +9 -0
  14. data/app/views/themes/base/attributes/_days_ago.html.erb +11 -0
  15. data/app/views/themes/base/attributes/_email.html.erb +9 -0
  16. data/app/views/themes/base/attributes/_has_many.html.erb +19 -0
  17. data/app/views/themes/base/attributes/_html.html.erb +10 -0
  18. data/app/views/themes/base/attributes/_image.html.erb +5 -0
  19. data/app/views/themes/base/attributes/_option.html.erb +9 -0
  20. data/app/views/themes/base/attributes/_options.html.erb +11 -0
  21. data/app/views/themes/base/attributes/_phone_number.html.erb +9 -0
  22. data/app/views/themes/base/attributes/_text.html.erb +9 -0
  23. data/app/views/themes/base/fields/_ckeditor.html.erb +25 -0
  24. data/app/views/themes/base/fields/_email_field.html.erb +9 -0
  25. data/app/views/themes/base/fields/_password_field.html.erb +9 -0
  26. data/app/views/themes/base/fields/_phone_field.html.erb +15 -0
  27. data/app/views/themes/base/fields/_super_select.html.erb +39 -0
  28. data/app/views/themes/base/fields/_text_area.html.erb +9 -0
  29. data/app/views/themes/base/fields/_text_field.html.erb +9 -0
  30. data/app/views/themes/base/fields/_trix_editor.html.erb +28 -0
  31. data/config/routes.rb +2 -0
  32. data/lib/bullet_train/themes/engine.rb +8 -0
  33. data/lib/bullet_train/themes/version.rb +5 -0
  34. data/lib/bullet_train/themes.rb +8 -0
  35. data/lib/tasks/bullet_train/themes_tasks.rake +4 -0
  36. data/lib/theme_partials.rb +97 -0
  37. metadata +94 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 88b8f18381414981334281312835975fd93241577a4eff5fd85aece600fa76e3
4
+ data.tar.gz: 272efa679248e0957b78e05ca1b4e96e99924b8a49e98567d1247891c416d438
5
+ SHA512:
6
+ metadata.gz: 7fa85c03a6e0dd87797097d8fad5f9f7af6a9b6675e89b300a90b220d87bec1798dea849a6a778b4deba4d835ad6f682eef32da234e1ee6cbc7cde91822479ed
7
+ data.tar.gz: faf92219a9b463333c271c402e0d4c143758bbe785e4679ae4e7ec09c191ee3b8781eb906370fdcac31429f33d10f10bd219772f4793c40e30021ea5d15e2741
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Andrew Culver
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # BulletTrain::Themes
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "bullet_train-themes"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install bullet_train-themes
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
File without changes
@@ -0,0 +1,19 @@
1
+ require_relative "../../lib/theme_partials"
2
+
3
+ module ThemeHelper
4
+ include ThemePartials
5
+
6
+ def current_theme
7
+ THEME_DIRECTORY_ORDER.first
8
+ end
9
+
10
+ def render(options = {}, locals = {}, &block)
11
+ if options.is_a?(String)
12
+ theme_partial = Resolver.resolve(options)
13
+
14
+ return super theme_partial, locals, &block unless theme_partial.blank?
15
+ end
16
+
17
+ super
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <%= render 'shared/attributes/base', strategy: strategy, url: url do |p| %>
6
+ <% p.content_for :heading, t("#{object.class.name.pluralize.underscore}.fields.#{attribute}.heading") %>
7
+ <% p.content_for :body, yield %>
8
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% disable_link ||= false %>
4
+ <% url ||= nil %>
5
+
6
+ <% if object.send(attribute).present? %>
7
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
8
+ <% if disable_link %>
9
+ <%= object.send(attribute).label_string %>
10
+ <% else %>
11
+ <%= link_to object.send(attribute).label_string, url || [:account, object.send(attribute)] %>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <pre><%= object.send(attribute) %></pre>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
6
+ <% unless object[attribute].nil? %>
7
+ <%= t("#{object.class.name.underscore.pluralize}.fields.#{attribute}.options.#{object.send(attribute)}") %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% source ||= nil %>
4
+ <% url ||= nil %>
5
+
6
+ <% if object.send(attribute).present? %>
7
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
8
+ <code class="text-pink-600 font-light"><%= object.send(source || attribute) %></code>
9
+ <% end %>
10
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= display_date(object.send(attribute)) %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= display_date_and_time(object.send(attribute)) %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
6
+ <% if object.send(attribute) %>
7
+ <%= time_ago_in_words(object.send(attribute)) %> ago
8
+ <% else %>
9
+ Never
10
+ <% end %>
11
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= link_to object.send(attribute), "mailto:#{object.send(attribute)}" %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% link_source ||= nil %>
4
+ <% disable_links ||= false %>
5
+ <% link_options ||= {} %>
6
+
7
+ <% if object.send(attribute).any? %>
8
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy do %>
9
+ <%= object.send(attribute).map do |child_object| %>
10
+ <% capture do %>
11
+ <% if disable_links %>
12
+ <%= child_object.label_string %>
13
+ <% else %>
14
+ <%= link_to child_object.label_string, [:account, link_source ? child_object.send(link_source) : child_object], link_options %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end.map(&:strip).to_sentence.html_safe %>
18
+ <% end %>
19
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <% # `.to_s` is for action text. %>
8
+ <%= trix_content(object.send(attribute).to_s).html_safe %>
9
+ <% end %>
10
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <%= cloudinary_image_tag @tangible_thing.send(attribute), height: 200 %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= t("#{object.class.name.underscore.pluralize}.fields.#{attribute}.options.#{object.send(attribute)}") %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).any? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= object.send(attribute).map do |value| %>
8
+ <% t("#{object.class.name.underscore.pluralize}.fields.#{attribute}.options.#{value}") %>
9
+ <% end.map(&:strip).to_sentence %>
10
+ <% end %>
11
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= display_phone_number(object.send(attribute)) %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% object ||= current_attributes_object %>
2
+ <% strategy ||= current_attributes_strategy || :none %>
3
+ <% url ||= nil %>
4
+
5
+ <% if object.send(attribute).present? %>
6
+ <%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
7
+ <%= object.send(attribute) %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ # ⚠️ CKEditor 5 is distributed under a GPL 2+ copyleft license.
5
+ # You need a commercial license to utilize it in closed-source SaaS products.
6
+ # See https://ckeditor.com/pricing/ for more details.
7
+ %>
8
+
9
+ <%
10
+ stimulus_controller = 'fields--ckeditor'
11
+
12
+ form ||= current_fields_form
13
+ options ||= {}
14
+ options = options.merge({ data: {"#{stimulus_controller}-target": 'field' }})
15
+ other_options ||= {}
16
+
17
+ %>
18
+
19
+ <%= render 'shared/fields/field', form: form, method: method, options: options, other_options: other_options do %>
20
+ <% content_for :field do %>
21
+ <div data-controller="<%= stimulus_controller %>">
22
+ <%= form.text_area method, options %>
23
+ </div>
24
+ <% end %>
25
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ form ||= current_fields_form
5
+ options ||= {}
6
+ other_options ||= {}
7
+ %>
8
+
9
+ <%= render 'shared/fields/field', form: form, method: method, helper: :email_field, options: options, other_options: other_options %>
@@ -0,0 +1,9 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ form ||= current_fields_form
5
+ options ||= {}
6
+ other_options ||= {}
7
+ %>
8
+
9
+ <%= render 'shared/fields/field', form: form, method: method, helper: :password_field, options: options, other_options: other_options %>
@@ -0,0 +1,15 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ stimulus_controller = 'fields--phone'
5
+
6
+ form ||= current_fields_form
7
+ options ||= {}
8
+ options = options.merge({type: 'tel', data: {method: method, "#{stimulus_controller}-target": 'field' }})
9
+ other_options ||= {}
10
+
11
+ %>
12
+
13
+ <div data-controller="<%= stimulus_controller %>">
14
+ <%= render 'shared/fields/field', form: form, method: method, helper: :text_field, options: options, other_options: other_options %>
15
+ </div>
@@ -0,0 +1,39 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ stimulus_controller = 'fields--super-select'
5
+
6
+ form ||= current_fields_form
7
+ options ||= {}
8
+ other_options ||= {}
9
+ html_options ||= {}
10
+ html_options[:id] ||= id_for(form, method)
11
+ html_options[:class] = "form-control select2 #{html_options[:class]}".strip
12
+ choices_url ||= nil
13
+ if choices_url.nil?
14
+ choices ||= options_for(form, method)&.invert
15
+ else
16
+ # If we have a choices_url, we're going to lazy load the choices. However, we still want to show the currently selected option.
17
+ method_without_id = method.to_s.gsub("_id", "")
18
+ if current_selection = form.object.send(method_without_id)
19
+ choices = [[current_selection.label_string, current_selection.id]]
20
+ else
21
+ choices = {}
22
+ end
23
+ end
24
+
25
+ wrapper_options = { data: { controller: stimulus_controller }}
26
+ wrapper_options[:data]["#{stimulus_controller}-enable-search-value"] = true if other_options[:search]
27
+ wrapper_options[:data]["#{stimulus_controller}-accepts-new-value"] = true if other_options[:accepts_new]
28
+ wrapper_options[:data]["#{stimulus_controller}-search-url-value"] = choices_url if choices_url.present?
29
+ html_options[:data] = { "#{stimulus_controller}-target": 'select' }
30
+
31
+ %>
32
+
33
+ <%= render 'shared/fields/field', form: form, method: method, options: html_options, other_options: other_options do %>
34
+ <% content_for :field do %>
35
+ <%= content_tag :div, data: wrapper_options[:data] do %>
36
+ <%= form.select method, choices, options, html_options %>
37
+ <% end %>
38
+ <% end %>
39
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ form ||= current_fields_form
5
+ options ||= {}
6
+ other_options ||= {}
7
+ %>
8
+
9
+ <%= render 'shared/fields/field', form: form, method: method, helper: :text_area, options: options, other_options: other_options %>
@@ -0,0 +1,9 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ form ||= current_fields_form
5
+ options ||= {}
6
+ other_options ||= {}
7
+ %>
8
+
9
+ <%= render 'shared/fields/field', form: form, method: method, helper: :text_field, options: options, other_options: other_options %>
@@ -0,0 +1,28 @@
1
+ <% yield %>
2
+
3
+ <%
4
+ form ||= current_fields_form
5
+ labels = labels_for(form, method)
6
+ options ||= {}
7
+ options[:class] = "formatted_content trix-content #{options[:class]}"
8
+ options[:placeholder] ||= labels.placeholder if labels.placeholder
9
+ options[:data] ||= {}
10
+ options[:data][:mentions] = ([current_team].map { |team|
11
+ {key: team.name, value: team.id, protocol: 'bullettrain', model: 'teams', id: team.id, label: team.name, photo: photo_for(team)}
12
+ } + current_team.memberships.current_and_invited.map { |membership|
13
+ {key: membership.name, value: membership.id, protocol: 'bullettrain', model: 'memberships', id: membership.id, label: membership.name, photo: membership_profile_photo_url(membership)}
14
+ }).to_json
15
+ options[:data][:topics] = []
16
+ # current_team.scaffolding_things.map { |scaffolding_thing|
17
+ # {key: scaffolding_thing.name, value: scaffolding_thing.id, protocol: 'bullettrain', model: 'scaffolding/things', id: scaffolding_thing.id, label: scaffolding_thing.name, photo: photo_for(scaffolding_thing)}
18
+ # }.to_json
19
+ other_options ||= {}
20
+ %>
21
+
22
+ <div class="<%= 'trix-hide-toolbar' if other_options[:hide_toolbar] %>">
23
+ <%= render 'shared/fields/field', form: form, method: method, options: options, other_options: other_options do %>
24
+ <% content_for :field do %>
25
+ <%= form.rich_text_area method, options %>
26
+ <% end %>
27
+ <% end %>
28
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "../../theme_partials"
2
+
3
+ module BulletTrain
4
+ module Themes
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module BulletTrain
2
+ module Themes
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "bullet_train/themes/version"
2
+ require "bullet_train/themes/engine"
3
+
4
+ module BulletTrain
5
+ module Themes
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bullet_train_themes do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,97 @@
1
+ module ThemePartials
2
+ # TODO This needs to be configurable now that we've moved this file upstream.
3
+ # TODO Also, this feels almost like it should be set on a per-request basis, since you can have more than one theme
4
+ # in an app at a time.
5
+ THEME_DIRECTORY_ORDER = [
6
+ "light",
7
+ "tailwind",
8
+ "base",
9
+ ]
10
+
11
+ INCLUDE_TARGETS = [
12
+ # ❌ This path is included for legacy purposes, but you shouldn't reference partials like this in new code.
13
+ "account/shared",
14
+
15
+ # ✅ This is the correct path to generically reference theme component partials with.
16
+ "shared"
17
+ ]
18
+
19
+ # i.e. Changes "account/shared/box" to "account/shared/_box"
20
+ def convert_to_literal_partial(path)
21
+ path.sub(/.*\K\//, "/_")
22
+ end
23
+
24
+ # i.e. Changes "account/shared/_box" to "_box"
25
+ def remove_hierarchy_base(path, include_target)
26
+ path.sub(/^#{include_target}\//, "")
27
+ end
28
+
29
+ # i.e. Get "app/views/themes/light/_box.html.erb" from "_box"
30
+ def get_full_debased_file_path(path, theme_directory)
31
+ "app/views/themes/#{theme_directory}/#{path}.html.erb"
32
+ end
33
+
34
+ # Adds a hierarchy with a specific theme to a partial.
35
+ # i.e. Changes "workflow/box" to "themes/light/workflow/box"
36
+ def add_hierarchy_to_path(file_path, theme_directory)
37
+ "themes/#{theme_directory}/#{file_path}"
38
+ end
39
+
40
+ class Resolver
41
+ extend ThemePartials
42
+
43
+ # This global variable is created once per application boot.
44
+ # We're not using the Rails caching system because we want everything in local memory for this.
45
+ # If we use the Rails caching system, we end up querying it over the wire from Redis or memcached.
46
+ $resolved_theme_partials = {}
47
+
48
+ def self.base_path_for(theme)
49
+ begin
50
+ "BulletTrain::Themes::#{theme.to_s.classify}::PathSnitch".constantize.method(:confess).source_location.first.split("/lib/bullet_train/themes/").first
51
+ rescue NameError => _
52
+ nil
53
+ end
54
+ end
55
+
56
+ def self.resolve(options)
57
+ INCLUDE_TARGETS
58
+ .filter { |include_target| options.start_with? include_target }
59
+ .each do |include_target|
60
+ # If the partial path has already been resolved since boot, just return that value.
61
+ # This caching is not enabled in development so people can introduce new files without restarting.
62
+ unless Rails.env.development?
63
+ if $resolved_theme_partials[options]
64
+ return $resolved_theme_partials[options]
65
+ end
66
+ end
67
+
68
+ # Otherwise, we need to traverse the inheritance structure of the themes to find the right partial.
69
+ debased_file_path = remove_hierarchy_base(options, include_target)
70
+ normal_file_path = convert_to_literal_partial(options)
71
+
72
+ # TODO this is a hack because the main menu is still in this directory
73
+ # and other people might also add stuff there.
74
+ unless File.exist?("#{Rails.root}/app/views/#{normal_file_path}.html.erb")
75
+ THEME_DIRECTORY_ORDER.each do |theme_directory|
76
+ # First we check whether it's defined in the actual application. This takes precedence.
77
+ full_debased_file_path = convert_to_literal_partial(get_full_debased_file_path(debased_file_path, theme_directory))
78
+
79
+ actual_file_path = [
80
+ Rails.root,
81
+ # This will return nil if the theme isn't distributed as a Ruby gem.
82
+ base_path_for(theme_directory),
83
+ ].compact.map { |path| "#{path}/#{full_debased_file_path}" }.detect { |file| File.exist?(file) }
84
+
85
+ if actual_file_path
86
+ # Once we've found it, ensure we don't do this again for the same partial.
87
+ $resolved_theme_partials[options] = add_hierarchy_to_path(debased_file_path, theme_directory)
88
+ return $resolved_theme_partials[options]
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ nil
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bullet_train-themes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Culver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ description: Bullet Train Themes
28
+ email:
29
+ - andrew.culver@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/bullet_train_themes_manifest.js
38
+ - app/helpers/theme_helper.rb
39
+ - app/views/themes/base/attributes/_attribute.html.erb
40
+ - app/views/themes/base/attributes/_belongs_to.html.erb
41
+ - app/views/themes/base/attributes/_block.html.erb
42
+ - app/views/themes/base/attributes/_boolean.html.erb
43
+ - app/views/themes/base/attributes/_code.html.erb
44
+ - app/views/themes/base/attributes/_date.html.erb
45
+ - app/views/themes/base/attributes/_date_and_time.html.erb
46
+ - app/views/themes/base/attributes/_days_ago.html.erb
47
+ - app/views/themes/base/attributes/_email.html.erb
48
+ - app/views/themes/base/attributes/_has_many.html.erb
49
+ - app/views/themes/base/attributes/_html.html.erb
50
+ - app/views/themes/base/attributes/_image.html.erb
51
+ - app/views/themes/base/attributes/_option.html.erb
52
+ - app/views/themes/base/attributes/_options.html.erb
53
+ - app/views/themes/base/attributes/_phone_number.html.erb
54
+ - app/views/themes/base/attributes/_text.html.erb
55
+ - app/views/themes/base/fields/_ckeditor.html.erb
56
+ - app/views/themes/base/fields/_email_field.html.erb
57
+ - app/views/themes/base/fields/_password_field.html.erb
58
+ - app/views/themes/base/fields/_phone_field.html.erb
59
+ - app/views/themes/base/fields/_super_select.html.erb
60
+ - app/views/themes/base/fields/_text_area.html.erb
61
+ - app/views/themes/base/fields/_text_field.html.erb
62
+ - app/views/themes/base/fields/_trix_editor.html.erb
63
+ - config/routes.rb
64
+ - lib/bullet_train/themes.rb
65
+ - lib/bullet_train/themes/engine.rb
66
+ - lib/bullet_train/themes/version.rb
67
+ - lib/tasks/bullet_train/themes_tasks.rake
68
+ - lib/theme_partials.rb
69
+ homepage: https://github.com/bullet-train-co/bullet_train-themes
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/bullet-train-co/bullet_train-themes
74
+ source_code_uri: https://github.com/bullet-train-co/bullet_train-themes
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.2.22
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Bullet Train Themes
94
+ test_files: []